目录
- Mybatis-Plus中getOne方法获取最新一条数据
- 一、代码
- 1、Controller
- 2、Service
- 3、效果
Mybatis-Plus中getOne方法获取最新一条数据
一、代码
1、Controller
@GetMapping("/queryNewProduct") public ProductDTO queryNewProduct(@RequestParam("type") String type) { return opProductService.queryNewProduct(type); }
2、Service
@Override public ProductDTO queryNewProduct(String type) { //以下出现的第一个入参boolean condition表示该条件是否加入最后生成的sql中, // 例如:query.like(StringUtils.isNotBlank(name), Entity::getName, name) // .eq(age!=null && age >= 0, Entity::getAge, age) OpProduct one = this.getOne(new LambdaQueryWrapper<OpProduct>() .eq(OpProduct::getType, type) .orderBy(true, false, OpProduct::getId) .last("limit 1") ); ProductDTO productDTO = BeanUtil.copyProperties(one, ProductDTO.class); return productDTO; }
3、效果
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)