diff --git a/whatsmars-spring-boot/src/main/java/org/hongxi/whatsmars/spring/boot/controller/NewController.java b/whatsmars-spring-boot/src/main/java/org/hongxi/whatsmars/spring/boot/controller/NewController.java index d8495825462430141e6a082cbee2744272be9d18..e959c82adf7757481e836a3a5d86b257885b8fd2 100644 --- a/whatsmars-spring-boot/src/main/java/org/hongxi/whatsmars/spring/boot/controller/NewController.java +++ b/whatsmars-spring-boot/src/main/java/org/hongxi/whatsmars/spring/boot/controller/NewController.java @@ -22,14 +22,14 @@ public class NewController { @Autowired private UserService userService; - @RequestMapping(value = "/t", method = RequestMethod.GET) + @GetMapping("/t") public Map query() { Map m = new HashMap(); m.put("domain", "toutiao.im"); return m; } - @RequestMapping(value = "/t", method = RequestMethod.POST) + @PostMapping("/t") public HttpStatus add(@RequestParam(name = "name") String username, @RequestParam(required = false) String nickname, @RequestParam(required = false, defaultValue = "1") Integer gender, @@ -43,18 +43,16 @@ public class NewController { return HttpStatus.OK; } - @RequestMapping(value = "/t", method = RequestMethod.PUT) - public Map update() { - Map m = new HashMap(); - m.put("domain", "toutiao.im"); - return m; + @PutMapping("/t") + public HttpStatus update(@RequestBody User user) { // 以json格式接收参数 + userService.update(user); + return HttpStatus.OK; } - @RequestMapping(value = "/t", method = RequestMethod.DELETE) - public Map delete() { - Map m = new HashMap(); - m.put("domain", "toutiao.im"); - return m; + @DeleteMapping("/t") + public HttpStatus delete(Long id) { + userService.delete(id); + return HttpStatus.OK; } @RequestMapping(value = "/e", method = RequestMethod.GET) diff --git a/whatsmars-spring-boot/src/main/java/org/hongxi/whatsmars/spring/boot/dao/UserMapper.java b/whatsmars-spring-boot/src/main/java/org/hongxi/whatsmars/spring/boot/dao/UserMapper.java index 84cd7a99c8c553a8d2f49900435b084b3ad4a3e1..a7183da4139bdf661410402dccffcbc35b38f2bb 100644 --- a/whatsmars-spring-boot/src/main/java/org/hongxi/whatsmars/spring/boot/dao/UserMapper.java +++ b/whatsmars-spring-boot/src/main/java/org/hongxi/whatsmars/spring/boot/dao/UserMapper.java @@ -18,4 +18,8 @@ public interface UserMapper { void insertBatch(List users); List query(); + + void update(User user); + + void delete(Long id); } diff --git a/whatsmars-spring-boot/src/main/java/org/hongxi/whatsmars/spring/boot/service/UserService.java b/whatsmars-spring-boot/src/main/java/org/hongxi/whatsmars/spring/boot/service/UserService.java index ed7a117628c314dc5efb5b9bddb6aade9b29e1a3..46ef2e181309a695065204f449d8cfb3a0863f98 100644 --- a/whatsmars-spring-boot/src/main/java/org/hongxi/whatsmars/spring/boot/service/UserService.java +++ b/whatsmars-spring-boot/src/main/java/org/hongxi/whatsmars/spring/boot/service/UserService.java @@ -12,5 +12,10 @@ public interface UserService { void add(User user); + void update(User user); + + void delete(Long id); + Page query(int offset, int limit); + } diff --git a/whatsmars-spring-boot/src/main/java/org/hongxi/whatsmars/spring/boot/service/impl/UserServiceImpl.java b/whatsmars-spring-boot/src/main/java/org/hongxi/whatsmars/spring/boot/service/impl/UserServiceImpl.java index 99c317a60d6cec598db0d368e08692f7f3571ff2..2d43e642c2184e7861d55185af9de0c5909b0d30 100644 --- a/whatsmars-spring-boot/src/main/java/org/hongxi/whatsmars/spring/boot/service/impl/UserServiceImpl.java +++ b/whatsmars-spring-boot/src/main/java/org/hongxi/whatsmars/spring/boot/service/impl/UserServiceImpl.java @@ -32,6 +32,16 @@ public class UserServiceImpl implements UserService { logger.info("add user success, username: {}", user.getUsername()); } + @Override + public void update(User user) { + userMapper.update(user); + } + + @Override + public void delete(Long id) { + userMapper.delete(id); + } + @Override public Page query(int offset, int limit) { return PageHelper.offsetPage(offset, limit).doSelectPage(() -> userMapper.query()); diff --git a/whatsmars-spring-boot/src/main/resources/mapper/UserMapper.xml b/whatsmars-spring-boot/src/main/resources/mapper/UserMapper.xml index a0439f56d61be4bb9a31054501a7daf8fff3a745..c3aa2818f7bae6c4068d44939f2ab69593e8cfb1 100644 --- a/whatsmars-spring-boot/src/main/resources/mapper/UserMapper.xml +++ b/whatsmars-spring-boot/src/main/resources/mapper/UserMapper.xml @@ -22,4 +22,16 @@ select * from user + + update user set update_date = NOW + , username = #{username} + , nickname = #{nickname} + , age = #{age} + where id = #{id} + + + + delete from user where id = #{id} + + \ No newline at end of file