xkbeancomparator 0.0.2 release

xkbeancomparator is a java bean and outputs the modified difference comparison tools.

Application scenarios: when the user edits submitted, record content, compared to values ​​before and after modification, an operation record; may be selected fields and field description records, custom action record.

0.0.2 Version:

  • Contrast basic types of support, such as when the boolean type, get special treatment method would have been to begin with is.

Software Description

0. dependence:

<dependency>  
  <groupId>com.github.xkzhangsan</groupId>    
  <artifactId>xkbeancomparator</artifactId>       
  <version>0.0.2</version>    
</dependency>    

1. Common use:

(1) modified to generate a change log object contrast;
(2) modify some fields contrast, according to the comment field output log.

2. The main features and usage categories:

Main Class Name Class: BeanComparator.java
main method Method:

public static String compareBean(Object source, Object target)
public static CompareResult getCompareResult(Object source, Object target)

Examples of the Samples-3 xkbeancomparator (  https://github.com/xkzhangsan/xkbeancomparator-samples  )

(1) adding dependency pom

<dependency>  
  <groupId>com.github.xkzhangsan</groupId>    
  <artifactId>xkbeancomparator</artifactId>       
  <version>0.0.2</version>    
</dependency>    

(2) java bean class User

import java.math.BigDecimal;

public class User {
	Integer id;
	String name;
	private BigDecimal point;
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public BigDecimal getPoint() {
		return point;
	}
	public void setPoint(BigDecimal point) {
		this.point = point;
	}
	

}

(3) adding additional logging class UserLog


import java.util.HashMap;
import java.util.Map;

import com.xkzhangsan.xkbeancomparator.BeanComparator;
import com.xkzhangsan.xkbeancomparator.CompareResult;

public class UserLog{
   private static final Map<String, String> propertyTranslationMap = new HashMap<>();

   static {
	  propertyTranslationMap.put("name", "用户名");
	  propertyTranslationMap.put("point", "积分");
   }

   public static CompareResult getCompareResult(Object source, Object target){
	  return BeanComparator.getCompareResult(source, target, propertyTranslationMap);
   }
}

(4) Use

@Test
public void test1() {
	User u1 = new User();
	u1.setId(1);
	u1.setName("aa");
	u1.setPoint(new BigDecimal("111111111111.12"));

	User u2 = new User();
	u2.setId(1);
	u2.setName("aa2");
	u2.setPoint(new BigDecimal("111111111111.15"));
	CompareResult compareResult = UserLog.getCompareResult(u1, u2);
	if (compareResult.isChanged()) {
		System.out.println(compareResult.getChangeContent());
	}
}

(5) the output

Username: aa-> aa2, Points: 111111111111.12-> 111111111111.15,

(6) Description

The above is the recommended usage, the use of secondary log class can maintain a unified java bean comment map, simplified call.

Welcome suggestions!

Guess you like

Origin www.oschina.net/news/111025/xkbeancomparator-0-0-2-released