Map Post Parameter With Dash to Model In Spring Co

2020-04-21 04:20发布

I have the following property that I need mapped to a post parameter in Spring. Is there an attribute I can use? It accepts application/x-www-form-urlencoded for string-based payloads, multipart/form-data for binary payloads. Other properties are mapping fine without underscores.

String deliveryAttemptId;

mapped to the post parameter

DELIVERY-ATTEMPT-ID

Controller

@Controller
@RequestMapping("/notifications")
public class NotificationController {

    @RequestMapping(method = RequestMethod.POST)
        @ResponseBody
        public void grade(EventNotificationRequest request, HttpServletResponse response) throws Exception {        

    }

Model

public class EventNotificationRequest {

    String deliveryAttemptId;

1条回答
一夜七次
2楼-- · 2020-04-21 04:53

I just made a work around for this Spring limitation. This also fixes case sensitivity issues with parameters. Sorry I am used to .NET and how easy binding is so it's frustrating to run into these Spring issues.

HttpServletRequest parameter lowecase

 @RequestMapping(method = RequestMethod.POST, value = "/grade")
        @ResponseBody
        public void grade(HttpServletRequest request, HttpServletResponse response) throws Exception {  

            EventNotificationRequest notificationRequest = new LearningStudioEventNotificationRequest();
            notificationRequest.setDeliveryAttemptId(getCaseInsensitiveParameter(request, "DELIVERY-ATTEMPT-ID"));
查看更多
登录 后发表回答