MyBatis-Plus一个下拉框参数支持多种条件查询
1.MyBatis-Plus中实现方式
Page<AlgorithmFactory> algorithmFactoryPage = new Page<>();
algorithmFactoryPage.setCurrent(algorithmListDTO.getPageIndex()).setSize(algorithmListDTO.getPageSize());
LambdaQueryWrapper<AlgorithmFactory> queryWrapper = Wrappers.<AlgorithmFactory>lambdaQuery();
queryWrapper.eq(AlgorithmFactory::getIsDeleted, DeleteEnum.NO_DELETE.getCode());
if (StringUtils.isNotBlank(algorithmListDTO.getAlgorithmNameAndProviderName())) {
queryWrapper.and(wrapper -> wrapper.like(AlgorithmFactory::getAlgorithmName, algorithmListDTO.getAlgorithmNameAndProviderName())
.or()
.like(AlgorithmFactory::getProviderName, algorithmListDTO.getAlgorithmNameAndProviderName()));
}
queryWrapper.orderByDesc(AlgorithmFactory::getUpdateTime);
Page<AlgorithmFactory> page = this.page(algorithmFactoryPage, queryWrapper);
实际完成的SQL
SELECT id,algorithm_name,algorithm_desc,provider_name,interface_address,version,status,detection_type,is_deleted,create_time,update_time,is_test_status,ai_code,config_status FROM algorithm_factory WHERE (is_deleted = 0 AND (algorithm_name LIKE '%玩手机%' OR provider_name LIKE '%玩手机%')) ORDER BY update_time DESC LIMIT 0,10
2.Mybatis中可以用concat标签
<select id="selectAll" resultType="com.test.pojo.user">
SELECT *
FROM user
<where>
<if test="key!='' and key!=null">
and CONCAT(username,nickname) like CONCAT ('%', #{key}, '%') </if>
</where>
</select>
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/118674.html