One, (supplemental) View Parser---Xmlviewresolver
function : Separates configuration information.
Expands on the view parser---beannameviewresolver, creating a new myview.xml separation information
Configuring Xmlviewresolver in Applicationcontext.xml, and processor configuration
Myview.xml:
Implementation results:
Second, SPRINGMVC annotation development
Two commonly used annotations:
@Controller: is the most commonly used annotation in SPRINGMVC, which can help define the current class as a spring-managed bean, specifying that the class is a controller that can be used to accept requests. Identifying the current class is a concrete implementation of the control layer
@requestMapping: Put on a method to specify the path to a method, when it is placed on the class equivalent to the namespace needs to requestmapping on the combination method to access
Expand:
Note Name |
Role |
@Controller |
Annotations indicate that the class requires the spring container to be loaded automatically, and a class to be the Bean of the spring container. |
@RequestMapping |
It can be labeled at the class definition, associating a Controller with a specific request, or it can be labeled at the method signature. So the @RequestMapping labeled at the class declaration is equivalent to having POJO implement the Controller interface, and the @RequestMapping at the method definition is equivalent to having the POJO extend the Spring predefined controller (such as Simp Leformcontroller, etc.). |
@Resource |
The setter method parameter that is used to annotate the attribute is derived from the spring Bean |
@ModelAttribute |
① bind request parameter to command object: When placed on the parameter of the function processing method, it is used to bind multiple request parameters to a command object, thus simplifying the binding process and automatically exposing the model data for use in view page presentation; ② exposes a form reference object as model data: when placed on a processor's general method (non-functional processing method), it is the form reference object that prepares the form for presentation, such as the city that needs to be selected when registering, and before performing the function processing method (@RequestMapping annotation method), Automatically added to the model object for use when the view page is displayed; ③ Exposure @requestmapping method returns a value of model data: when placed on the return value of a function processing method, the return value of the exposed function processing method is the model data that is used when the view page is displayed. |
@SessionAttributes |
Represents the annotated object that is stored in the httpsession scope |
@PathVariable |
Used to map template variables in the request URL to parameters of a functional processing method |
@requestParam |
Used to map the request parameter area data to the parameters of a functional processing method |
Introductory Case:
①SPRINGMVC Package Scanner:
Because of the use of note-based controllers, this specifies the path of the package that needs to be scanned, if more than one can be separated by commas.
Processor class: [ N Processor methods can also be defined in a processing class ]
2. Wildcard usage in a request
Implementation results:
3, the definition of the way in the request
For @requestmapping, there is an attribute method that restricts the way a request is submitted by the annotated method, and only the method specified by the methods property is satisfied to execute the annotated methods. The value of the method property is Requestmethod, which is an enumeration constant . Common values are requestmethod.get and requestmethod.post
4, the parameters of the processor method
There are five types of parameters commonly used in processor methods, which are automatically assigned by the system when the system is called, that is, the programmer can use it directly within the method:
①httpservletrequest
②httpservletresponse
③httpsession
④ model for carrying data
Request parameters that are carried in the ⑤ request
Top three ways to implement:
@RequestMapping (value= "/one.do", method=requestmethod.get) public String Dofirst (HttpServletRequest request, HttpServletResponse response,httpsession session) {SYSTEM.OUT.PRINTLN (request); SYSTEM.OUT.PRINTLN (response); SYSTEM.OUT.PRINTLN (session); return "index";}
Model for hosting data: fragmented parameters
@RequestMapping (value= "/one.do", method=requestmethod.get) public String Dofirst (model model) {Map<string,object > Datas=new hashmap<string, object> ();d atas.put ("uname", "tease ^^"); Model.addallattributes (datas); SYSTEM.OUT.PRINTLN (model); return "index";}
Object parameters: Assembling into entities
Custom entity classes: UserInfo
public class UserInfo {private string Uname;public string Getuname () {return uname;} public void Setuname (String uname) {this.uname = uname;}
The Firstcontroller controller class method parameter is an entity class object:
@Controller @requestmapping (value= "/con") public class firstcontroller{@RequestMapping (value= "/dofirst.do") public String Dofirst (UserInfo info) {System.out.println (Info.getuname ()); return "Index";}}
Large configuration:
JSP page Form form submission:
Implementation results:
The console will appear garbled, how to solve?
5, solve garbled problem: Web. XML configuration Encoding Filter---characterencodingfilter
Preliminary development of SPRINGMVC annotation