spring data jpa update

时间:2024-10-17 10:06:14

一:在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 即可: