Write framework together-MVC Framework-basic functions-simple data type parameter binding (6),-mvc Data Type

Source: Internet
Author: User

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

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.