parent
1fca85e151
commit
f661c416da
@ -0,0 +1,54 @@
|
|||||||
|
package com.example.mybatisdemo.controller;
|
||||||
|
|
||||||
|
import com.example.mybatisdemo.mapper.UserMapper;
|
||||||
|
import com.example.mybatisdemo.pojo.dto.UserDTO;
|
||||||
|
import com.example.mybatisdemo.pojo.entity.User;
|
||||||
|
import com.example.mybatisdemo.pojo.vo.UserVO;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class UserController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserMapper userMapper;
|
||||||
|
|
||||||
|
@PostMapping("/addUser")
|
||||||
|
public String addUser(@RequestBody UserDTO userDTO){
|
||||||
|
User user = new User();
|
||||||
|
BeanUtils.copyProperties(userDTO,user);
|
||||||
|
int insert = userMapper.insert(user);
|
||||||
|
if (insert!=0){
|
||||||
|
return "添加成功";
|
||||||
|
}
|
||||||
|
return "添加失败";
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/selectUser/{id}")
|
||||||
|
public UserVO selectUser(@PathVariable int id){
|
||||||
|
UserVO userVO = userMapper.selectById(id);
|
||||||
|
return userVO;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/update")
|
||||||
|
public String updateUser(@RequestBody UserDTO userDTO){
|
||||||
|
int i = userMapper.updateById(userDTO);
|
||||||
|
if (i!=0){
|
||||||
|
return "修改成功";
|
||||||
|
}
|
||||||
|
return "修改失败";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("delete/{id}")
|
||||||
|
public String deleteUser(@PathVariable int id){
|
||||||
|
int i = userMapper.deleteById(id);
|
||||||
|
if (i!=0){
|
||||||
|
return "删除成功";
|
||||||
|
}
|
||||||
|
return "删除失败";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue