Update and Delete data from database using Spring MVC

L

Lvzerhawk

Guest
sorry for my English! How can I update and delete data from database in Portal Controller using Spring MVC and html form? I am using Cuba studio 6.8 and IDEA, also im working in portal module.

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!

Continue reading...
 

Tanjuunfig

New member
Joined
Nov 1, 2019
Messages
4
Reaction score
0
Points
1
iPhone 11 Pro Kılıf
Tıkla...
 
Top