用Dash映射Post参数到Spring控制器中的模型 [英] Map Post Parameter With Dash to Model In Spring Controller
问题描述
我有以下属性需要映射到Spring中的post参数。我可以使用哪个属性?它接受application / x-www-form-urlencoded用于基于字符串的有效负载,用于二进制有效负载的multipart / form-data。其他属性映射正常,没有下划线。
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;
映射到post参数
DELIVERY-ATTEMPT-ID
控制器
@Controller
@RequestMapping("/notifications")
public class NotificationController {
@RequestMapping(method = RequestMethod.POST)
@ResponseBody
public void grade(EventNotificationRequest request, HttpServletResponse response) throws Exception {
}
型号
public class EventNotificationRequest {
String deliveryAttemptId;
推荐答案
我刚刚为Spring限制做了一些工作。这也解决了参数的区分大小写问题。对不起,我已经习惯了.NET以及如何轻松绑定,因此遇到这些Spring问题令人沮丧。
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.
@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"));
这篇关于用Dash映射Post参数到Spring控制器中的模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!