Spring. Map field of @RequestBody with @PathVariable

眉间皱痕 提交于 2020-03-28 06:44:11

问题


Now I have code like this:

@RestController
public class ChildController {

@RequestMapping(value = "/parents/{parentId}/addChild", method = RequestMethod.POST)
  public void addChild(@RequestBody ChildDTO child, @PathVariable Long parentId) {
    child.setParentId(parentId);
    //...
  }
}

class ChildDTO {

  private Long parentId;

  private String name;

  private double weight;

  private double height;

  //setters ang getters
}

Is there any way to map parentId in child object without calling setter in method body? I need it for my Aspect @Before logic

来源:https://stackoverflow.com/questions/39728571/spring-map-field-of-requestbody-with-pathvariable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!