ssm 项目遇到mapper 里循环两次取参数的问题
来源:互联网 发布:js设置按钮隐藏 编辑:程序博客网 时间:2024/05/29 07:16
需求。做一个商品搜索的接口,要求按照条件搜索商品,参数以一个集合的形式取的,
@ApiModel("Param")
public class Param {
@ApiModelProperty("属性id")
private Integer id;
@ApiModelProperty("//最大值")
private Integer maxValId;
@ApiModelProperty("//最小值")
private Integer minValId;
@ApiModelProperty("字符串取值集合")
private List<String> valId;
@ApiModelProperty("最小价格取值")
private Integer minPic;
@ApiModelProperty("最大价格取值")
private Integer maxPic;
}
@ApiModel("ListParam")
public class ListParam {
@ApiModelProperty("属性。参数取值集合")
private List<Param> paramList;
@ApiModelProperty("第几页")
private Integer pageNum;
@ApiModelProperty("分页数,一页显示几条")
private Integer pageSize;
@ApiModelProperty("搜索框内容")
private String content;
@ApiModelProperty("按销量排序")
private String saleSort;
@ApiModelProperty("按新品排序1、降序。0升序")
private String newSort;
@ApiModelProperty("按价格排序1、降序。0升序")
private String priceSort;
@ApiModelProperty("类型id")
private int type;
}
对应的mapper。xml
<select id="getSearchQuery" parameterType="com.jnzx.zbjy.filter.ListParam"
resultType="com.jnzx.zbjy.entity.Product">
SELECT DISTINCT product.* FROM product LEFT JOIN pro_detail on product.id=pro_detail.product_id
<where>
product.type_id = #{type} and product.is_shopping='1'
<if test="paramList!=null and paramList.size>0 ">
<foreach collection="paramList" item="item" index="index">
<if test=" item.id==1">
AND
pro_detail.attribute_id1=#{item.id}
AND
( SELECT pro_attribute_value.attribute_value FROM pro_attribute_value WHERE
pro_attribute_value.id=pro_detail.attribute_value_id1)
BETWEEN (SELECT pro_attribute_scope.attribute_scope FROM pro_attribute_scope where
pro_attribute_scope.id=#{item.minValId}) AND
(SELECT pro_attribute_scope.attribute_scope FROM pro_attribute_scope WHERE
pro_attribute_scope.id=#{item.maxValId})
</if>
<if test="item.id==2">
AND
pro_detail.attribute_id2=#{item.id} -- 查询指圈是否是搜索中的条件
AND
( SELECT pro_attribute_value.attribute_value FROM pro_attribute_value WHERE
pro_attribute_value.id=pro_detail.attribute_value_id2) -- pro_detail.attribute_value_id2
-- 对应的是指圈属性对应的值
BETWEEN (SELECT pro_attribute_scope.attribute_scope FROM pro_attribute_scope where
pro_attribute_scope.id=#{item.minValId})
AND
(SELECT pro_attribute_scope.attribute_scope FROM pro_attribute_scope WHERE
pro_attribute_scope.id=#{item.maxValId})
</if>
<if test="item.id==7">
AND
product.price BETWEEN #{item.minPic} AND #{item.maxPic}
</if>
<if test="item.id==3">
AND
-- 查询品牌是否是搜索中的品牌
product.brand in(SELECT pro_attribute_scope.attribute_scope FROM pro_attribute_scope WHERE
pro_attribute_scope.id in
<foreach collection="item.ValId" item="val" index="index" open="(" close=")" separator=",">
#{val}
</foreach>
)
</if>
<if test="item.id==4">
AND
pro_detail.arg_id3=#{item.id} -- 查询工艺/镶嵌类型是否是搜索中的值
and
(SELECT pro_attribute_value.attribute_value FROM pro_attribute_value where
pro_attribute_value.id=pro_detail.arg_val_id3) in(SELECT pro_attribute_scope.attribute_scope
FROM
pro_attribute_scope WHERE
pro_attribute_scope.id in
<foreach collection="item.ValId" item="val" index="index" open="(" close=")" separator=",">
#{val}
</foreach>
)
</if>
<if test="item.id==5">
AND
pro_detail.arg_id4=#{item.id} -- 查询戒臂类型是否是搜索中的值
AND
(SELECT pro_attribute_value.attribute_value FROM pro_attribute_value where
pro_attribute_value.id=pro_detail.arg_val_id4) in(SELECT pro_attribute_scope.attribute_scope
FROM
pro_attribute_scope WHERE
pro_attribute_scope.id in
<foreach collection="item.ValId" item="val" index="index" open="(" close=")" separator=",">
#{val}
</foreach>
)
</if>
<if test="item.id==6">
AND
pro_detail.arg_id2=#{item.id} -- 判断是否有辅石 0或数字
<if test="item.valId !=null">
<foreach collection="item.valId" index="index" item="shi">
<if test="shi==7">
and -- 没有辅石的情况
(SELECT pro_attribute_value.attribute_value FROM pro_attribute_value where
pro_attribute_value.id=pro_detail.arg_val_id2)=0
</if>
<if test="shi==8">
AND -- 有副石的情况
(SELECT pro_attribute_value.attribute_value FROM pro_attribute_value where
pro_attribute_value.id=pro_detail.arg_val_id2) >0
</if>
</foreach>
</if>
</if>
</foreach>
</if>
<if test="content !=null and content !=''">
AND product.NAME LIKE '%${content}%'
</if>
<if test="priceSort !=null or saleSort !=null or newSort!=null">
<if test="priceSort==1">
ORDER BY
product.price DESC
</if>
<if test="priceSort==0">
ORDER BY
product.price ASC
</if>
<if test="saleSort==1 ">
ORDER BY
product.sales DESC
</if>
<if test="saleSort==0">
ORDER BY
p.sales ASC
</if>
<if test="newSort==1">
ORDER BY
product.create_date DESC
</if>
<if test="newSort==0">
ORDER BY
product.create_date ASC
</if>
</if>
</where>
</select> <select id="getSearchQuery" parameterType="com.jnzx.zbjy.filter.ListParam"
resultType="com.jnzx.zbjy.entity.Product">
SELECT DISTINCT product.* FROM product LEFT JOIN pro_detail on product.id=pro_detail.product_id
<where>
product.type_id = #{type} and product.is_shopping='1'
<if test="paramList!=null and paramList.size>0 ">
<foreach collection="paramList" item="item" index="index">
<if test=" item.id==1">
AND
pro_detail.attribute_id1=#{item.id}
AND
( SELECT pro_attribute_value.attribute_value FROM pro_attribute_value WHERE
pro_attribute_value.id=pro_detail.attribute_value_id1)
BETWEEN (SELECT pro_attribute_scope.attribute_scope FROM pro_attribute_scope where
pro_attribute_scope.id=#{item.minValId}) AND
(SELECT pro_attribute_scope.attribute_scope FROM pro_attribute_scope WHERE
pro_attribute_scope.id=#{item.maxValId})
</if>
<if test="item.id==2">
AND
pro_detail.attribute_id2=#{item.id} -- 查询指圈是否是搜索中的条件
AND
( SELECT pro_attribute_value.attribute_value FROM pro_attribute_value WHERE
pro_attribute_value.id=pro_detail.attribute_value_id2) -- pro_detail.attribute_value_id2
-- 对应的是指圈属性对应的值
BETWEEN (SELECT pro_attribute_scope.attribute_scope FROM pro_attribute_scope where
pro_attribute_scope.id=#{item.minValId})
AND
(SELECT pro_attribute_scope.attribute_scope FROM pro_attribute_scope WHERE
pro_attribute_scope.id=#{item.maxValId})
</if>
<if test="item.id==7">
AND
product.price BETWEEN #{item.minPic} AND #{item.maxPic}
</if>
<if test="item.id==3">
AND
-- 查询品牌是否是搜索中的品牌
product.brand in(SELECT pro_attribute_scope.attribute_scope FROM pro_attribute_scope WHERE
pro_attribute_scope.id in
<foreach collection="item.ValId" item="val" index="index" open="(" close=")" separator=",">
#{val}
</foreach>
)
</if>
<if test="item.id==4">
AND
pro_detail.arg_id3=#{item.id} -- 查询工艺/镶嵌类型是否是搜索中的值
and
(SELECT pro_attribute_value.attribute_value FROM pro_attribute_value where
pro_attribute_value.id=pro_detail.arg_val_id3) in(SELECT pro_attribute_scope.attribute_scope
FROM
pro_attribute_scope WHERE
pro_attribute_scope.id in
<foreach collection="item.ValId" item="val" index="index" open="(" close=")" separator=",">
#{val}
</foreach>
)
</if>
<if test="item.id==5">
AND
pro_detail.arg_id4=#{item.id} -- 查询戒臂类型是否是搜索中的值
AND
(SELECT pro_attribute_value.attribute_value FROM pro_attribute_value where
pro_attribute_value.id=pro_detail.arg_val_id4) in(SELECT pro_attribute_scope.attribute_scope
FROM
pro_attribute_scope WHERE
pro_attribute_scope.id in
<foreach collection="item.ValId" item="val" index="index" open="(" close=")" separator=",">
#{val}
</foreach>
)
</if>
<if test="item.id==6">
AND
pro_detail.arg_id2=#{item.id} -- 判断是否有辅石 0或数字
<if test="item.valId !=null">
<foreach collection="item.valId" index="index" item="shi">
<if test="shi==7">
and -- 没有辅石的情况
(SELECT pro_attribute_value.attribute_value FROM pro_attribute_value where
pro_attribute_value.id=pro_detail.arg_val_id2)=0
</if>
<if test="shi==8">
AND -- 有副石的情况
(SELECT pro_attribute_value.attribute_value FROM pro_attribute_value where
pro_attribute_value.id=pro_detail.arg_val_id2) >0
</if>
</foreach>
</if>
</if>
</foreach>
</if>
<if test="content !=null and content !=''">
AND product.NAME LIKE '%${content}%'
</if>
<if test="priceSort !=null or saleSort !=null or newSort!=null">
<if test="priceSort==1">
ORDER BY
product.price DESC
</if>
<if test="priceSort==0">
ORDER BY
product.price ASC
</if>
<if test="saleSort==1 ">
ORDER BY
product.sales DESC
</if>
<if test="saleSort==0">
ORDER BY
p.sales ASC
</if>
<if test="newSort==1">
ORDER BY
product.create_date DESC
</if>
<if test="newSort==0">
ORDER BY
product.create_date ASC
</if>
</if>
</where>
</select>
- ssm 项目遇到mapper 里循环两次取参数的问题
- ssm项目遇到的问题
- SSM项目搭建时遇到的问题
- SSM做项目时遇到的问题
- ssm项目下遇到的404问题
- 搭建SSM项目遇到的问题
- ssm中找不到mapper.xml的问题
- 解决idea创建ssm项目找不到mybatis的mapper的xml文件问题
- 项目里增删改查时遇到的问题
- Maven搭建的SSM项目中遇到的问题
- oracle + ssm 项目重构遇到的问题及解决方法
- SSM项目重构时遇到的一些问题及解决方法
- 建立SSM项目详细流程及所遇到的问题
- 搭建SSM项目时遇到的一些问题
- 在idea里使用SpringBoot整合MyBatis时遇到的Mapper扫描不到的问题
- for循环里嵌套使用ajax遇到的问题
- ssm挖坑,遇到的问题
- SSM遇到的问题汇总
- Java-day01
- iOS截屏后仿今日头条实现一键分享
- Docker使用记录
- 操作系统-循环首次适应算法
- 3个月可以做什么
- ssm 项目遇到mapper 里循环两次取参数的问题
- Pat 1028. 人口普查(20)
- 【2017.11.28】编译可能产生的原因
- 数据挖掘的概念
- Linux下使用Tomcat遇到的一些问题
- 改善深层神经网络第一周-Gradient Checking
- 二叉树
- XMind8在linux环境下内存溢出的另一种解决办法
- POJ 1149 迈克卖猪问题(PIGS) 最大流