我需要知道Spring boot如何在运行时将URL中的请求参数映射到POJO。
以下是一个带有参数的示例URL
http://localhost:8080/api/public/properties?serviceType.in=SALE&title.contains=some text&price.greaterOrEqualThan=500&price.lessOrEqualThan=50000&propertyType.in=HOUSE&locationId.in=1,2&landSize.greaterOrEqualThan=100&landSize.lessOrEqualThan=1000&bedrooms.greaterOrEqualThan=2&bedrooms.lessOrEqualThan=5&bathrooms.greaterOrEqualThan=1&bathrooms.lessOrEqualThan=3&ageType.in=BRAND_NEW
我有许多Criteria类,它们都扩展了PropertyCriteria类。举个例子,如果请求不包含任何参数,我希望控制器使用PropertyCriteria。如果请求包含卧室参数,我希望控制器使用HousePropertyCriteria,依此类推。参见下面的控制器方法示例。
@GetMapping("/public/properties")
public ResponseEntity<List<Property>>
getAllPropertiesNested(HttpServletRequest request) {
if (condition1 == true) {
EntityOnePropertyCriteria c1 = new EntityOnePropertyCriteria();
//populate c1 using request object
} else {
EntityTwoPropertyCriteria c2 = new EntityTwoPropertyCriteria();
//populate c2 using request object
}
}
https://stackoverflow.com/questions/50657140
复制相似问题