Struts 2 built-in type converter

Source: Internet
Author: User

For most common types, developers do not need to care about type conversion. Struts 2 can complete most common type conversion tasks. These common types are converted using the built-in type converter of Struts 2. Struts 2 has built in the conversion between the string type and the following types.

Boolean and Boolean: converts the string and boolean values.

Ø char and Character: converts strings and characters.

Int and Integer: converts the string and Integer values.

Ø long and Long: converts string and long integer values.

Ø float and Float: converts a string to a single-precision floating point value.

Ø double and Double: Convert the string and double-precision floating point values.

Ø Date: converts string and Date types. The Date format uses the SHORT format of the Locale where the user request is located.

Ø array: by default, the array element is a string. If you provide a custom type converter, it can also be an array of other composite types.

Ø set: by default, it is assumed that the element type of the set is String and a new ArrayList is created to encapsulate all strings.

For array type conversion, each element is converted separately according to the type of array elements. However, if the type conversion of array elements cannot be completed, the system will encounter a type conversion error.

Because Struts 2 provides the above types of converters, if you need to convert HTTP request parameters to the above types, you do not need to perform any special processing. Therefore, in most actual development, developers do not need to convert their own types.

 

This article from the "crazy Java Li Gang" blog, please be sure to keep this source http://javaligang.blog.51cto.com/5026500/871582

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.