008-treemap, map and bean cross-transfer, Beanutils.copyproperties (A, b) copy, URL encoding decoding, string completion

Source: Internet
Author: User

1, TreeMap ordered map

Unordered and orderly conversion

Use the default construction method:

 Public extends extends V> m)
2, map and bean Mutual transfer beanutils is located below Org.apache.commons.beanutils.BeanUtils, its method populate function explains as follows: The Complete method:
Beanutils.populate (Object Bean, Map properties),

This method iterates over the key in the Map<key, value>, and if it has this attribute in the bean, assigns the value of the key to the Bean's property.

2.1. Bean converted to map
Person person1=New person ();  Person1.setname ("name1");  Person1.setsex ("sex1");  Map<string, string> map = Beanutils.describe (Person1);  
2.2. Map into Bean
 Public static <T> T Map2bean (map<string, string> Map, class<t> Class1) {  null ;   Try    {  = class1.newinstance ();  Beanutils.populate (bean, map);   Catch  (Exception e) {  e.printstacktrace ();  }    return  bean  ;  
3, Beanutils.copyproperties (A, B) copy

3.1, package Org.springframework.beans;

Beanutils.copyproperties (A, b);//a→b is the value in a.

3.2, package org.apache.commons.beanutils; (common)

Beanutils.copyproperties (A, b);//b→a is a value in

3.3, package org.apache.commons.beanutils; (common)

Propertyutils.copyproperties (A, b);//b→a is a value in

Note: Propertyutils provides the type conversion feature, where the conversion is performed within the range of supported data types when a property of the same name of two JavaBean is found to be of different types, and beanutils does not support this feature, but it is faster.

4. URL encoding and decoding

Code: Java.net.URLEncoder.encode (String s)

Decoding: Java.net.URLDecoder.decode (String s);

5, the string is padded

Org.apache.commons.lang.StringUtils

String test = "123456"= Stringutils.leftpad (test, ten, "0"); System.out.println (value);

Output: 0000123456

008-treemap, map and bean cross-transfer, Beanutils.copyproperties (A, b) copy, URL encoding decoding, string completion

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.