UserControllrer类 package com.sdcet.controller; import com.sdcet.entity.User; import com.sdcet.mapper.UserMapper; import com.sdcet.util.ResponseMessage; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import java.util.Date; @Controller @ResponseBody public class UserControllrer { @Autowired private UserMapper userMapper; // @RequestMapping("/getName") //public String getName(Long id) { // return userMapper.selectNameById(id); // // } //@RequestMapping("/user") // public User user(Long id) { // return userMapper.selectUserById(id); //} //@RequestMapping("/getUserByName") // public User getUserByName(String name) { // return userMapper.selectUserByName(name); // } @GetMapping("/getUserById") public ResponseMessage getUserById(Long id){ return ResponseMessage.success(userMapper.selectUserById(id)); } @GetMapping("/getUserByName") public ResponseMessage getUserById(String name){ return ResponseMessage.success(userMapper.selectUserByName(name)); } @RequestMapping("/save") public ResponseMessage save(@RequestBody User user){ if(user.getName()==null||"".equals(user.getName())){ return ResponseMessage.fail("Column'name' cannot be null"); } if(user.getPassword()==null||"".equals(user.getPassword())){ return ResponseMessage.fail("Column 'password'ccannot be null"); } Date date=new Date(); user.setCreateTime(date); user.setCreateTime(date); return ResponseMessage.success(userMapper.save(user)); } //修改数据 @PutMapping("/update") public ResponseMessage update(@RequestBody User user){ if(user.getName()==null||"".equals(user.getName())){ return ResponseMessage.fail("Column'name' cannot be null"); } if(user.getPassword()==null||"".equals(user.getPassword())){ return ResponseMessage.fail("Column 'password'ccannot be null"); } System.out.println("name="+user.getName()); return ResponseMessage.success(userMapper.update(user)); } //删除数据 @DeleteMapping("/delete") public ResponseMessage delete(Long id){ return ResponseMessage.success(userMapper.delete(id)); } //访问列表 }
2021-05-23
最新推荐文章于 2021-09-05 18:13:11 发布