加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

java – Spring MVC如何转换@RequestParam值?

发布时间:2020-12-15 01:48:57 所属栏目:大数据 来源:网络整理
导读:我是Spring框架的新手,作为一种症状,我希望尽可能简单地采用它的Web MVC部分,所以我使用注释函数来处理Spring.在过去,我用过: int value = Integer.valueOf(request.getParameter(“numberValue”))从参数中提取值 显式转换getParameter()返回的String.有用

我是Spring框架的新手,作为一种症状,我希望尽可能简单地采用它的Web MVC部分,所以我使用注释函数来处理Spring.在过去,我用过:
int value = Integer.valueOf(request.getParameter(“numberValue”))从参数中提取值 – 显式转换getParameter()返回的String.有用的,我注意到当我使用Spring的术语时:@RequestParameter(“numberValue”)int numVal
转换是自动处理的.这很好,但对我来说是一个“黑匣子”.我尝试在这里或Spring文档中查看问题,但所有这些信息都涉及对象或格式问题的自定义转换(如Converter).我想知道的是Spring默认如何为@RequestParam处理原始类型转换.

I’ve noticed that when I use Spring’s terminology:
@RequestParameter(“numberValue”) int numVal the conversion is handled
automatically.

在这里,您正在寻找类型转换

根据link的弹簧文档

String-based values extracted from the request including request
parameters,path variables,request headers,and cookie values may
need to be converted to the target type of the method parameter or
field (e.g.,binding a request parameter to a field in an
@ModelAttribute parameter) they’re bound to. If the target type is not
String,Spring automatically converts to the appropriate type. All
simple types such as int,long,Date,etc. are supported.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读