`
Copperfield
  • 浏览: 254411 次
  • 性别: Icon_minigender_1
  • 来自: 上海
博客专栏
C407adc3-512e-3a03-a056-ce4607c3a3c0
java并发编程陷阱
浏览量:24592
社区版块
存档分类

spring3学习笔记(1)-----RequestMapping与页面路径

 
阅读更多

@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 映射请求

    Spring MVC--2.@RequestMapping 映射请求

    springboot 基础简易实例, maven项目

    import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; // @RestController返回的是json @RestController public class ...

    springboot学习思维笔记.xmind

    springboot学习笔记 spring基础 Spring概述 Spring的简史 xml配置 注解配置 java配置 Spring概述 Spring的模块 核心容器CoreContainer Spring-Core Spring-Beans ...

    Spring MVC 学习笔记 五 controller与requestmapping

    工程文件 博文链接:https://starscream.iteye.com/blog/1063966

    spring-web-5.3.6 jar包.rar

    这个jar文件包含Web应用开发时,用到Spring框架时所需的核心类, 包括自动载入WebApplicationContext特性的类、Struts与JSF集成类、文件上传的支持类、Filter类和大量工具辅助类。 spring的核心类,提供了核心HTTP...

    获取RequestMapping所有的方法和路径|SpringMvc的Controller

    通过编译文件的class路径,反射得到Class,获取RequestMapping对应注解和value路径

    Spring注解 - 52注解 - 原稿笔记

    在火狐中显示可能会有问题,大家都是... @RequestMapping , @RequestParam , @Resource , @ResponseBody , @RestController , @Scope , @Service , @Validated , @Value , @WebFilter , @WebInitParam , @WebListener

    基于框架的Web开发-RequestMapping通配符和占位符.doc

    1 @RequestMapping注解 类上指定的URL相对于应用根目录 @RequestMapping注解可以使用在控制器类和控制器类的方法上,一般情况下,类定义处的@ RequestMapping提供初步的请求映射信息,方法定义处的@ RequestMapping ...

    spring-boot-reference.pdf

    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. ...

    spring-framework-reference-4.1.2

    3. New Features and Enhancements in Spring Framework 4.0 ............................................ 17 3.1. Improved Getting Started Experience .........................................................

    spring-web-2.5.jar

    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

    xss-filter-spring-boot-starter springboot自动xss 使用方法在项目的pom.xml中加入依赖即口 &lt;groupId&gt;com.djk&lt;/groupId&gt; &lt;artifactId&gt;xss-filter-spring-boot-starter &lt;version&gt;0.0.1 目前支持3种入参数xss...

    spring-boot-kibernetes-config-map:在Spring Boot应用程序中使用Kubernetes ConfigMap

    1. Spring Boot Application属性 首先,让我们向MVC控制器添加简单的启动属性,没什么大不了的: @RestController public class ControllerMVC { @Value ( " ${my.system.property:defaultValue} " ) protected ...

    spring-boot-example-smallest:春天引导示例最小

    - |-- |-- entity|-- |-- |-- repository|-- |-- |-- controller|-- test休息api GETPOSTPUTPATCHDELETE 1,Maven pom.xml 2,Spring MVC(*)RestController RequestMapping GetMapping PostMapping 3,JSON(*) 5...

    carcar.sql

    spring-boot很多配置都有默认配置,比如默认页面映射路径为 classpath:/templates/*.html 同样静态文件路径为 classpath:/static/ 在application.properties中可以配置thymeleaf模板解析器属性.就像使用springMVC...

    Spring MVC之@RequestMapping详解

    前段时间项目中用到了REST风格来开发程序,但是当用POST、PUT模式提交数据时,发现服务器端接受不到提交的数据(服务器端参数绑定没有加任何注解),查看了提交方式为application/json, 而且服务器端通过request....

    spring-boot-1-performance:Spring Boot 1.x性能指标

    Spring引导1性能Spring Boot 1.5.14性能指标,带有简单的ping控制器,没有任何业务逻辑。 /src/main/java/StatusController.java @RestController@RequestMapping ( " /api " )public class StatusController { @...

    spring-web.jar

    spring-web.jar(springmvc所需jar包@RequestMapping注解依赖包)

    详解获取Spring MVC中所有RequestMapping以及对应方法和参数

    本篇文章主要介绍了详解获取Spring MVC中所有RequestMapping以及对应方法和参数,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。

Global site tag (gtag.js) - Google Analytics