Write framework together-MVC Framework-basic functions-simple data type parameter binding (6),-mvc Data Type
Function implementation
Requirement: Based on the field name of the form, if it is consistent with the variable name of the parameter and the type is compatible, the data is automatically encapsulated into the corresponding automatic.
Supported data types include:
1. Basic data types: long, int, double, float, char, byte, boolean, and short
2. Packaging classes of basic data types: Long, Integer, Double, Float, Character, Byte, Boolean, Short
3. String type: String
There is a difficulty here, because JDK earlier than JDK1.8 does not support directly obtaining parameter names. Even if it is higher than JDK1.8. you need to add the '-parameters' parameter or enable the debug mode '-G' during compilation '.(Trouble)
JDK does not support parameter names. You can only obtain parameter names by reading the class bytecode. If you are interested, take a look at the asm framework.
Implementation
Steps
Test code
1. Test code directory
2. Test page
<% @ Page language = "java" contentType = "text/html; charset = UTF-8" pageEncoding = "UTF-8" %> <! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
3UserController Modification
1/** 2 * registration page 3 * @ param username 4 * @ param password 5 * @ return 6 */7 @ RequestMapping (value = "/register ") 8 public String register (@ Param ("username") String username, @ Param ("password") String password, @ Param ("age") long age, HttpServletRequest request) {9 System. out. println ("username:" + username + ", password:" + password + ", age" + age); 10 System. out. println (request. getRequestURI (); 11 return "redirect:/register. jsp "; 12}
4. Test Results