package com.hdb.web.controller;
import com.hdb.web.pojo.User;
import com.hdb.web.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/user")
public class UserController {
@Autowired
private UserService userService;
/**
* 添加用户
*/
@GetMapping("/add")
public String add(String username){
User user = new User();
user.setUsername(username);
boolean b = userService.save(user);
return b ? "success":"failure";
}
/**
* 删除用户
*/
@GetMapping("/delete")
public String delete(Integer id){
boolean b = userService.removeById(id);
return b ? "success":"failure";
}
/**
* 更新用户
*/
@GetMapping("/update")
public String update(Integer id ,String username){
User user = userService.getById(id);
user.setUsername(username);
boolean b = userService.saveOrUpdate(user);
return b ? "success":"failure";
}
/**
* 查询所有用户
*/
@GetMapping("/find")
public List<User> find(){
return userService.list();
}
}