家庭记账本3
完成Note类后端的增删改查的操作
NoteController.java
/**
* (Note)表控制ceng
*/
@RestController
@RequestMapping("/note")
public class NoteController {
@Autowired
NoteService service;
@GetMapping
public Result list(){
return Result.success(service.list());
}
@GetMapping("{id}")
public Result getById(@PathVariable int id){
return Result.success(service.getById(id));
}
@DeleteMapping("{id}")
public Result delById(@PathVariable int id){
service.removeById(id);
return Result.success();
}
@PostMapping
public Result add(@RequestBody Note note){
service.save(note);
return Result.success();
}
@PutMapping
public Result update(@RequestBody Note note){
service.updateById(note);
return Result.success();
}
}
NoteService.java
/**
* (Note)表服务接口
*/
public interface NoteService extends IService<Note> {
}
NoteServiceImpl.java
/**
* (Note)表服务实现类
*/
@Service
public class NoteServiceImpl extends ServiceImpl<NoteDao, Note> implements NoteService {
}
NoteDao.java
/**
* (Note)表数据库访问层
*/
@Mapper
public interface NoteDao extends BaseMapper<Note> {
}
实体类Note.java
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Note {
@TableId(type = IdType.AUTO)
private Integer id;
private Integer money;
private String date;
private String msg;
}