JD强子 2022-01-26 19:11 采纳率: 0%
浏览 51
已结题

写一个查询 springboot+mybatisPlus+restful风格

数据库表

img

按照categoryType进行条件查询

controller

@RestController
@RequestMapping("/product-category")
public class ProductCategoryController {

    @Autowired
    private ProductCategoryService productCategoryService;
    
    @ApiOperation("按id查找")
    @GetMapping("find/{categoryId}")
    public ProductCategory findById(@PathVariable String categoryId){

        ProductCategory byId = productCategoryService.getById(categoryId);
        return byId;
    }

    @ApiOperation("按type查找")
    @GetMapping("/find/{categoryType}")
    public List<ProductCategory> findByType(@PathVariable List<Integer> categoryType) {

    }

数据库sql

DROP TABLE IF EXISTS `product_category`;
CREATE TABLE `product_category`  (
  `category_id` int(0) NOT NULL AUTO_INCREMENT,
  `category_name` varchar(64) CHARACTER SET utf8  COLLATE utf8_general_ci  NOT NULL COMMENT '类目名字',
  `category_type` int(0) NOT NULL COMMENT '类目编号',
  `create_time` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '修改时间',
  PRIMARY KEY (`category_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8  COLLATE = utf8_general_ci  COMMENT = '类目表' ROW_FORMAT = Dynamic;

实体类

@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="ProductCategory对象", description="类目表")
public class ProductCategory implements Serializable {

    private static final long serialVersionUID = 1L;

      @TableId(value = "category_id", type = IdType.AUTO)
    private Integer categoryId;

    @ApiModelProperty(value = "类目名字")
    private String categoryName;

    @ApiModelProperty(value = "类目编号")
    private Integer categoryType;

    @ApiModelProperty(value = "创建时间")
    @TableField(fill = FieldFill.INSERT)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    @ApiModelProperty(value = "修改时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;

}

最好能帮忙详细写下service层接口实现和controller层
感激不尽

  • 写回答

2条回答 默认 最新

  • JD强子 2022-01-27 01:41
    关注

    已解决

    使用queryWrapper.in

    @PostMapping("find/{categoryType}")
        public List<ProductCategory> findByType(@PathVariable List<Integer> categoryType){
    
            QueryWrapper<ProductCategory> queryWrapper = new QueryWrapper<>();
    
            queryWrapper.in("category_type",categoryType);
    
            List<ProductCategory> list = productCategoryService.list(queryWrapper);
            return list;
        }
    

    注意GetMapping和PostMapping

    不得不说mybatisPlus是真的强大

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 1月27日
  • 创建了问题 1月26日

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用