springMVC注解中之@RequestMapping注解及常用参数
来源:互联网 发布:举牌软件下载 编辑:程序博客网 时间:2024/05/16 07:34
- package cn.hive.action;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.PathVariable;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestParam;
- /**
- * Created with IntelliJ IDEA.
- * Author: DAX
- * Date: 2016/10/13
- * 测试action类
- * Time: 20:08
- */
- @Controller
- @RequestMapping(value = "/{abc}")
- public class InitAction {
- /*
- * @RequestMapping value 和params 的详解
- *
- *
- * 如类没有定义请求映射 类方法中的value代表根路径 如果在类方法中有点类似于struts中 action的id
- * params 为请求参数的数组 支持一些简单的表达式 params={"!id","name!=James"} 表示不能带名称为id的参数 而且name的值不能为James 等等表达式
- *
- * @RequestMapping(value = "/init", params = {"id=myValue"}) 只有存在了请求参数id=myValue /init.action?id=myValue 才会被initData处理
- * @RequestMapping(value = "/init", params = {"name=kobe", "number=23"}) /init.action?name=kobe&&number=23 否则 404错误
- *
- * 一旦abc init 为占位符即用{}包括起来 该请求默认为下面
- * http://localhost:8080/abc/init.action
- * 如果被赋值 例如 abc = "hello"; init = "world"; 则下面网址也可以访问ininData方法
- * http://localhost:8080/hello/world.action
- * 这形成了具有REST(表现层状态转化)风格的请求形式 表示 abc 的id为 init的实际赋值 但是请求的方法必须为GET
- *
- * @RequestParam 详解 接收 请求参数
- * required参数默认为false 表示 可以为空
- * 如果为 数据的基本类型 一旦没有赋值 提交 会被赋值null
- * 抛出异常 一般推荐用包装类 来接收 比如 int 用 Integer double 用Double 等
- */
- @RequestMapping(value = "/{init}")
- public String initData(@PathVariable("abc") String abc, @PathVariable("init") String init, @RequestParam(value = "name", required = false) String name, @RequestParam(value = "age", required = false) Integer age) {
- abc = "hello";
- init = "world";
- System.out.println(name + age);
- return "test";
- }
- }
value的uri值为以下三类:
A) 可以指定为普通的具体值;
B) 可以指定为含有某变量的一类值(URI Template Patterns with Path Variables);
C) 可以指定为含正则表达式的一类值( URI Template Patterns with Regular Expressions);
阅读全文
0 0
- springMVC注解中之@RequestMapping注解及常用参数
- springmvc注解之@RequestMapping注解
- SpringMVC之@RequestMapping注解
- springmvc 注解之 @RequestMapping
- springmvc常用注解之@Controller和@RequestMapping
- springmvc常用注解之@Controller和@RequestMapping
- springmvc常用注解之@Controller和@RequestMapping
- springmvc常用注解之@Controller和@RequestMapping
- springmvc常用注解之@Controller和@RequestMapping
- springmvc常用注解之@Controller和@RequestMapping
- 【springMVC 学习三】springmvc常用注解之@Controller和@RequestMapping
- springMVC注解中@RequestMapping中常用参数value params 以及@RequestParam 详解
- springmvc注解开发之requestMapping
- SpringMVC之RequestMapping注解详解
- SpringMVC中@RequestMapping处理请求参数的@RequestParam注解
- springmvc常用注解之@Controller和@RequestMapping概要说明
- 【3】springmvc常用注解之@Controller和@RequestMapping
- SpringMVC中@Controller和@RequestMapping用法和其他常用注解
- [Leetcode] 381. Insert Delete GetRandom O(1)
- HDU 2665 个人理解(主席树)
- python属性查找 深入理解(attribute lookup)
- ajax标准格式
- Sass 与 SCSS
- springMVC注解中之@RequestMapping注解及常用参数
- android 自定义跑马灯(不限制字体长度且字体居中)
- Use UMDH to identify memory leak problem
- ViewPager 指示器
- POJ 3690 Constellations + Gym
- Maven构建忽略测试失败
- 自定义AlertDialog
- Android 界面滑动实现---Scroller类 从源码和开发文档中学习(让你的布局动起来)
- Retrofit2.0的使用及原理解析