Q:

How to send model property, the property is the model too in spring

I have two models. 
@Entity
class Product {
  @Id
  private String id;
  private String name;
  @ManyToOne(optional = false)
  @JoinColumn(name = "category_id", referencedColumnName = "id")
  @NotNull(groups = {CREATE.class, UPDATE.class})
  private Category category;
  ...
}
@Entity
class Category {
  @Id
  private String id;
  private String name;
  ...
}

@RestController
@RequestMapping(path = "/product")
class ProductController {
  @RequestMapping(method = RequestMethod. POST)
  public void create(@ModelAttribute Product product) {
    ...
  }
}

I want send request to ProductController:
http POST http://localhost:8080/product name=='Product 1' category=1

The param category is id of Category into db, but spring does not understand it.  
Is it possible to do this? 

A:

Well, your entitiy classes are ok, but it's really weird to see parameters in the POST request especially in so sort as you have it placed here. 
Here is my sample that is working properly
public class Product {
  private String id;
  private String name;
  private Category category;
  ******
}

public class Category {
  private String id;
  private String name;
  *******
}

@RestController
@RequestMapping(path = "/product")
public class ProductController {

  @RequestMapping(method = RequestMethod. POST)
  public void create(@ModelAttribute Product product) {
    Product prd1 = product;
    prd1.getId();
  }
}

And just in case here is an appConfig:
@Configuration
@EnableWebMvc
public class AppConfig {

}

That is all.  Now your contorller is expecting to get a message that is a Product instance.  
Let's go onward.  It's pretty weird to see parameters in the POST query.  I've had some test and they are ok - just pass the data as a request body!  Whatever you cose.  For instance let's modify controller as it shown below:
  @RequestMapping(method = RequestMethod. POST, consumes = MediaType. APPLICATION_JSON_UTF8_VALUE)
  public void create(@ModelAttribute Product product) {
    Product prd1 = product;
    prd1.getId();
  }
}

And now you have to send a POST message with a body that contains a Product data in a JSON format, i.e
{ "id": 1 }

and it works for all other formats that are supported by spring

