Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Still have the same User POJO</p> <pre><code>class User { private Integer id; private String name; public User() {} public Integer getId() { return id; } public String getName() { return name; } public void setName(String name) { this.name = name; } } @RequestMapping("/create/userCreate.do") public String createUser(Model model) { User user = new User(); model.addAttribute(user); return "userCreate"; } </code></pre> <p>Here I don't send the Id or any parameter, just pass the User form model attribute</p> <pre><code>@RequestMapping(value="/edit/userEdit.do", method=RequestMethod.POST) public String editFromForm(@ModelAttribute("user") @Valid User user, BindingResult bindingResult, Model model) { // If we have errors, don't save if(bindingResult.hasErrors()) { // Put what they did in the model and send it back model.addAttribute(user); return "users/edit"; } else { userDAO.saveOrUpdate(user); } // Show them the updated page on success return "redirect:/users/" + user.getId() + "/" + user.getName(); } </code></pre> <p>Here, the User object is bind user name and id. If there is no Id then the object will be saved and if the user object already is having Id then it will be updated. You don't have to pass id or parameter and make it visible on the address bar. Sometimes I don't like the idea of showing parameters to the users. I hope that helps</p> <pre><code>&lt;%@taglib uri="http://www.springframework.org/tags" prefix="spring"%&gt; &lt;%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%&gt; &lt;%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%&gt; &lt;head&gt; &lt;title&gt; User Edit &lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form:form method="post" action="userEdit.do" commandName="user"&gt; &lt;form:hidden path="id" /&gt; &lt;form:label path="username"&gt;User name:&lt;/form:label&gt; &lt;form:input path="username" type="text" maxlength="20" /&gt; &lt;form:errors path="username" /&gt; &lt;/form:form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload