/**
* xx实体类
*/
@TableName("demo_table")
public class DemoTableEntity implements Serializable {
/**
* ID
*/
@TableId
private String demoId;
/**
* 名称
*/
private String demoName;
public String getDemoId() {
return demoId;
}
public void setDemoId(String demoId) {
this.demoId= demoId;
}
public String getDemoName() {
return demoName;
}
public void setDemoName(String demoName) {
this.demoName= demoName;
}
}
@RestController
@RequestMapping("/demoTable")
public class DemoTableController extends BaseController {
@Autowired
private DemoTableService demoTableService;
/**
* 新增
* @param demoTableEntity
* @return
*/
@PostMapping("/save")
public AjaxResult save(@RequestBody DemoTableEntity demoTableEntity){
return toAjax(demoTableService.save(demoTableEntity));
}
/**
* 修改
* @param demoTableEntity
* @return
*/
@PostMapping("/update")
public AjaxResult update(@RequestBody DemoTableEntity demoTableEntity){
return toAjax(demoTableService.update(demoTableEntity));
}
/**
* 查询列表
* @param demoTableEntity
* @return
*/
@GetMapping("/selectList")
public TableDataInfo selectList(DemoTableEntity demoTableEntity){
startPage();
List<DemoTableEntity> list = demoTableService.selectList(demoTableEntity);
return getDataTable(list);
}
/**
* 删除
* @param id
* @return
*/
@DeleteMapping("/delete/{id}")
public AjaxResult deleteById(@PathVariable String id){
return toAjax(demoTableService.deleteById(id));
}
}
public interface DemoTableService {
/**
* 新增服务实例
* @param demoTableEntity
* @return
*/
Integer save(DemoTableEntity demoTableEntity);
/**
* 修改服务实例
* @param demoTableEntity
* @return
*/
Integer update(DemoTableEntity demoTableEntity);
/**
* 查询服务实例列表
* @param demoTableEntity
* @return
*/
List<DemoTableEntity> selectList(DemoTableEntity demoTableEntity);
/**
* 根据id删除服务实例
* @param id
* @return
*/
Integer deleteById(String id);
}
@Service
public class DemoTableServiceImpl implements DemoTableService {
@Autowired
private DemoTableMapper demoTableMapper;
/**
* 新增服务实例
* @param demoTableEntity
* @return
*/
@Override
public Integer save(DemoTableEntity demoTableEntity){
return demoTableMapper.insert(demoTableEntity);
}
/**
* 修改
* @param demoTableEntity
* @return
*/
@Override
public Integer update(DemoTableEntity demoTableEntity){
UpdateWrapper<DemoTableEntity> wrapper = new UpdateWrapper<>();
return demoTableMapper.update(demoTableEntity, wrapper);
}
/**
* 查询列表
* @param demoTableEntity
* @return
*/
@Override
public List<DemoTableEntity> selectList(DemoTableEntity demoTableEntity){
QueryWrapper queryWrapper = new QueryWrapper();
return demoTableMapper.selectList(queryWrapper);
}
/**
* 根据id删除
* @param id
* @return
*/
@Override
public Integer deleteById(String id){
return demoTableMapper.deleteById(id);
}
}
public interface DemoTableMapper extends BaseMapper<DemoTableEntity> {
}
bug场景: 访问 Controller 的接口返回404
// 解决方案: 启动类添加 @MapperScan注解
@MapperScan("com.gientech.armp.empower.mapper.*")
@MapperScan
注解指定了 Mapper 接口所在的包路径为 com.gientech.armp.empower.mapper
。这样,在应用启动时,Spring Boot 就会自动扫描该包下的所有 Mapper 接口,并将其实例化后交给 Spring 容器管理。