【问题标题】:Map Post Parameter With Dash to Model In Spring Controller将带有 Dash 的 Post 参数映射到 Spring 控制器中的模型
【发布时间】:2013-12-20 00:33:27
【问题描述】:

我有以下属性需要映射到 Spring 中的 post 参数。有我可以使用的属性吗?它接受 application/x-www-form-urlencoded 用于基于字符串的有效负载,multipart/form-data 用于二进制有效负载。其他属性映射良好,没有下划线。

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;

【问题讨论】:

  • 请说明此端点是 Web 服务端点还是表单处理端点。方法因答案而异。
  • 弹簧的MVC控制器
  • 我得到的那部分(即,有一个 Spring Web MVC 控制器处理请求)。我的问题是您是否有提交数据的 HTML 表单,或者它是否是 Web 服务客户端。
  • 任何一个都可以进行 POST,application/x-www-form-urlencoded 用于基于字符串的有效负载,multipart/form-data 用于二进制有效负载
  • 有没有办法像我在这里发布的那样映射它,stackoverflow.com/questions/20646634/…

标签: java spring spring-mvc


【解决方案1】:

我刚刚解决了这个 Spring 限制。这也解决了参数的区分大小写问题。抱歉,我习惯了 .NET,而且绑定是如此简单,所以遇到这些 Spring 问题令人沮丧。

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"));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-22
    • 1970-01-01
    • 2016-02-08
    • 1970-01-01
    • 2012-03-27
    • 2021-03-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多