MyBatis增删改查学习(持续记录)
1.批量修改
列表为List T包含id和修改字段名
update [表名]
set [修改字段名] =
<foreach collection="[列表]" item="item" index="index"
separator=" " open="case" close="end">
when id=#{item.id} then #{item.修改字段名}
</foreach>
where id in
<foreach collection="[列表]" index="index" item="item"
separator="," open="(" close=")">
#{item.id,jdbcType=BIGINT}
</foreach>
2.处理JSON字段
一个>会带有双引号。使用Mybatis的话要把 > 符号转义,用 <![CDATA[ ]]>包裹着
JSON如下:
{“beforeJobsWage”:“test=”,…}
SELECT (CASE WHEN before_all_wage->'$.beforeJobsWage' is not null
THEN
before_all_wage->>'$.beforeJobsWage'
ELSE
"123"
END) as [beforeJobsWage] FROM [表名] WHERE id = [某id]