java几个工具类

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012848709/article/details/82788760

楔子

记录一些学习中遇到的好用的工具。

org.apache.commons.lang3

equals hashCode toString

	@Override
	public boolean equals(Object obj) {
		return EqualsBuilder.reflectionEquals(this, obj, "name", "comment");
	}

	@Override
	public int hashCode() {
		return HashCodeBuilder.reflectionHashCode(this, "name", "comment");
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
		//cn.zhuzi.test.bean.DbType@4926097b[name=role,comment=role_code]
	}

fastjson

	@Test
	public void testEqual() throws Exception {
		DbType dbType = new DbType("role", "role_code");
		DbType dbType2 = new DbType("role", "role_code");
		System.out.println(dbType.equals(dbType2));
		System.out.println(dbType);
		// 指定需要json输出的字段
		SimplePropertyPreFilter filter = new SimplePropertyPreFilter(DbType.class, "comment");
		// 排除不要的转json的字段
		filter.getExcludes().add("comment");
		System.out.println(JSON.toJSONString(dbType, filter));
	}
//上述在javabean使用注解
@JSONType(includes = { "name", "auto" })
public class KindleBook implements Serializable {

猜你喜欢

转载自blog.csdn.net/u012848709/article/details/82788760