一、自动填充封装
1、在service-base模块中添加
创建包handler,创建自动填充类 MyMetaObjectHandler
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
@Override
public void insertFill(MetaObject metaObject) {
this.setFieldValByName("gmtCreate", new Date(), metaObject);
this.setFieldValByName("gmtModified", new Date(), metaObject);
}
@Override
public void updateFill(MetaObject metaObject) {
this.setFieldValByName("gmtModified", new Date(), metaObject);
}
}
2、在实体类添加自动填充注解
二、controller方法定义
1、新增
@ApiOperation(value = "新增讲师")
@PostMapping
public R save(
@ApiParam(name = "teacher", value = "讲师对象", required = true)
@RequestBody Teacher teacher){
teacherService.save(teacher);
return R.ok();
}
2、根据id查询
@ApiOperation(value = "根据ID查询讲师")
@GetMapping("{id}")
public R getById(
@ApiParam(name = "id", value = "讲师ID", required = true)
@PathVariable String id){
Teacher teacher = teacherService.getById(id);
return R.ok().data("item", teacher);
}
3、根据id修改
@ApiOperation(value = "根据ID修改讲师")
@PutMapping("{id}")
public R updateById(
@ApiParam(name = "id", value = "讲师ID", required = true)
@PathVariable String id,
@ApiParam(name = "teacher", value = "讲师对象", required = true)
@RequestBody Teacher teacher){
teacher.setId(id);
teacherService.updateById(teacher);
return R.ok();
}