simter-util [中文]
Some util tools. Includes:
- BeanUtils.assign : similar to JavaScript
Object.assign
method - XPathUtils : find xml node by standard xpath
- RandomUtils : generate random Int or String, get a nextId
Installation
<dependency>
<groupId>tech.simter</groupId>
<artifactId>simter-util</artifactId>
<version>1.0.0</version>
</dependency>
Requirement
- Java 8+
- ModelMapper 1+
Usage - BeanUtils.assign
Convert PO to DTO or reverse
UserPo po = new UserPo();
// set po property value
...
// convert to DTO instance
UserDto dto = BeanUtils.assign(UserDto.class, po);
If the DTO has the same property from multiple po, code should be like this:
UserDto dto = BeanUtils.assign(UserDto.class, po1, po2, ...);
The latter po property value will override the previous po property value.
Copy property value to target instance object
UserPo po = new UserPo();
// set po property value
...
// instance target instance
UserDto dto = new UserDto();
// copy po property value to the dto property
BeanUtils.assign(dto, po);
If the DTO has the same property from multiple po, code should be like this:
BeanUtils.assign(dto, po1, po2, ...);
The latter po property value will override the previous po property value.
Usage - XPathUtils
TODO.
Build
mvn clean package
Deploy
First take a look at simter-parent deploy config.
Deploy to LAN Nexus Repository
mvn clean deploy -P lan
Deploy to Sonatype Repository
mvn clean deploy -P sonatype
After deployed, login into https://oss.sonatype.org. Through Staging Repositories
, search this package, then close and release it. After couple hours, it will be synced to Maven Central Repository.
Deploy to Bintray Repository
mvn clean deploy -P bintray
Will deploy to https://api.bintray.com/maven/simter/maven/tech.simter:simter-util/;publish=1
. So first create a package https://bintray.com/simter/maven/tech.simter:simter-util
on Bintray. After deployed, check it from https://jcenter.bintray.com/tech/simter/simter-util.