1.

@Controller
@RequestMapping(path = "/user")//一级目录
public class FormSubmit {
@RequestMapping(path = "/save")//二级目录 /user/save
public String typeCase(@RequestParam(name = "name") String username, User user, HttpServletRequest request//获得原生的Servlet API) {
return "success";
}
}
注解 解释

@RequestMapping

RequestMapping是一个用来处理请求地址映射的注解,可用于类或方法上。用于类上,表示类中的所有响应请求的方法都是以该地址作为父路径。

属性:

value:     指定请求的实际地址,指定的地址可以是URI Template 模式,@RequestMapping 中还支持通配符“* ”

method:  指定请求的method类型, GET、POST、PUT、DELETE等

consumes: 指定处理请求的提交内容类型(Content-Type),例如application/json, text/html;

params: 指定request中必须包含某些参数值是,才让该方法处理。

@PathVariable

拿到@RequestMapping(path="/pathVariable/{id}")中{}中携带的参数

(@PathVariable(name="id") String id)

 @RequestHeader  获得指定的请求头(@RequestHeader(value="Accept")  String header)
 @RequestBody  获得所有请求体(@RequestBody String body)
 @RequestParam 当请求中的参数名与映射的接受的参数名不同时,用与接受不同名的参数@RequestParam(name = "name") String username,
 @CookieValue( 获得指定的CookieValue @CookieValue(value="JSESSIONID") String cookie
 @ModeAttribute

@ModeAttribute用在方法上时首先执行该方法以下就叫 frist();方法

@RequestMapping(path = "/modeAttribute")
    public String testModeAttribute(@ModelAttribute(value = "map") User user) {//将map中的值传给user
        System.out.println(user);
        return "success";
    }

@ModelAttribute  //无返回值时将map中的值传给user 有返回值时将返回值传给user
    public void test() {
        User user = new User();
        user.setDate(new Date());
        HashMap<String, User> map = new HashMap<String, User>();
        map.put("User", user);

}

   
   

TZ_06_SpringMVC_常用注解的更多相关文章

  1. Spring系列之Spring常用注解总结

    传统的Spring做法是使用.xml文件来对bean进行注入或者是配置aop.事物,这么做有两个缺点:1.如果所有的内容都配置在.xml文件中,那么.xml文件将会十分庞大:如果按需求分开.xml文件 ...

  2. SpringMVC常用注解實例詳解3:@ResponseBody

    我的開發環境框架:        springmvc+spring+freemarker開發工具: springsource-tool-suite-2.9.0JDK版本: 1.6.0_29tomcat ...

  3. SpringMVC常用注解實例詳解2:@ModelAttribute

    我的開發環境框架:        springmvc+spring+freemarker開發工具: springsource-tool-suite-2.9.0JDK版本: 1.6.0_29tomcat ...

  4. Spring常用注解汇总

    本文汇总了Spring的常用注解,以方便大家查询和使用,具体如下: 使用注解之前要开启自动扫描功能 其中base-package为需要扫描的包(含子包). <context:component- ...

  5. Spring常用注解,自动扫描装配Bean

    1 引入context命名空间(在Spring的配置文件中),配置文件如下: xmlns:context="http://www.springframework.org/schema/con ...

  6. springmvc常用注解与类型转换

    springmvc常用注解与类型转换 一:前置 spring -servlet.xml 注入 <!-- 启用spring mvc 注解 --> <context:annotation ...

  7. SpringMVC常用注解,返回方式,路径匹配形式,验证

    常用注解元素 @Controller 标注在Bean的类定义处 @RequestMapping 真正让Bean具备 Spring MVC Controller 功能的是 @RequestMapping ...

  8. SpringMVC 常用注解

    本文参考了博客,具体请见:http://www.cnblogs.com/leskang/p/5445698.html Spring MVC的常用注解 1.@Controller @Controller ...

  9. spring注解开发中常用注解以及简单配置

    一.spring注解开发中常用注解以及简单配置 1.为什么要用注解开发:spring的核心是Ioc容器和Aop,对于传统的Ioc编程来说我们需要在spring的配置文件中邪大量的bean来向sprin ...

随机推荐

  1. iOS开发系列-网络状态监控

    概述 在网络应用中,需要对用户设别的网络状态进行实时监控,可以让用户了解自己的网络状态出现网络问题提示用户. 一般在网络状态不好的场景下需要做一些处理比如: WIFT/3G/4G网络:自动下载高清图. ...

  2. mysql主从复制linux配置(二进制日志文件)

    安装mysql,两台机器一主(192.168.131.153),一从(192.168.131.154) 主机配置 修改主/etc/my.cnf文件 添加 #server_id=153 ###服务器id ...

  3. JavaScript中定义函数的几种方式

    函数的组成:函数名 + 函数体 1.使用function关键字定义函数 -- 具有优先级,优先将function关键字定义的函数优先执行 function  functionName(arg0, ar ...

  4. SG函数模板(洛谷2197nim游戏

    #include <iostream> #include <cstdio> #include <queue> #include <algorithm> ...

  5. Excel skill: 如何替换换行符,以及如何把一格转换成多行/多列

    http://blog.sciencenet.cn/blog-508298-695290.html 增加一辅助列,用替换函数替换掉软回车.比如A列是数据,从A1开始,则插入B列,B1输入公式=REPL ...

  6. SpringData_02_JPQL查询、SQL查询和方法命名规则查询

    1.使用JPQL的方式查询 JPQL查询:Hibernate提供的是HQL查询,而JPA提供的是JPQL查询语言 使用Spring Data JPA提供的查询方法已经可以解决大部分的应用场景,但是对于 ...

  7. RabbitMQ代码操作之AmqpAdmin和RabbitListener

    AmqpAdmin:RabbitMQ系统管理功能组件(可以创建exchange,queue,Binding) @Test public void createExchange(){ //创建交换器 / ...

  8. 查看pip install *.whl 支持的文件版本

    import pip._internalprint(pip._internal.pep425tags.get_supported())[('cp37', 'cp37m', 'manylinux2010 ...

  9. PAT甲级——A1081 Rational Sum

    Given N rational numbers in the form numerator/denominator, you are supposed to calculate their sum. ...

  10. PAT甲级——A1004 Counting Leaves

    A family hierarchy is usually presented by a pedigree tree. Your job is to count those family member ...