java

controller配置

rzk · 4月10日 · 2020年本文共816个字 · 预计阅读3分钟100次已读
//声明Spring类的实例是一个控制器
@Controller
//@RequestMapper注解用于映射url到控制器或一个特定的处理程序方法,可用于类和方法
@RequestMapping
 1 
 2  3          xmlns_xsi="http://www.w3.org/2001/XMLSchema-instance"
 4          xsi_schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
 5          version="4.0">
 6     
 7     
 8         srpingmvc
 9         class>org.springframework.web.servlet.DispatcherServletclass>
10         
11             contextConfigLocation
12             classpath:springmvc-servlet.xml
13         
14         1
15     
16     
17     
18         srpingmvc
19         /
20     
21     
22 

 1 
 2  3        xmlns_xsi="http://www.w3.org/2001/XMLSchema-instance"
 4        xmlns_context="http://www.springframework.org/schema/context"
 5        xmlns_mvc="http://www.springframework.org/schema/mvc"
 6        xsi_schemaLocation="http://www.springframework.org/schema/beans
 7         https://www.springframework.org/schema/beans/spring-beans.xsd
 8         http://www.springframework.org/schema/context
 9         http://www.springframework.org/schema/context/spring-context.xsd
10         http://www.springframework.org/schema/mvc
11         http://www.springframework.org/schema/mvc/spring-mvc.xsd">
12     
13     package="com.rzk.controller"/>
14 
15 
16 
17 
18 
19    
20     class="org.s睿共享pringframework.web.servlet.view.InternalResourceViewResolver"
21           id="InternalResourceViewResolver">
22         
23         
24         
25         
26     
27 
28 

实现多个请求指向一个视图,但页面结果的显示是不一样的,可以实现视图的复用性,而控制器和视图之间弱耦合关系

 1 @Controller
 2 public class ControllerDome2 {
 3     @RequestMapping(path = "/t1"睿共享)
 4     public String demo1(Model model){
 5 
 6         model.addAttribute("hello","你好1");
 7         /*这里的Login要对应jsp的名字*/
 8         return "Login";
 9     }
10     @RequestMapping(path = "/t2")
11     public String demo2(Model model){
12 
13         model.addAttribute("hello","你好2");
14         /*这里的Login要对应jsp的名字*/
15         return "Login";
16     }
17     @RequestMapping(path = "/t3")
18     public String demo3(Model model){
19 
20         model.addAttribute("hello","你好3");
睿共享21         /*这里的Login要对应jsp的名字*/
22         睿共享return "Login";
23     }
24 }
睿共享

Login.jsp页面


${hello}

controller配置

controller配置

0 条回应