- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
今天我想给大家提出的问题是这样的:
请求到达 Controller (在 spring MVC 环境中),在该 Controller 中我想以某种方式拆分请求参数。我最初的方法是使用@ModelAttribute 注释
public String processForm(@ModelAttribute Mouse tom, @ModelAttribute Mouse jerry)
但是使用这种方法我将如何获得其他参数?这是有效的吗?
所以我想做这样的事情:
Mouse jerry = new Mouse();
BeanUtils.populate(jerry, request.getParameterMap());
//do something to remove the mice :) how?
Cat tom = new Cat();
BeanUtils.populate(cat, request.getParameterMap());
//do something to remove the cats how?
BeanUtils.populate(theRest, request.getParameterMap());
最终的问题是:如何通过尽可能少地遍历列表来有效地将请求拆分为 3 个不同的实体?
感谢您阅读本文,并希望得到答复。
最佳答案
我认为您是在问如何在处理程序方法中处理多个对象,而不是实际拆分表单/查询参数,是吗?
只需使用一个模型。将 Tom、Jerry 和 theRest 包装在一个新对象中:
class Foo {
Cat tom;
Mouse jerry;
Bar theRest;
...
}
和
public String processForm(@ModelAttribute Foo foo)
Spring MVC 可以 data bind为你。你不需要 BeanUtils。
关于java - 如何有效地拆分 ServletRequest .getParameterMap()? [Spring MVC,ServletRequest],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29679922/
我正在尝试从请求对象获取完整的参数映射并对其进行迭代。 这里是示例代码 Map map = request.getParameterMap(); for(Object key : map.keyS
HttpServletRequest 的 getParameterMap() 返回查询参数和发布的表单数据。 我可以从 UriInfo.getQueryParameters() 单独获取查询参数。 但
HTTPServletRequest req,有一个方法getParameterMap(),但是,值返回一个String[]而不是String,发布数据为 name=Marry&lastName=Jo
HandshakeRequest 的方法getParameterMap 是否包含路径参数?我似乎找不到关于此的详细文档。 最佳答案 HandShakeRequest#getParameterMap()
我有一个 java servlet 应用程序,我们正在将其从 WebSphere 移植到 TC Server 并从 java 2 升级到 java 7。 在测试中,我们发现以 % 符号结尾的参数(包括
下面是我用来测试的代码: 我们正在做的是使用 getPageContext().getRequest().getParameterMap(
为什么参数值是Object哈希码: input_name:[[Ljava.lang.String;@3f4d64] 我认为代码 request.getParameterMap().get(name);
我有一个 JSP,可以从像这样的 url 访问 http://localhost/products.jsp (因此没有查询字符串),而该页面包含其他 JSP: 在 product.jsp
我正在使用 FilterInvocationSecurityMetadataSource 实现类实现 configure(HTTP HttpSecurity) 中请求的角色动态验证方法,但是,我遇到了
我要转换Map到 Bean与 getter 和 setter。有没有一个图书馆可以做到这一点?如果没有的话怎么办? 我的想法是这样的: public Object convert(final Map
我想将表单数据直接转换为bean。最初我使用 spring 来实现这一点,但在我当前的项目中,我们不允许再使用 spring,所以我尝试在 Apache BeanUtils 的帮助下做类似的事情。我的
今天我想给大家提出的问题是这样的: 请求到达 Controller (在 spring MVC 环境中),在该 Controller 中我想以某种方式拆分请求参数。我最初的方法是使用@ModelAtt
谁能解释一下为什么 ServletRequest.getParameterMap() 返回类型 Map ServletRequest.getParameter() 只返回类型 String 我不明白为
我是一名优秀的程序员,十分优秀!