My Jsp

<%@ taglib uri="" prefix="spring" %>

<spring:form method="post" modelAttribute="myObject">
      <spring:input type="hidden" path="id"/>

     <div class="type-text">
	     <label for="myLabel">My Label</label>
         <input type="text" path="firstName"/>

      .... // here We have Partial Form of myObject 


Controller Class

public MyObject beforBinding(@RequestParam(required=false) Long id){
	if (id != null) {
		return myObjectDao.findById(id);
	return null;

@RequestMapping(value = "/view", method = RequestMethod.GET)
public void viewMyPersistenObject(ModelMap model) {
         model.addAttribute("myObject", myObjectDao.findById(123));

@RequestMapping(value = "/save", method = RequestMethod.POST)
public void saveMyPersistenObject(@ModelAttribute("myObject") MyObject mergeObject) {
         // Here mergeObject is a merge between myObject return by beforeBinding method
         // and my Post Form

One Response to “Spring MVC – How to load persitent object before binding”

  1. BAS Apside

    Grâce à cet article, j’ai pu apprendre et mieux maîtriser mes objets. Merci.

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *