SpringBoot +MyBatis 一个单个id,一个id集合查询查询
废话不多说,代码走起来!
请求参数
{
"typeId":2,
"thirdLevelId":[1,2,3]
}
响应参数
{
"respCode": "200",
"respMessage": "查询成功",
"data": [
{
"id": 2,
"feePoints": 6.00,
"oneCategoryName": "手机",
"twoCategoryName": "手机配件",
"threeCategoryName": "移动电源"
},
{
"id": 15,
"feePoints": 7.00,
"oneCategoryName": "手机",
"twoCategoryName": "手机配件",
"threeCategoryName": "移动电源"
}
]
}
封装的请求参数
public class PointsDTO implements Serializable {
private Integer typeId;
private Integer[] thirdLevelId;
public Integer getTypeId() {
return typeId;
}
public void setTypeId(Integer typeId) {
this.typeId = typeId;
}
public Integer[] getThirdLevelId() {
return thirdLevelId;
}
public void setThirdLevelId(Integer[] thirdLevelId) {
this.thirdLevelId = thirdLevelId;
}
}
封装的响应参数
public class PointsVO {
private Integer id;
private BigDecimal feePoints;
private String OneCategoryName;
private String TwoCategoryName;
private String ThreeCategoryName;
public PointsVO(Integer id, BigDecimal feePoints, String oneCategoryName, String twoCategoryName, String threeCategoryName) {
this.id = id;
this.feePoints = feePoints;
OneCategoryName = oneCategoryName;
TwoCategoryName = twoCategoryName;
ThreeCategoryName = threeCategoryName;
}
public PointsVO() {
super();
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public BigDecimal getFeePoints() {
return feePoints;
}
public void setFeePoints(BigDecimal feePoints) {
this.feePoints = feePoints;
}
public String getOneCategoryName() {
return OneCategoryName;
}
public void setOneCategoryName(String oneCategoryName) {
OneCategoryName = oneCategoryName;
}
public String getTwoCategoryName() {
return TwoCategoryName;
}
public void setTwoCategoryName(String twoCategoryName) {
TwoCategoryName = twoCategoryName;
}
public String getThreeCategoryName() {
return ThreeCategoryName;
}
public void setThreeCategoryName(String threeCategoryName) {
ThreeCategoryName = threeCategoryName;
}
}
Mapper接口
List<PointsVO> getAllPointsById(@Param("thirdLevelId") Integer[] thirdLevelId,@Param("typeId") Integer typeId);
Mapper.xml 文件
<select id="getAllPointsById" resultType="com.dy.mallConfig.pojo.vo.PointsVO">
SELECT
points.id AS id,
points.fee_points AS feePoints,
`third`.category_name AS threeCategoryName,
`second`.category_name AS twoCategoryName,
`first`.category_name AS oneCategoryName
FROM
category_fee_points points
LEFT JOIN category_third_level `third` ON `third`.third_level_id = points.third_level_id
LEFT JOIN category_second_level `second` ON `second`.second_level_id = `third`.parent_id
LEFT JOIN category_first_level `first` ON `first`.first_level_id = `third`.first_level_id
where points.type_id=#{typeId}
AND points.third_level_id IN
<foreach collection="thirdLevelId" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</select>
Service接口
OutputObject getAllPointsById(PointsDTO pointsDTO);
ServiceImpl实现类
@Override
public OutputObject getAllPointsById(PointsDTO pointsDTO) {
try{
List<PointsVO> list = categoryFeePointsMapper.getAllPointsById(pointsDTO.getThirdLevelId(),pointsDTO.getTypeId());
return new OutputObject(ReturnCode.SUCCESS,"查询成功",list);
}catch (Exception e){
return new OutputObject(ReturnCode.FAIL, "查询失败", e.getMessage());
}
}
Controller控制器
@PostMapping("/getAllPointsById")
@ResponseBody
public OutputObject getAllPointsById(@RequestBody PointsDTO pointsDTO){
LOGGER.info("com.dy.mallConfig.controller.CategoryFeePointsController.getAllPointsById.对外 根据店铺类型和三级类目查询扣点 PointsDTO",pointsDTO);
return categoryFeePointsService.getAllPointsById(pointsDTO);
}