Is received parameter date type

1.1 New Dynamic web project

 1.2 Related jar package introduced springmvc

 

 1.3 web.xml configuration file (plugin has been installed, use plug-ins to load and then modify the relevant parameters, keyboard shortcut: Alt + /)

* Modify the following places

 

 

 Create a Spring Bean Configuration File 1.4 files, configuration springmvc configuration file (xml file name created with the need to control the web.xml file name after the classpath)

* Jar using a plug introduced into the package path

 * Add a package scanning on drive viewresolver

 

1.5 New view files in the folder WEB-INF directory, add index.jsp file

 * Note: The resources under WEB-INF, can not be accessed directly through the browser can not be accessed by redirecting only by forwarding the request to access

Example 1.6 In User controller to package, creating UserController class, add related method of receiving a single reference parameter, return type String, Date type parameter or parameters for the method receives User entity class

way1: Use @InitBinder date type of process data

复制代码
@InitBinder. 1 
2 public void of an initBinder (ServletRequestDatabinder Binder) { 
. 3 // long page data from the format of yyyy-MM-dd will be converted to the Date type 
4 binder.registerCustomEditor (Date.class, new CustomDateEditor ( new SimpleDateFormat ( "the MM-dd-YYYY"), 
. 5 to true)); 
. 6}
复制代码

 

* Parameter received as an entity class

 way2: encapsulated entity class, the entity class used @DateTimeFormat (pattern = "yyyy-MM-dd")

 

 1.7在WebContent目录下添加login.jsp文件

注意:input标签中name属性的值,要与controller方法中的参数一样,

Guess you like

Origin www.cnblogs.com/lwgok1003/p/11548134.html