spring data jpa update

一:在controller  加上:

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    private static final Logger LOG = LoggerFactory.getLogger(UserController.class);
    
  /*************use to update  part is null problem*********************/
    @ModelAttribute  
    public void getUser(@RequestParam(value = "id", required = false) Integer id, Model model) {
        if (id != null) {
            User user = userService.getById(id);
           model.addAttribute("user", user);
        }
    }

    /************** tologin ****************/
    @RequestMapping(value="/tologin",method = RequestMethod.GET)
    public String toLogin(){
        
        return "redirect:/index.html";
    }
    

二:

update 的时候使用 save 即可:

原文地址:https://www.cnblogs.com/lshan/p/9981496.html