@Controller Controller is defined in Spring 3.0, Class can be defined as a Controller class using the @Controller annotation. To enable springMVC to find the bean defined as controller, add it to the servlet-Context configuration file

The following definition:

<context:component-scan base-package=”com.xxx.controller”/> <context:component-scan base-package=”com.xxx.controller”/>

RequestMapping is defined in front of the class to bind the URL to the class.

Defined in front of a method, the URL is bound to the class’s method

//url: http://localhost:8080/springmvc01/hello2/test01.do

@RequestMapping(“test01”)

public ModelAndView test01(){

ModelAndView mv=new ModelAndView(); 

mv.setViewName("hello"); 

mv.addObject("hello", "hello test01"); 

return mv; 
Copy the code

}

//url: http://localhost:8080/springmvc01/hello2.do? test01

@RequestMapping(params=”test02″)

public ModelAndView test02(){

ModelAndView mv=new ModelAndView(); 

mv.setViewName("hello"); 

mv.addObject("hello", "hello test02"); 

return mv; 
Copy the code

}

//url: http://localhost:8080/springmvc01/hello2/test03.do

@RequestMapping(“test03”)

public String test03(Model model){ 

model.addAttribute("hello", "hello test03"); 

return "hello"; 
Copy the code

}

//url: http://localhost:8080/springmvc01/hello2/test04.do

@RequestMapping(“test04”)

public String test04(ModelMap modelMap){

modelMap.addAttribute("hello", "hello test04"); 

return "hello"; 
Copy the code

}

//url: http://localhost:8080/springmvc01/hello2/test05.do

@SuppressWarnings(“unchecked”)

@RequestMapping(“test05”)

public String test05(Map model){

model.put("hello", "hello test05 "); 

return "hello"; 
Copy the code

} @sessionAttributes is used to declare session-level storage attributes to be placed on the processor class.

@Controller

@sessionAttributes ({“userName”})// userName adds to session

public class UserController {

@RequestMapping("/queryUser") 

public ModelAndView queryUser(String userName){ 

    ModelAndView mv=new ModelAndView(); 

    mv.addObject("userName", userName); 

    mv.setViewName("user"); 

    return mv; 

} 
Copy the code

} page value

${sessionScope.a}|||${sessionScope.b} 
Copy the code

Jsp+servlet> Struts1 > Spring MVC > Struts2 +freemarker> Struts2, OGNL, value stack

In terms of development efficiency, it is basically the opposite. It’s worth noting that Spring MVC is about as effective as Struts2 in terms of development efficiency, but by now spring MVC is far more popular than Struts2.

Struts2’s poor performance is due to OGNL(an expression language with a simple and consistent expression syntax that allows access to arbitrary properties of objects, calls to methods of objects, and is used in conjunction with the Struts2 framework) and the value stack (simply a stack of Struts2 actions). So, if your system has high concurrency, you can use Freemaker instead of OGNL and value stacks. This can result in a considerable improvement in performance.