项目小结

1、sql语句

 (1)查询分页:select * from table limit #{start},limit

(2)mysql查询最后一行:select * from tbuser order by id desc limit 1

(3)创建自增字段,id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,mybatatis中插入自增字段

    <insert id="addUser" parameterType="User" statementType="PREPARED"

       keyProperty="userid" useGeneratedKeys="true">

            insert into users(username,password,type)

                values(#{username},#{password},#{type})</insert>

(4)mapper函数需要传递多个值到sql语句中,可以使用map类型,map中的key是可以代表上面的username

(5)Mybatis与SpringBoot集成,配置参数写在application.propers中。

spring.datasource.url=jdbc:mysql://localhost:3306/userdb?useUnicode=true&characterEncoding=utf-8&useSSL=false
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
# mybatis
mybatis.type-aliases-package=com.zmc.entity
mybatis.mapper-locations=classpath:mapper/*.xml
mybatis.configuration.map-underscore-to-camel-case=true
server.port=8080

2、映射问题

(1)post与put取值为空。我的错误原因就是因为,在spring注解开发中,使用get或者是post请求的时候,就是需要这些注意事项 
这里写图片描述 

è¿éåå¾çæè¿°

è¿éåå¾çæè¿°

        因为没有注意这个问题,调试了一天才解决。无法获得get请求可以使用request.getParams()方法对参数进行解析。另外put请求获得参数也需要使用@RequestBody注解。该异常表示的另外一种方式是,使用postMan发送请求能够对参数进行解析。网上很多map及list都用@RequestParam进行注解是不正确的。

     Restful接口参数一般建议使用简单类型的对象形式,因为http协议传递的参数都是字符串,也有可能为空。采用值类型对应的对象类可以省去很多麻烦。

3、PostMan

PostMan是非常好用的Restful接口测试工具,官网下载地址不能下载,其他下载地址:http://files.cnblogs.com/files/mafly/postman-4.1.2.rar。下载完成后,解压缩通过谷歌的扩展程序打开。

4、fetch

export function patch({ id, values }) {
    console.log(JSON.stringify(values))
    return request(`/api/users/${id}`, {
        method: 'PUT',
        headers: {
            "Content-Type": "application/json;charset=utf-8"
        },
        body: JSON.stringify(values)
    })
}
async function request(url, options) {
    const response = await fetch(url, options)
    checkStatus(response)
    const data = await response.json()
    const ret = {
        data,
        headers: {}
    }   

    if (response.headers.get('x-total-count')) {
        ret.headers['x-total-count'] = response.headers.get('x-total-count')
    }
    return ret
}

第2部分参考https://blog.csdn.net/yanlici1249075710/article/details/78491868?locationNum=8&fps=1

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值