springmvc @RequestMapping注解的入门配置教程
2016-09-20 10:04
519 查看
原文:springmvc
@RequestMapping注解的入门配置教程
源代码下载地址:http://www.zuidaima.com/share/1837785387207680.htm
直接代码喽。
DispatcherServle
/appointments/new.do
映射方法是getNewForm()
/appointments.do
GET请求映射方法是 get()
POST请求映射方法是add(@Valid AppointmentForm appointment, BindingResult result)
通过参数条件缩小路径映射
URL中只有存在myParam=myValue参数时才被允许访问路径映射的方法
只有在URL的头信息中包含有content-type=text/*(content-type=text/xml)的POST请求才能访问add()方法
配合@RequestMapping使用的方法或注解
org.springframework.web.context.request.WebRequest或org.springframework.web.context.request.NativeWebRequest。通用请求参数允许访问 request/session属性,到本机的Servlet / Portlet API的。
java.util.Locale 当前请求的区域设置,由解析器提供最具体的语言环境。
java.io.InputStream /java.io.Reader访问请求的内容。这个值是原始的InputStream /Reader ,由Servlet API公开。
java.io.OutputStream /java.io.Writer生成响应的内容。这个值是原始的OutputStream /Writer,由Servlet API公开。
@ PathVariable注明获取URI模板变量的参数。
@ RequestParam注明为获取特定的servlet请求参数的参数。
@ RequestHeader 访问特定的servlet请求的HTTP头的参数。参数值转换为声明的方法的参数类型。
@ RequestBody 访问HTTP请求体参数。参数值转换为所声明的方法的参数类型使用HttpMessageConverters。
HttpEntity <?>访问servlet请求的HTTP头和内容。请求流将被转换为实体采用HttpMessageConverters。
java.util.Map/ org.springframework.ui.Model /org.springframework.ui.ModelMap为丰富的隐含模型,暴露在Web视图
org.springframework.validation.Errors / org.springframework.validation.BindingResult
org.springframework.web.bind.support.SessionStatus
原文地址:http://www.blogjava.net/wmcoo/articles/333428.html
@RequestMapping注解的入门配置教程
源代码下载地址:http://www.zuidaima.com/share/1837785387207680.htm
直接代码喽。
@Controller @RequestMapping("/appointments") public class AppointmentsController { private final AppointmentBook appointmentBook; @Autowired public AppointmentsController(AppointmentBook appointmentBook) { this.appointmentBook = appointmentBook; } @RequestMapping(method = RequestMethod.GET) public Map<String, Appointment> get() { return appointmentBook.getAppointmentsForToday(); } @RequestMapping(value="/{day}", method = RequestMethod.GET) public Map<String, Appointment> getForDay(@PathVariable @DateTimeFormat(iso=ISO.DATE) Date day, Model model) { return appointmentBook.getAppointmentsForDay(day); } @RequestMapping(value="/new", method = RequestMethod.GET) public AppointmentForm getNewForm() { return new AppointmentForm(); } @RequestMapping(method = RequestMethod.POST) public String add(@Valid AppointmentForm appointment, BindingResult result) { if (result.hasErrors()) { return "appointments/new"; } appointmentBook.addAppointment(appointment); return "redirect:/appointments"; } }
DispatcherServle
<servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping>
/appointments/new.do
映射方法是getNewForm()
/appointments.do
GET请求映射方法是 get()
POST请求映射方法是add(@Valid AppointmentForm appointment, BindingResult result)
通过参数条件缩小路径映射
@RequestMapping(value = "/path", params="myParam=myValue") public void add(){...}http://localhost:8080/DynamicWebProject/hao/hello.do?myParam=myValue
URL中只有存在myParam=myValue参数时才被允许访问路径映射的方法
@RequestMapping(value = "/path", method = RequestMethod.POST, headers="content-type=text/*") public void add(){...}
只有在URL的头信息中包含有content-type=text/*(content-type=text/xml)的POST请求才能访问add()方法
配合@RequestMapping使用的方法或注解
org.springframework.web.context.request.WebRequest或org.springframework.web.context.request.NativeWebRequest。通用请求参数允许访问 request/session属性,到本机的Servlet / Portlet API的。
java.util.Locale 当前请求的区域设置,由解析器提供最具体的语言环境。
java.io.InputStream /java.io.Reader访问请求的内容。这个值是原始的InputStream /Reader ,由Servlet API公开。
java.io.OutputStream /java.io.Writer生成响应的内容。这个值是原始的OutputStream /Writer,由Servlet API公开。
@ PathVariable注明获取URI模板变量的参数。
@ RequestParam注明为获取特定的servlet请求参数的参数。
@ RequestHeader 访问特定的servlet请求的HTTP头的参数。参数值转换为声明的方法的参数类型。
@ RequestBody 访问HTTP请求体参数。参数值转换为所声明的方法的参数类型使用HttpMessageConverters。
HttpEntity <?>访问servlet请求的HTTP头和内容。请求流将被转换为实体采用HttpMessageConverters。
java.util.Map/ org.springframework.ui.Model /org.springframework.ui.ModelMap为丰富的隐含模型,暴露在Web视图
org.springframework.validation.Errors / org.springframework.validation.BindingResult
org.springframework.web.bind.support.SessionStatus
原文地址:http://www.blogjava.net/wmcoo/articles/333428.html
相关文章推荐
- websocket请求用自定义注解@WSRequestMapping访问,类似springmvc @RequestMapping访问。
- springboot 入门教程(3)-运行原理、关键注解和配置
- springmvc RequestMapping注解做伪静态的坑
- SpringMvc @Requestmapping参数配置
- SpringMVC RequestMapping注解详解
- SpringMVC RequestMapping注解详解
- 基于注解的Spring MVC+Hiberntae简单入门
- springmvc No mapping found for HTTP request with URI in Dispatc
- Spring 3.0.5 MVC 基于注解ehcache.xml 配置方式
- Spring 3.0.5 MVC 基于注解ehcache.xml 配置方式
- 【#】Spring3 MVC 注解(一)---注解基本配置及@controller和 @RequestMapping 常用解释
- Spring&nbsp;mvc中@RequestMapping…
- Spring 的MVC @RequestMapping
- spring3 mvc系列一:架构基本配置(注解版)
- Spring MVC注解配置结合Hibernate的入门教程及其代码实例
- spring-mvc入门(五):使用注解(下)
- 第十五章 Spring基于注解的配置(Spring Framework3.1教程)
- Spring入门Blog[五、Spring容器组建注解@Component和Resouces实现完全注解配置]
- Spring mvc (六) [基于注解的spring3 mvc的基本配置和交互原理][注解模板传参]
- Spring3 MVC 注解---注解基本配置及@controller和 @RequestMapping 常用解释