以下示例对齐 tofly-dcsw 典型实现:
ResultResponeGET /page + Page + @ModelAttribute@ToFlyAppLogpackage com.tofly.quality.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.log.annotation.ToFlyAppLog;
import com.tofly.quality.entity.SamplePlaceD;
import com.tofly.quality.entity.dto.SamplePlaceDQuery;
import com.tofly.quality.service.SamplePlaceDService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
@RestController
@AllArgsConstructor
@RequestMapping("/sampleplaced")
@Api(tags = "采样地点配置表接口")
public class SamplePlaceDController {
private final SamplePlaceDService samplePlaceDService;
@GetMapping("/page")
@ApiOperation(value = "分页查询")
public ResultRespone getSamplePlaceDPage(Page page, @ModelAttribute SamplePlaceDQuery query) {
return ResultRespone.success(samplePlaceDService.getPageData(page, query));
}
@GetMapping("/{id}")
@ApiOperation(value = "通过ID查询")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
})
public ResultRespone getById(@PathVariable("id") Long id) {
return ResultRespone.success(samplePlaceDService.getById(id));
}
@ToFlyAppLog(title = "新增采样地点配置表")
@ApiOperation(value = "新增采样地点配置表")
@PostMapping
public ResultRespone save(@RequestBody @Valid SamplePlaceD samplePlaceD) {
return ResultRespone.success(samplePlaceDService.save(samplePlaceD));
}
@ToFlyAppLog(title = "修改采样地点配置表")
@ApiOperation(value = "修改采样地点配置表")
@PutMapping
public ResultRespone updateById(@RequestBody @Valid SamplePlaceD samplePlaceD) {
return ResultRespone.success(samplePlaceDService.updateById(samplePlaceD));
}
@ToFlyAppLog(title = "通过ID批量删除采样地点配置表")
@ApiOperation(value = "通过ID批量删除采样地点配置表")
@DeleteMapping("/deleteByIds")
public ResultRespone removeByIds(String ids) {
return ResultRespone.success(samplePlaceDService.deleteByIds(ids));
}
}
package com.tofly.quality.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.tofly.quality.entity.SamplePlaceD;
import com.tofly.quality.entity.dto.SamplePlaceDQuery;
public interface SamplePlaceDService extends IService<SamplePlaceD> {
Page<SamplePlaceD> getPageData(Page page, SamplePlaceDQuery query);
boolean deleteByIds(String ids);
boolean selectByName(String samplePlaceName, Long id);
}
package com.tofly.quality.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tofly.quality.entity.SamplePlaceD;
import com.tofly.quality.entity.dto.SamplePlaceDQuery;
import com.tofly.quality.mapper.SamplePlaceDMapper;
import com.tofly.quality.service.SamplePlaceDService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.List;
@Service("samplePlaceDService")
public class SamplePlaceDServiceImpl extends ServiceImpl<SamplePlaceDMapper, SamplePlaceD> implements SamplePlaceDService {
@Override
public Page<SamplePlaceD> getPageData(Page page, SamplePlaceDQuery query) {
return this.baseMapper.getPageData(page, query);
}
@Override
@Transactional
public boolean deleteByIds(String ids) {
List<String> idList = Arrays.asList(ids.split(","));
return this.removeByIds(idList);
}
@Override
public boolean selectByName(String samplePlaceName, Long id) {
QueryWrapper<SamplePlaceD> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("SAMPLE_PLACE_NAME", samplePlaceName);
if (id != null && id > 0) {
queryWrapper.ne("ID", id);
}
return this.baseMapper.selectCount(queryWrapper) == 0;
}
}
package com.tofly.quality.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.quality.entity.SamplePlaceD;
import com.tofly.quality.entity.dto.SamplePlaceDQuery;
import org.apache.ibatis.annotations.Param;
public interface SamplePlaceDMapper extends BaseMapper<SamplePlaceD> {
Page<SamplePlaceD> getPageData(Page page, @Param("qry") SamplePlaceDQuery query);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tofly.quality.mapper.SamplePlaceDMapper">
<resultMap id="samplePlaceDMap" type="com.tofly.quality.entity.SamplePlaceD">
<id property="id" column="ID"/>
<result property="samplePlaceName" column="SAMPLE_PLACE_NAME"/>
<result property="createUser" column="CREATE_USER"/>
<result property="createTime" column="CREATE_TIME"/>
</resultMap>
<select id="getPageData" resultMap="samplePlaceDMap">
select t1.ID, t1.SAMPLE_PLACE_NAME, t1.CREATE_USER, t1.CREATE_TIME
from TF_WATERQUALITY_SAMPLE_PLACE_D t1
where 1 = 1
<if test="qry.samplePlaceName != null and qry.samplePlaceName.trim() != ''">
and t1.SAMPLE_PLACE_NAME like '%' || #{qry.samplePlaceName} || '%'
</if>
order by t1.CREATE_TIME desc
</select>
</mapper>