mybatis映射文件模板mapper.xml格式
1、定义基础的映射
对象DO与数据库字段间的映射
2、定义sql语句字段模版
字符类型判断null和' ',其他类型只判null
Integer,Long之类的类型传0,如果是id要加判断''或者判断是否等于0,这样对于0值,会直接跳过判断语句
如果是状态类型的数值,只要判null,不然会过滤掉0这个条件判断
//sql语句前置DO对象字段模版
id,
gmt_create,
gmt_modified,
user_name,
deleted
//插入sql语句后置传入对象模版
#{id},
now(),
now(),
#{userName},
#{deleted}
/批量插入sql语句后置传入对象模版,配合foreach使用
#{item.id},
now(),
now(),
#{item.userName},
#{item.deleted}
//sql语句更新列模版
user_name = #{userName},
deleted = #{deleted}
//sql语句批量更新列模版
user_name = #{item.userName}
//sql语句查询条件模版
//基础模版
AND id = #{id}
//日期格式模版
= #{start} ]]>
// 不让xml编译内部语句
//模糊查询模版
AND user_name like CONCAT('%',#{userName},'%')
//模糊查询使用bind标签 https://www.cnblogs.com/youmingDDD/p/9435422.html
and user_name like #{userNameLike}
//基础实例
insert into sx_user (
values (
INSERT INTO sx_user (
VALUES
(
update sx_user set gmt_modified=now(),
where id = #{id}
update sx_user set gmt_modified=now(),
where id = #{item.id}
delete from sx_user where id = #{id}
参考学习:https://blog.csdn.net/lu1024188315/article/details/78758943
update table
when id=#{item.id} then #{item.userName}
when id=#{item.id} then ''
when id=#{item.id} then null
where
id=#{item.id}

浙公网安备 33010602011771号