Hello, How can I update and delete data from database in Portal Controller using Spring MVC and html form?
This is how I save and show my firstName, lastName list in Controller:
@GetMapping("/add")
public String add(Model model){
John john = new John();
model.addAttribute("john", john);
return "add";
}
@PostMapping("/add")
public String save(Model model, @ModelAttribute("john") John john){
String firstName = john.getFirstName();
String lastName = john.getLastName();
John newJohn = new John(firstName, lastName);
John standardEntity = metadata.create(John.class);
standardEntity.setFirstName(newJohn.getFirstName());
standardEntity.setLastName(newJohn.getLastName());
dataManager.commit(standardEntity);
return "redirect:/allPersons";
}
@RequestMapping(value = "/allPersons", method = RequestMethod.GET)
public String getPersons(Model model) {
LoadContext loadJohn = new LoadContext(John.class);
loadJohn.setQueryString("select u from test6$John u");
model.addAttribute("users", dataService.loadList(loadJohn));
return "list";
}
Thanks!