单表动态条件查询 1)单字段作为参数 直接用@param设置的值作为注入就好了 @Select("select * from ppms_person_message wher
单表动态条件查询
1)单字段作为参数
直接用@param设置的值作为注入就好了
@Select("select * from ppms_person_message where create_time = #{testValue}") void test(@Param("testValue") String testValue);
2)对象作为参数
注意:在@param内的值不为“ew”的时候会提示找不到条件参数
@Select("select * from ppms_person_message ${ew.customsqlSegment}") Page<PersonMessage> selectTestPage(@Param("page") Page<PersonMessage> page, @Param("ew") QueryWrapper<PersonMessage> qw);
多表联合动态条件查询
1>使用wrapper
注意:1)${ew.customSqlSegment}仅为where下的条件
2)join on后面的条件需要使用另外的param
@Select("select m.* from ppms_person_message m " + "left join ppms_notice n on n.id = m.notice_id and n.create_time = #{testValue}" + "${ew.customSqlSegment}") void test(@Param("testValue") String testValue, @Param("ew") QueryWrapper<PersonMessage> qw);
2>使用标签
注意:1)动态条件外双引号改为单引号,内单引号改为转义双引号(")
2)使用遍历条件时需要在最外成加上标签
@Select("") List<MessageRespVo> selectUnReadNumByUserId2(@Param("dto") TaskPageDto dto);
来源地址:https://blog.csdn.net/qq_45621643/article/details/129301957
--结束END--
本文标题: mybatis-plus在Mapper类中使用@select标签进行多表联合动态条件查询
本文链接: https://www.lsjlt.com/news/432717.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-09
2024-05-09
2024-05-09
2024-05-09
2024-05-09
2024-05-09
2024-05-09
2024-05-08
2024-05-08
2024-05-08
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0