Configuring Scanners in Spring
<!--SPRINGMVC Scanner--
<context:component-scan base-package= "Com.beifeng.servlet"/>
Building a controller class
@Controller
@RequestMapping (value= "/sys/")
Public class Regcontroller {
@RequestMapping (value= "Reg.do", Method=requestmethod. POST)
Public String Reg () {
System. out. println ("-User Registration--");
return "Index";
}
}
Note When using annotations cannot be used The mapping of the class name controller that controls the class, otherwise it will not be found
<bean class= "Org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" ></bean>
The data that receives the foreground form can also be received through the httpservletrequest or through the form field name or through the object.
- Array of receive direct write array
- A date type's receive can be formatted by using the Initbinder function to define the date conversion
/**
* Get page data via HttpServletRequest
*
* @return
*/
@RequestMapping ("Reg1.do")
Public String REG1 (HttpServletRequest request) {
String userId = Request.getparameter ("UserId");
String USERPW = Request.getparameter ("USERPW");
SYSTEM.OUT.PRINTLN ("Account number:" + userId);
System.out.println ("Password:" + USERPW);
Return "index";
}
/**
* Get your Name
*
* @return
*/
@RequestMapping ("Reg2.do")
public string REG2 (string userName) {
System.out.println ("Name:" + userName);
Return "index";
}
@RequestMapping ("Reg3.do")
Public String reg3 (Integer userId, String userName, Date userbrithday) {
SYSTEM.OUT.PRINTLN ("Account number:" + userId);
System.out.println ("Name:" + userName);
System.out.println ("Birthday:" + userbrithday);
Return "index";
}
/**
* Gets the value of the check box: Multiple values
*
* @param Xqs
* @return
*/
@RequestMapping ("Reg4.do")
Public String REG4 (string[] xqs) {
for (String Xq:xqs) {
System.out.println ("Interest:" + XQ);
}
Return "index";
}
/**
* Get page parameters by object
*
* @param Xqs
* @return
*/
@RequestMapping ("Reg5.do")
Public String reg5 (UserInfo user) {
SYSTEM.OUT.PRINTLN (user);
Return "index";
}
/**
* Add time to the property editor
*/
@InitBinder
public void Initbinder (Servletrequestdatabinder bin) {
Bin.registercustomeditor (Date.class, New Customdateeditor (
New SimpleDateFormat ("Yyyy-mm-dd"), true);
}
Spring MVC annotations Access to the controller and how the form data is received, including methods for receiving date types and objects directly