Layui+mybatis开发 小知识
1、当你用实体类去接收数据时,如果数据类型为Date应该加上@JsonFormat(pattern = “yyyy-MM-dd HH:mm:ss”, timezone = “GMT+8”)即可将毫秒数转化为日期格式
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;
2、在sql中模糊查询,需要将sql中带参数的语句换为like concat(‘%’,#{param1},‘%’)即可进行模糊查询,其中可以用<if test=>来对数据进行判断,提高sql语句的复用率。且mybatis并不能直接读取参数,它只能将参数以param1、param2、param3…的方式传入sql中进行判断。
select *
from user
where 1 = 1
<if test="param1!='' and param1!=null">
AND user_name like concat('%',#{param1},'%')
</if>
该解决办法来源:https://www.jianshu.com/p/b29f577793c7