@RequestMapping的参数如下
/**
* @see RequestMapping 参数
* @param value
* 需要跳转的地址
* @param mehtod
* 基于RestFul的跳转参数,有RequestMethod.get post,put 等
* @param params
* 符合某个参数的时候才调用该方法
* @param headers
* 符合头信息的时候才调用
* */
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp"></property>
</bean>
@Controller
@RequestMapping("/test")
public class HelloWorldController {
static Logger logger = Logger.getLogger(HelloWorldController.class.getName());
@RequestMapping("/hello")
public void Hello() {
logger.info("The hello() method is use");
}
根据以上配置,方法无返回值时,默认寻找以下路径:spring3.X/WEB-INF/jsp/test/hello
.jsp
prefix+类路径(类级别的mapping注解)+方法路径(方法级别的mapping注解)+prefix
修改代码返回ModelAndView对象:
@RequestMapping("/hello")
public ModelAndView Hello() {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("hello");
return modelAndView;
}
路径:spring3.X/WEB-INF/jsp/hello
.jsp(prefix+viewName+suffix)。
返回Map对象:
@SuppressWarnings("unchecked")
@RequestMapping("/hello")
public Map Hello() {
Map map = new HashMap();
map.put("map","hello");
return map;
}
路径:spring3.X/WEB-INF/jsp/test/hello.jsp,和第一种方法无返回值的情况类似:
prefix+类路径(类级别的mapping注解)+方法路径(方法级别的mapping注解)+suffix
返回一个ModelMap类型,使用modelMap.addAllAttributes将map中的所有元素添加到modelMap中,并显示到页面上。
@SuppressWarnings("unchecked")
@RequestMapping("/hello")
public ModelMap Hello() {
ModelMap modelMap = new ModelMap();
HashMap hashMap = new HashMap();
hashMap.put("h", "hello");
modelMap.addAttribute("w", "world");
/** Copy all attributes in the supplied Collection into this Map, using attribute name generation for each element.**/
modelMap.addAllAttributes(hashMap);
return modelMap;
}
路径:spring3.X/WEB-INF/jsp/test/hello.jsp
prefix+类路径(类级别的mapping注解)+方法路径(方法级别的mapping注解)+suffix
<body>
页面路径:hello/hello.jsp
<br />
${h},${w}
</body>
- 大小: 8.2 KB
分享到:
相关推荐
Spring MVC--2.@RequestMapping 映射请求
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; // @RestController返回的是json @RestController public class ...
springboot学习笔记 spring基础 Spring概述 Spring的简史 xml配置 注解配置 java配置 Spring概述 Spring的模块 核心容器CoreContainer Spring-Core Spring-Beans ...
工程文件 博文链接:https://starscream.iteye.com/blog/1063966
这个jar文件包含Web应用开发时,用到Spring框架时所需的核心类, 包括自动载入WebApplicationContext特性的类、Struts与JSF集成类、文件上传的支持类、Filter类和大量工具辅助类。 spring的核心类,提供了核心HTTP...
通过编译文件的class路径,反射得到Class,获取RequestMapping对应注解和value路径
在火狐中显示可能会有问题,大家都是... @RequestMapping , @RequestParam , @Resource , @ResponseBody , @RestController , @Scope , @Service , @Validated , @Value , @WebFilter , @WebInitParam , @WebListener
1 @RequestMapping注解 类上指定的URL相对于应用根目录 @RequestMapping注解可以使用在控制器类和控制器类的方法上,一般情况下,类定义处的@ RequestMapping提供初步的请求映射信息,方法定义处的@ RequestMapping ...
11.3.1. The @RestController and @RequestMapping Annotations 11.3.2. The @EnableAutoConfiguration Annotation 11.3.3. The “main” Method 11.4. Running the Example 11.5. Creating an Executable Jar 12. ...
3. New Features and Enhancements in Spring Framework 4.0 ............................................ 17 3.1. Improved Getting Started Experience .........................................................
org.springframework.remoting.caucho.Hessian1SkeletonInvoker.class org.springframework.remoting.caucho.Hessian2SkeletonInvoker.class org.springframework.remoting.caucho.HessianClientInterceptor.class ...
xss-filter-spring-boot-starter springboot自动xss 使用方法在项目的pom.xml中加入依赖即口 <groupId>com.djk</groupId> <artifactId>xss-filter-spring-boot-starter <version>0.0.1 目前支持3种入参数xss...
1. Spring Boot Application属性 首先,让我们向MVC控制器添加简单的启动属性,没什么大不了的: @RestController public class ControllerMVC { @Value ( " ${my.system.property:defaultValue} " ) protected ...
- |-- |-- entity|-- |-- |-- repository|-- |-- |-- controller|-- test休息api GETPOSTPUTPATCHDELETE 1,Maven pom.xml 2,Spring MVC(*)RestController RequestMapping GetMapping PostMapping 3,JSON(*) 5...
spring-boot很多配置都有默认配置,比如默认页面映射路径为 classpath:/templates/*.html 同样静态文件路径为 classpath:/static/ 在application.properties中可以配置thymeleaf模板解析器属性.就像使用springMVC...
前段时间项目中用到了REST风格来开发程序,但是当用POST、PUT模式提交数据时,发现服务器端接受不到提交的数据(服务器端参数绑定没有加任何注解),查看了提交方式为application/json, 而且服务器端通过request....
Spring引导1性能Spring Boot 1.5.14性能指标,带有简单的ping控制器,没有任何业务逻辑。 /src/main/java/StatusController.java @RestController@RequestMapping ( " /api " )public class StatusController { @...
spring-web.jar(springmvc所需jar包@RequestMapping注解依赖包)
本篇文章主要介绍了详解获取Spring MVC中所有RequestMapping以及对应方法和参数,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。