Simple analysis and application of the principle of converter realization of DWR

Source: Internet
Author: User
Tags integer

We use DWR to invoke the remote method to involve the data conversion between JS and JAVA parameters and return values, for example:

The conversion between JS 123 and Java int or Integer, long

The conversion between JS "2009-06-23" and Java java.util.Date

Conversion between JS "[1,2,3]" and Java int[]

JS "{id:123, Name: ' Unmi '}" and Java Class person{int ID; Conversion between String name}

or more complex nested types ("{id:123, Name: ' Unmi ', blogs: [' http://unmi.blogjava.net ', ' Http://blog.csdn.net/kypfos ']}") and conversions between Java types Wait a minute. So how did all this happen? In fact, we have seen a lot of component type mappings, such as Java PropertyEditor, Hibernate (usertype), IBatis (Typehandler) type mappings, STRUTS1/2 used in Form/model Converter and so on.

Here I will analyze the Converter implementation of DWR and explain how to customize my Converter. The DWR used in this article is the 2.0.5 version.

1. DWR built-in Converter and application types

Name Type of application Converters
Null Void,java.lang.void Nullconverter
Enum   Enumconverter
Primitive Boolean,byte,short,int,
Long,float,double,char,

Java.lang.boolean,java.lang.byte,
Java.lang.Short,

Java.lang.integer,java.lang.long,
Java.lang.Float,

Java.lang.double,java.lang.character

Primitiveconverter
BigNumber Java.math.biginteger,java.math.bigdecimal Bignumberconverter
String Java.lang.String Stringconverter
Array [z,[b,[s,[i,[j,[f,[d,[c,[l* Arrayconverter
Map Java.util.Map Mapconverter
Collection Java.util.Collection Collectionconverter
Date Java.util.date,java.sql.date,
Java.sql.Time,

Java.sql.Timestamp,
Java.util.Calendar

DateConverter
Dom Org.w3c.dom.node,org.w3c.dom.element,
Org.w3c.dom.Document
Domconverter
dom4j Org.dom4j.document,org.dom4j.element,
Org.dom4j.Node
Dom4jconverter
Jdom Org.jdom.document,org.jdom.element Jdomconverter
Xom Nu.xom.document,nu.xom.element,
Nu.xom.Node
Xomconverter
Servlet Javax.servlet.ServletConfig,
Javax.servlet.ServletContext,

Javax.servlet.http.HttpServletRequest,

Javax.servlet.http.HttpServletResponse,

Javax.servlet.http.HttpSession

Servletconverter
Bean   Beanconverter
Object   Objectconverter
Hibernate2   H2beanconverter
Hibernate3   H3beanconverter
Url Java.net.URL Urlconverter
exception   Exceptionconverter
Miniexception Java.lang.Throwable Minimalistexceptionconverter

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.