-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Open
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)status: feedback-providedFeedback has been providedFeedback has been providedstatus: waiting-for-triageAn issue we've not yet triaged or decided onAn issue we've not yet triaged or decided on
Description
It can be reproduced.
Spring 5.3.x works normally; it is recommended that 6.2.10 maintains backward compatibility: WebDataBinder.getTarget() is null
- Purpose: Map alias values of Query parameters to actual fields via
@ControllerAdvice
and@InitBinder
?
@ControllerAdvice
public class GlobalInitBinder {
@InitBinder
public void initBinder(WebDataBinder binder, HttpServletRequest request) {
//Spring 6 fails to retrieve Params parameter objects, with binder.getTarget() = null;
// please help troubleshoot the issue.
Object target = binder.getTarget();
if (target == null) {
return;
}
Map<String, String[]> parameterMap = request.getParameterMap();
MutablePropertyValues mpv = new MutablePropertyValues(parameterMap);
Field[] fields = target.getClass().getDeclaredFields();
}
@RestController
@RequestMapping("v1")
public class TestController {
@PostMapping("/test")
public void getLoadWeightRuleList(Params params) {}
}
import lombok.Data;
@Data
public class Params implements Serializable {
@FormFieldAlias(alternateNames = {"PageNum", "PageNumber", "pageNum"})
private Integer pageNum;
}
- How to bind multiple aliases to
@BindParam("PageNumber")
,like{alternateNames = {"PageNum", "PageNumber", "pageNum"}}
? - link: Support target instantiation and binding via constructor in DataBinder #26721
import org.springframework.web.bind.annotation.BindParam;
public class Params implements Serializable {
@BindParam("PageNumber")
private Integer pageNum;
public Params(Integer pageNum) {
this.pageNum = pageNum;
}
}
- to use
HandlerMethodArgumentResolver
to solve the binding of multiple aliases to fields during query submission, or to use toServletRequestDataBinder
to invokebind(ServletRequest)
?
Metadata
Metadata
Assignees
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)status: feedback-providedFeedback has been providedFeedback has been providedstatus: waiting-for-triageAn issue we've not yet triaged or decided onAn issue we've not yet triaged or decided on