mybatis 字段与数据库关键字冲突了怎么办
如update join_brand_hot set
index = #{top} where id = #{id}
这样明显会因为index与索引关键词导致的冲突
解决方法一
update join_brand_hot set
`index` = #{top}
where id = #{id}
- 1
- 2
- 3
解决方法二
update join_brand_hot h set
h.index = #{top} where id = #{id}
mybatis传入的参数不能直接干涉到MySQL
mybatis传入的参数不能直接干涉到MySQL
传入的参数做的if判定只能影响#{}这个传入的值
不是对MySQL数据库进行选择
所以应该这样写
<if test="today != null" >
and (show_end_time is null or show_end_time >= #{today})
</if>
- 1
- 2
- 3
mybatis for 循环查询输出
select * form user where
name in
<foreach collection="searchNameForList" item="item" index="index" open="(" separator="," close=")">
#{item}
</foreach>
- 1
- 2
- 3
- 4
- 5
批量更新mybatis plus
//条件
UpdateWrapper<MchDataAuthConfigRule> updateWrapper = new UpdateWrapper<>();
updateWrapper.in("id", idList);
//更新
MchDataAuthConfigRule rule = new MchDataAuthConfigRule();
rule.setStatus(100);
int update = mchDataAuthConfigRuleMapper.update(rule, updateWrapper);
log.info("update:{}", update);
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
mybatis常用标签
1.if 标签 if标签通常用于WHERE语句、UPDATE语句、INSERT语句中,通过判断参数值来决定是否使用某个查询条件、判断是否更新某一个字段、判断是否插入某个字段的值。 2.foreach 标签 foreach标签主要用于构建in条件,可在sql中对集合进行迭代。也常用到批量删除、添加等操作中。 3 choose标签 有时候我们并不想应用所有的条件,而只是想从多个选项中选择一个。 MyBatis提供了choose 元素,按顺序判断when中的条件出否成立, 如果有一个成立,则choose结束。当choose中所有when的条件都不满则时, 则执行 otherwise中的sql。类似于Java 的switch 语句,choose为switch, when为case,otherwise则为default。 if是与(and)的关系,而choose是或(or)的关系。 4. where标签 这个“where”标签会知道如果它包含的标签中有返回值的话,它就插入一个‘where’。 此外,如果标签返回的内容是以AND 或OR 开头的,则它会剔除掉。 5. set 标签 当在update语句中使用if标签时,使用set标签可以将动态的配置set关键字,和剔除追 加到条件末尾的任何不相关的逗号。 6.include标签 sql标签中id属性对应include标签中的refid属性。通过include标签将sql片段 和原sql片段进行拼接成一个完整的sql语句进行执行。 例如: 7.多表联查中: JavaType和ofType都是用来指定对象类型的,但是JavaType是用来指定pojo中属性的类型,而ofType指定的是映射到list集合属性中pojo的类型。 collection、association标签是用于体现关联的。 如一个实体与另一个实体之间是一对多的关系, 那么在一的一方使用 collection 标签,对应多的一方的一个集合, 在多的一方使用association标签对应一的一方的一个实体
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
本文使用 文章同步助手 同步