1 pom依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.3.1</version>
</dependency>
2 mapper 接口文件
List<TBookOrder> searchDiy(@Param(Constants.WRAPPER) Wrapper<TBookOrder> queryWrapper);
3 mapper 的xml配置文件
<select id="searchDiy" resultMap="BaseResultMap">
select
id, order_id, book_id, user_id, `status`, `count`, bill_time from t_book_order
${ew.customSqlSegment}
</select>
4 查询
//无参
QueryWrapper<TBookOrder> queryWrapper_1 = new QueryWrapper<>();
tBookOrderMapper.searchDiy(queryWrapper_1);
System.out.println();
System.out.println();
//有参
LambdaQueryWrapper<TBookOrder> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(TBookOrder::getBookId, 2);
queryWrapper.ge(TBookOrder::getUserId, 1002);
List<TBookOrder> tBookOrders = tBookOrderMapper.searchDiy(queryWrapper);
5 测试,生成的两个sql语句如下文章来源:https://www.toymoban.com/news/detail-835494.html
select
id,
order_id,
book_id,
user_id,
`status`,
`count`,
bill_time
from
t_book_order;
select
id,
order_id,
book_id,
user_id,
`status`,
`count`,
bill_time
from
t_book_order
WHERE
(
book_id = 2
AND user_id >= 1002
);
注意:不同的版本,可能会有部分区别,总之注意下版本文章来源地址https://www.toymoban.com/news/detail-835494.html
到了这里,关于Mybatisplus 传参参数为自定义sql, 使用条件构造器作为参数的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!