BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / java / #60571同步于 2018/12/8
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖

关于RequestMapping 注解的请求处理方法可出现的参数类型

zidian321
2018/12/8镜像同步2 回复
看到一本书里是这么写的: 使用 @RequestMapping 注解的方法 每个请求处理方法可以有多个不同类型的参数,以及一个多种类型的返回结果。 以下是可以在请求处理方法中出现的参数类型 javax.servlet.ServletRequest 或 javax.servlet.http.httpServletRequest javax.servlet.ServletResponse 或 javax.servlet.http.httpServletResponse javax.servlet.http.HttpSession org.springframework.web.context.request.WebRequest 或 org.springframework.web.context.request.NativeWebRequest java.util.Locale java.io.InputStream 或 java.io.Reader java.io.OutputStream 或 java.io.Writer java.security.Principal HttpEntity<?> java.util.Map org.springframework.ui.Model org.springframework.ui.ModelMap org.springframework.web.servlet.mvc.support.RedirectAttributes org.springframework.validation.BindingResult org.springframework.web.bind.support.SessionStatus org.springframework.web.util.UriComponentsBuilder 带 @PathVariable,@MatrixVariable注解的对象 @RequestParam,@RequestHeader,@RequestBody,@RequestPart 但是我自己用spring boot 写的 其中DemoObj是我自定义的Java bean, 访问URL 为 http://localhost:8080/greeting?id=1&name=yyy 一切正常 可以打印数据,看起来是 自动封装到了DemoObj里,那请问上面的内容为什么没有提到用户自定义类呢?????? @Controller public class HelloController { @RequestMapping(value ="/greeting",produces ="text/plain;chaset=UTF-8") public String hello(DemoObj obj,HttpServletRequest request) { System.out.println(obj.getName()+obj.getId()); return "helloWorld.html"; } }
订阅后,新回复会通过你的通知中心匿名送达。
2 条回复
qingliu机器人#1 · 2018/12/8
If a method argument is not matched to any of the earlier values in this table and it is a simple type (as determined byBeanUtils#isSimpleProperty, it is a resolved as a @RequestParam. Otherwise, it is resolved as a @ModelAttribute. 好好读读文档吧
zidian321机器人#2 · 2018/12/8
感谢 【 在 qingliu 的大作中提到: 】 : If a method argument is not matched to any of the earlier values in this table and it is a simple type (as determined byBeanUtils#isSimpleProperty, it is a resolved as a @RequestParam. Otherwise, it is resolved as a @ModelAttribute. : 好好读读文档吧