- 浏览: 108453 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
Inmethetiger:
yixiandave 写道能不能在Validation注解的m ...
Spring验证小结和问题 -
yixiandave:
Inmethetiger 写道yixiandave 写道如果用 ...
Spring验证小结和问题 -
Inmethetiger:
yixiandave 写道如果用JSR303的话,可以引入hi ...
Spring验证小结和问题 -
yixiandave:
如果用JSR303的话,可以引入hibernate-valid ...
Spring验证小结和问题 -
jackytang520:
貌似用了这么久,没有碰到过这个问题..
idea属性文件中文乱码
转载自:http://blog.sina.com.cn/s/blog_6d3c1ec601017q4l.html
下列参数一般都和@RequestMapping配合使用。
A、@CookieValue
org.springframework.web.bind.annotation.CookieValue
public @interface CookieValue
Annotation which indicates that a method parameter should be bound to an HTTP cookie. Supported for annotated handler methods in Servlet and Portlet environments.
这个注释表示一个方法参数绑定到一个HTTP cookie。支持Servlet和Portlet环境。
The method parameter may be declared as type Cookie or as cookie value type (String, int, etc).
这个方法的参数可声明为Cookie类型或String, int等。
A.1、@CookieValue的属性
String value
The name of the cookie to bind to.
绑定的cookie名称。
boolean required
Whether the header is required.
Default is true, leading to an exception being thrown in case the header is missing in the request. Switch this to false if you prefer a null in case of the missing header.
Head是否需要。默认是true,请求中头丢失将抛出一个异常。False,请求中头丢失将返回null。
Alternatively, provide a defaultValue, which implicitly sets this flag to false.
因此,提供一个defaultValue。
String defaultValue
The default value to use as a fallback. Supplying a default value implicitly sets required() to false.
当required为false,请求中头丢失将返回这个值。
B、@PathVariable
Annotation which indicates that a method parameter should be bound to a URI template variable. Supported for RequestMapping annotated handler methods in Servlet environments.
这个参数指出方法的一个参数绑定到一个URI template变量。在Servlet环境中的被@RequestMapping注释的处理器方法。
B.1、@PathVariable的属性
value
The URI template variable to bind to.
绑定URI template变量。
举例说明
当URI template变量和方法的参数名称一样时,可以省略value的定义,@PathVariable达到同样的效果。
C、@RequestBody
Annotation which indicates that a method parameter should be bound to the web request body. Supported for annotated handler methods in Servlet environments.
这个注释它指示一个方法的参数绑定到一个web请求的body。它支持Servlet环境中的注释处理器方法。
举例说明
这时这个参数reqBody的值是请求页面的form表单的所有值。
D、@ RequestHeader
Annotation which indicates that a method parameter should be bound to a web request header. Supported for annotated handler methods in Servlet and Portlet environments.
这个注释它指示一个方法的参数绑定到一个web请求的头信息。它支持Servlet和Portlet环境中的注释处理器方法。
D.1、@ RequestHeader的属性
String defaultValue
The default value to use as a fallback.
默认返回值。
Boolean required
Whether the header is required.
是否需要header。
String value
The name of the request header to bind to.
绑定的请求头名称。
举例说明
这时这个参数info将获得请求的Accept头信息。
E、@RequestParam
org.springframework.web.bind.annotation.RequestParam
Annotation which indicates that a method parameter should be bound to a web request parameter. Supported for annotated handler methods in Servlet and Portlet environments.
这个参数指出一个方法的参数应绑定到一个web请求的参数。支持Servlet和Portlet环境下注释处理器的方法。
E.1、@RequestParam的属性
E.1.1、value
The name of the request parameter to bind to.
绑定的请求参数的名称。
@RequestParam(value="abc")等同于@RequestParam("abc")
E.1.2、required
Whether the parameter is required.
是否需要参数。
Default is true, leading to an exception thrown in case of the parameter missing in the request. Switch this to false if you prefer a null in case of the parameter missing.
默认为true,若请求中没有参数会导致抛出一个异常。若设置为false,若请求中没有参数就会返回null。
Alternatively, provide a defaultValue, which implicitly sets this flag to false.
在required=false时,最好设置一个defaultValue默认值。
E.1.3、defaultValue
The default value to use as a fallback. Supplying a default value implicitly sets required() to false.
当required=false时,设定默认值。
举例说明
F、@ResponseBody
Annotation which indicates that a method return value should be bound to the web response body. Supported for annotated handler methods in Servlet environments.
这个注释它指示一个方法的返回值应该绑定到一个web响应的body中。它支持Servlet环境中的注释处理器方法。
应用@ResponseBody将会跳过视图处理,而是调用合适HttpMessageConverter,将返回值写入输出流。
举例说明
或者这样定义
这时访问/a/b时,不是返回一个view名为helloWorld的视图,而是作出一个响应,其内容为helloWorld。
下列参数一般都和@RequestMapping配合使用。
A、@CookieValue
org.springframework.web.bind.annotation.CookieValue
public @interface CookieValue
Annotation which indicates that a method parameter should be bound to an HTTP cookie. Supported for annotated handler methods in Servlet and Portlet environments.
这个注释表示一个方法参数绑定到一个HTTP cookie。支持Servlet和Portlet环境。
The method parameter may be declared as type Cookie or as cookie value type (String, int, etc).
这个方法的参数可声明为Cookie类型或String, int等。
A.1、@CookieValue的属性
String value
The name of the cookie to bind to.
绑定的cookie名称。
boolean required
Whether the header is required.
Default is true, leading to an exception being thrown in case the header is missing in the request. Switch this to false if you prefer a null in case of the missing header.
Head是否需要。默认是true,请求中头丢失将抛出一个异常。False,请求中头丢失将返回null。
Alternatively, provide a defaultValue, which implicitly sets this flag to false.
因此,提供一个defaultValue。
String defaultValue
The default value to use as a fallback. Supplying a default value implicitly sets required() to false.
当required为false,请求中头丢失将返回这个值。
B、@PathVariable
Annotation which indicates that a method parameter should be bound to a URI template variable. Supported for RequestMapping annotated handler methods in Servlet environments.
这个参数指出方法的一个参数绑定到一个URI template变量。在Servlet环境中的被@RequestMapping注释的处理器方法。
B.1、@PathVariable的属性
value
The URI template variable to bind to.
绑定URI template变量。
举例说明
@Controller public class HelloWorldController { @RequestMapping("/helloWorld/{userId}") public String helloWorld(ModelMap model,@PathVariable("userId") String userId) { model.addAttribute("attributeName", userId); return "helloWorld"; } }
当URI template变量和方法的参数名称一样时,可以省略value的定义,@PathVariable达到同样的效果。
C、@RequestBody
Annotation which indicates that a method parameter should be bound to the web request body. Supported for annotated handler methods in Servlet environments.
这个注释它指示一个方法的参数绑定到一个web请求的body。它支持Servlet环境中的注释处理器方法。
举例说明
@Controller public class HelloWorldController { @RequestMapping("/hello.do") public String helloWorld(Model model,@RequestBody String reqBody) { model.addAttribute("message", reqBody); return "helloWorld"; } }
这时这个参数reqBody的值是请求页面的form表单的所有值。
D、@ RequestHeader
Annotation which indicates that a method parameter should be bound to a web request header. Supported for annotated handler methods in Servlet and Portlet environments.
这个注释它指示一个方法的参数绑定到一个web请求的头信息。它支持Servlet和Portlet环境中的注释处理器方法。
D.1、@ RequestHeader的属性
String defaultValue
The default value to use as a fallback.
默认返回值。
Boolean required
Whether the header is required.
是否需要header。
String value
The name of the request header to bind to.
绑定的请求头名称。
举例说明
@Controller public class HelloWorldController { @RequestMapping("/hello.do") public String helloWorld(Model model,@RequestHeader("Accept") String info) { model.addAttribute("message", info); return "helloWorld"; } }
这时这个参数info将获得请求的Accept头信息。
E、@RequestParam
org.springframework.web.bind.annotation.RequestParam
Annotation which indicates that a method parameter should be bound to a web request parameter. Supported for annotated handler methods in Servlet and Portlet environments.
这个参数指出一个方法的参数应绑定到一个web请求的参数。支持Servlet和Portlet环境下注释处理器的方法。
E.1、@RequestParam的属性
E.1.1、value
The name of the request parameter to bind to.
绑定的请求参数的名称。
@RequestParam(value="abc")等同于@RequestParam("abc")
E.1.2、required
Whether the parameter is required.
是否需要参数。
Default is true, leading to an exception thrown in case of the parameter missing in the request. Switch this to false if you prefer a null in case of the parameter missing.
默认为true,若请求中没有参数会导致抛出一个异常。若设置为false,若请求中没有参数就会返回null。
Alternatively, provide a defaultValue, which implicitly sets this flag to false.
在required=false时,最好设置一个defaultValue默认值。
@RequestParam(value = "abc",required=false)
E.1.3、defaultValue
The default value to use as a fallback. Supplying a default value implicitly sets required() to false.
当required=false时,设定默认值。
举例说明
@Controller @RequestMapping("/a") public class HelloWorldController { @RequestMapping("/b") public String helloWorld(Model model,@RequestParam("a") String abc) { model.addAttribute("message", abc); return "helloWorld"; } }
F、@ResponseBody
Annotation which indicates that a method return value should be bound to the web response body. Supported for annotated handler methods in Servlet environments.
这个注释它指示一个方法的返回值应该绑定到一个web响应的body中。它支持Servlet环境中的注释处理器方法。
应用@ResponseBody将会跳过视图处理,而是调用合适HttpMessageConverter,将返回值写入输出流。
举例说明
@Controller @RequestMapping("/a") public class HelloWorldController { @RequestMapping("/b") @ResponseBody public String helloWorld() { return "helloWorld"; } }
或者这样定义
@Controller public class HelloWorldController { @RequestMapping("/a/b") public @ResponseBody String helloWorld() { return "helloWorld"; } }
这时访问/a/b时,不是返回一个view名为helloWorld的视图,而是作出一个响应,其内容为helloWorld。
发表评论
-
Spring验证小结和问题
2014-07-27 16:36 4883因为从云笔记中粘贴过来的,代码格式就没有了。格式稍好点的地 ... -
在spring中使用Ehcache
2014-06-18 16:07 1040前提: 使用环境:详细页面 依赖包: ... -
Spring MVC 3.0版本和3.1版本的一点小区别
2013-06-12 00:57 2724先上代码: 主要是控制器: @Controller ... -
在Maven下的springJpa多模块开发引起的问题
2013-02-21 22:33 3112最近的项目搭建中,出现了一个问题。 ... -
spring 事务二:注解springmvc+注解or声明式事务
2012-11-23 08:42 2233前面讲了两大类,四种spring事务的方式。这篇主要记录基于注 ... -
spring 事务一:非注解springmvc+注解or声明式事务
2012-11-22 15:47 2494前两天一人问我,在使用spring mvc (基于注解) 的时 ... -
在spring中使用mybatis
2012-11-14 21:59 3630今天在使用mybatis的时候,发现dao的实现竟然可以不需要 ... -
三种连接池的配置
2012-09-28 10:00 1145用spring默认的连接池性能效率不高, 如果数据库重启 ... -
spring jdbc之query详细实例2
2012-09-27 16:45 1884首发地址: http://inmethetiger.iteye ... -
spring jdbc之query详细实例1
2012-09-27 16:15 3220首发:http://inmethetiger.iteye. ... -
spring jdbc之最简单的增删改查
2012-09-27 10:10 2072首发地址: http://inmethetiger.iteye ... -
spring的实例化方式
2012-09-26 17:48 1818首发地址: http://inmethetiger.iteye ... -
Spring Aop(一)
2012-09-26 16:06 765这是一个简单的spring aop的例子。 一:定义目 ... -
spring mvc表单标签和@ModelAttribute
2012-09-20 21:05 9115首发地址:http://inmethetiger.iteye ... -
spring相关资料的URL(持续更新)
2012-09-20 13:34 1199首发地址http://inmethetiger.iteye.c ... -
Spring mvc注解之实现MultiActionController功能
2012-09-16 16:38 1632首发地址http://inmethetiger.iteye.c ... -
spring mvc 之注解版基础
2012-09-14 17:28 920首发地址:http://inmethetiger.iteye ... -
spring mvc 之MultiActionController和MethodNameResolver--附带实例
2012-09-14 17:23 1979首发地址:http://inmethetiger.iteye. ... -
Spring MVC的开发流程--附带实例
2012-09-12 18:05 2568首发地址: http://inmethetiger.i ...
相关推荐
springboot jpa mysql controller 完整demo演示 ... //将数据放置到ModelAndView对象view中,第二个参数可以是任何java类型 view.addObject("name", name); //返回ModelAndView对象view return view; }
常用注解:@Controller @RestController(Controller+ResponseBody) @Service @Transactional @Mapper @AutoWired @RequestMapping--路由 @RequestParam--参数绑定(不同名参数或Map<Object,String>) @...
在火狐中显示可能会有问题,大家都是程序员,改个参数就好啦 注解包含: 拦截器 , 过滤器 , 序列化 , @After , @AfterReturning , @AfterThrowing , @annotation , @Around , @Aspect , @Autowired , @Bean , @Before ,...
@RequestMapping 注解中除了 params 属性外,还有一个常用的属性是 method,它可以让 Controller 方法处理特定 HTTP 请求方式的请求,如让一个方法处理 HTTP GET 请求,而另一个方法处理 HTTP POST 请求,如下所示:...
JavaWeb框架——SpringMVC学习过程前端控制器、视图解析器@Controller@RequestMapping(value、method、params)获取请求参数域对象共享数据视图前缀RESTFul文件上传下载拦截器Interceptor异常处理Excepton
Web服务方法参数包含@RequestParam,该属性具有defaultValue属性 ,该值将为请求中不可用的请求参数分配默认值。 要设置环境,我们可以使用Spring Boot快速启动。WebApplicationInitializer用于替换web.xml设置。...
第一节:@RequestMapping配置url映射 第二节:@Controller处理http请求 第三节:@RestController处理ajax请求 第四节:@PathVariable获取url参数 第五节:@RequestParam获取请求参数 第四章:SpringBoot之Spring ...
比较全面的MVC源码分享。用户只要轻松使用几个注解就能完成...@Controller:表示控制器; @RequestMapping:映射url路径的控制器; @RequestParam:表示请求时传递来的参数; @ResponseBody:表示方法返回json数据。
导入静态资源展示后台首页1 功能分析请求的url:/参数:无返回值:逻辑视图String2 Controller/** * 页面跳转controller * */ @Controller public class PageController { @RequestMapping("/") public ...
@RequestMapping(value = "/hello",method = RequestMethod.GET) public String hello(Model model) { model.addAttribute("name", "Dear"); return "hello"; } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 2....
1、通过@Controller注解为控制器类注入实例(DI,依赖注入); 2、通过@RequestMapping,建立url请求路径与对应处理类及方法的映射关系; 3、通过@RequestParam,为url对应处理方法的参数变量赋值; 4、通过@...
通过 @PathVariable 可以将 URL 中占位符参数绑定到控制器处理方法的入参中:URL 中的 {xxx} 占位符可以通过@PathVariable(“xxx“) 绑定到操作方法的入参中。 select * from tb_category where id in (select ...
< dependency> < groupId>de.is24.spring</ groupId> < artifactId>base64-url-decoder</ artifactId> < version>1.0</ version> 用法根据此示例,在 MVC 控制器中使用@DecodedUri注释来注释您的参数: @...
用@ RequestParam @PathVariable , @ RequestParam , @ RequestBody注释的参数。 它还记录了以下定制注释: @JsonRequestExample @JsonResponseExample @PossibleResponseStatuses 这些批注在中声明。 使用...
SpringMVC的相关用法主要内容@RequestMapping注解中相关参数的意义参考RequestMappingController类.Controller中方法的参数可以定义的类型统计普通常用的基本参数没有写, 介绍了一些稍微冷门但是还有点用的, 参考...
web项目设置在Servlet的context parameter中 事件Application Event 自定义事件,集成ApplicationEvent 定义事件监听器,实现ApplicationListener 使用容器发布事件 Spring高级话题 Spring Aware ...
1、扫描包下的controller注解类 2、扫描controller类型下RequestMapping注解的方法 3、获取方法的请求参数类,并获取参数类中的非静态参数
SpringMVC第一天 框架课程 ...5、设置sql语句中的参数(使用preparedStatement) 6、通过statement执行sql并获取结果 7、对sql执行结果进行解析处理 8、释放资源(resultSet、preparedstatement、connection)
一个code200,404来告诉具体状态,用一个const类存不同状态对应的code值,用resultgenerator来按照controller的逻辑修改result的参数(通过setter), 最后result的值和信息通过@RequestMapping指定的路径在访问这个...