是否可以在 Spring 中创建 GET
Web 服务并在查询中使用嵌套属性?就像下面示例中的 search.limitResults
一样:
localhost:8080/firstname=test&search.limitResults=10
你明白了。这可以实现吗?
@RestController
public class MyServlet {
@RequestMapping(value = "/", method = RequestMethod.GET)
private String test(RestParams p) {
}
}
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class RestParams {
private String firstname;
private String lastname;
//is that possible to nest?
private Search search;
}
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Search {
private int limitResults;
//some more
}
最佳答案
回答我自己的问题:它就是这样工作!可以使用点访问器访问嵌套属性,例如 search.limitResults
。
关于java - 在 @RestController 中使用嵌套对象进行 GET 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38435071/