Example 1:
mapper layer:
List<Map> queryBookCondition(@Param("params") Map<String, Object> params);
The corresponding mapper implementation layer:
public PageInfo<Map> queryBookCondition(Map<String, Object> params) {
PageHelper.startPage(Integer.parseInt(params.get("pageNum").toString()), Integer.parseInt(params.get("pageSize").toString()));
List<Map> maps = bookMapper.queryBookCondition(params);
PageInfo<Map> mapPageInfo = new PageInfo<>(maps);
return mapPageInfo;
}
The corresponding mybatis writing method:
<select id="queryBookCondition" resultType="map">
select
book_id bookId, book_name bookName, book_number bookNumber, book_picture bookPicture, price, type_name typeName, deleted
from A.book b LEFT JOIN A.book_type t ON b.type_id = t.type_id
where 1 = 1
<if test="params.searchKey == 'bookName'">
AND b.book_name like CONCAT("%",#{params.searchValue},"%")
</if>
<if test="params.searchKey == 'typeName'">
AND type_name like CONCAT("%",#{params.searchValue},"%")
</if>
<if test="params.searchKey == 'price'">
AND price like CONCAT("%",#{params.searchValue},"%")
</if>
<if test="params.searchKey == 'bookNumber'">
AND book_number like CONCAT("%",#{params.searchValuer},"%")
</if>
order by b.book_id DESC
</select>
Example 2:
int insertBatch(@Param("book") List<Book> entities);
<insert id="insertBatch" keyProperty="bookId" useGeneratedKeys="true">
insert into A.book(book_name, book_number, book_picture, description, book_press, price,
book_type)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.bookName}, #{entity.bookNumber}, #{entity.bookPicture}, #{entity.description},
#{entity.bookPress}, #{entity.price}, #{entity.bookType})
</foreach>
</insert>
Regarding keyProperty, you can refer to: About the keyProperty attribute in Mybatis
Springboot integrates mybatis-plus's sql output to the log file - Baidu: mybatisplus outputs to the file
How to print sql logs and parameters to the log file under mybatis-plus under springboot |Source →
#控制台方式(本地启动日志打印到控制台常用方式):
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
#文件方式,需结合logginglevel
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl
logging:
level:
com.baomidou.mybatisplus: DEBUG
#这个是配置的mapper路径,如:cn.example.mapper
cn.example.mapper: DEBUG