统一接口:在查询时,不同的Api会响应返回不同类型的数据,前端处理起来就比较麻烦,沟通成本也比较高,
定义一个productQuery类用来传递请求中的数据
编写查询语句,返回结果集合
productDao.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yy.dao.ProductDao">
<select id="select" parameterType="com.yy.entity.ProductQuery" resultType="com.yy.entity.Product">
select * from 210_product
<where>
<if test="categoryId != null">
and categoryId = #{categoryId}
</if>
<if test="id != null">
and id = #{id}
</if>
<if test="ids != null">
and id in
<foreach collection="ids" item="id" open="(" close=")" separator=",">
#{id}
</foreach>
</if>
<if test="name != null">
and name like concat('%',#{name},'%')
</if>
<if test="categoryIds != null">
and categoryId in
<foreach collection="categoryIds" item="categoryId" open="(" close=")" separator=",">
#{categoryId}
</foreach>
</if>
</where>
</select>
</mapper>