Get item from db and let Spring MVC binder populate it -


i have

  • jpa entity

    @entity public class tag {     @id     private long id;     private string name;     // getters, setters ... } 
  • a form edit tag http://localhost:8080/tag/{id}

    <form method="post">     <input type="text" name="name" /> </form> 
  • a controller method

    @requestmapping("{id}") public string save(@modelattribute("tag") tag tag) {     tagrepository.save(tag); } 

what best way tag database , let spring populate properties request parameters?

  • create webargumentresolver , annotate method parameter @pathvariable("id") (or @requestparam("id") if pass id request parameter)
  • modify binder in method annotated @initbinder (and how?)
  • create method annotated @modelattribute("tag") populate item first db
  • anything else?

this not limited jpa , spring data, case , thought it's more clear.


Comments

Popular posts from this blog

tcpdump - How to check if server received packet (acknowledged) -