2、为什么要使用ToStringBuilder?...使用ToStringBuilder就可以避免暴内存这种问题的。...二、示例学习 1、ToStringBuilder的append方法 ToStringBuilder类主要用于类的格式化输出。...ToStringBuilder中append方法可以向该类添加基本类型、数组、和对象,只有添加的方法才会被toString输出。...ToStringBuilder: 当你需要重载 toString 函数而不想写代码把当前类的所有成员信息列出来,可以用这个函数。
日常开发中,经常用org.apache.commons.lang3.builder.ToStringBuilder工具类来记录日志,比如: package com.cnblogs.yjmyzz; import...org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle...obj = new DemoObject(); //原始toString() System.out.println(obj); //ToStringBuilder...的输出(默认风格) System.out.println(ToStringBuilder.reflectionToString(obj)); //ToStringBuilder...的输出(短前缀风格) System.out.println(ToStringBuilder.reflectionToString(obj, ToStringStyle.SHORT_PREFIX_STYLE
javaBean的属性名不一样,导致接收不到: Child类用来接收传过来的json串: packagecom.test.dto;importorg.apache.commons.lang3.builder.ToStringBuilder...voidsetChileFather(String chileFather) {this.chileFather =chileFather; } @OverridepublicString toString() {return ToStringBuilder.reflectionToString...packagecom.test.dto;importcom.fasterxml.jackson.annotation.JsonProperty;importorg.apache.commons.lang3.builder.ToStringBuilder...voidsetChileFather(String chileFather) {this.chileFather =chileFather; } @OverridepublicString toString() {return ToStringBuilder.reflectionToString...packagecom.test.dto;importcom.alibaba.fastjson.annotation.JSONField;importorg.apache.commons.lang3.builder.ToStringBuilder
com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.lang3.builder.ToStringBuilder...this.address = address; } @Override public String toString() { return new ToStringBuilder...import com.fasterxml.jackson.core.JsonProcessingException; import org.apache.commons.lang3.builder.ToStringBuilder...this.address = address; } @Override public String toString() { return new ToStringBuilder...this.address = address; } @Override public String toString() { return new ToStringBuilder
final long serialVersionUID = 2332798099928474975L; public String toString() { return ToStringBuilder.reflectionToString...(this, CanalToStringStyle.DEFAULT_STYLE); } } Position定义了toString方法,使用ToStringBuilder.reflectionToString...cursors获取Position;updateCursor方法则更新cursors中key为clientIdentity的value为position 小结 Position定义了toString方法,使用ToStringBuilder.reflectionToString
search); for (int i = 0; i < studentsByNameAndSex.size(); i++) { System.out.println(ToStringBuilder.reflectionToString...studentMapper.selectByIdOrName(student); System.out.println("有 ID 则根据 ID 获取"); System.out.println(ToStringBuilder.reflectionToString...studentMapper.selectByIdOrName(student); System.out.println("没有 ID 则根据 name 获取"); System.out.println(ToStringBuilder.reflectionToString...search); for (int i = 0; i < studentsByNameAndSex.size(); i++) { System.out.println(ToStringBuilder.reflectionToString...studentMapper.selectByStudentIdList(ids); for (int i = 0; i < students.size(); i++) { System.out.println(ToStringBuilder.reflectionToString
final long serialVersionUID = 2332798099928474975L; public String toString() { return ToStringBuilder.reflectionToString...(this, CanalToStringStyle.DEFAULT_STYLE); } } Position定义了toString方法,使用ToStringBuilder.reflectionToString...cursors获取Position;updateCursor方法则更新cursors中key为clientIdentity的value为position 小结 Position定义了toString方法,使用ToStringBuilder.reflectionToString
五、toString()方法的进阶应用 除了基本的重写toString()方法,还可以利用一些工具类和库来简化toString()方法的实现,例如Apache Commons Lang库中的ToStringBuilder...使用Apache Commons Lang的ToStringBuilder: Apache Commons Lang提供了一个ToStringBuilder类,可以简化toString()方法的实现,并提供多种格式选项...: import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle...String name; private int age; @Override public String toString() { return new ToStringBuilder....append("name", name) .append("age", age) .toString(); } } 使用ToStringBuilder
public void setAge(int age) { this.age = age; } @Override public String toString() { return new ToStringBuilder...; import java.io.ObjectInput; import java.io.ObjectOutput; import org.apache.commons.lang3.builder.ToStringBuilder...public void setAge(int age) { this.age = age; } @Override public String toString() { return new ToStringBuilder...; import java.io.ObjectInput; import java.io.ObjectOutput; import org.apache.commons.lang3.builder.ToStringBuilder...public void setAge(int age) { this.age = age; } @Override public String toString() { return new ToStringBuilder
Object array) { if (array == null) { return "{}"; } return new ToStringBuilder...().append(array).toString(); } public static class ToStringBuilder { private final...StringBuffer(512); private final ToStringStyle style = new ToStringStyle(); public ToStringBuilder
此外,这些IDE们提供了许多方式来生成我们自己的toString:字符串连接(使用+号)、StringBuffer、StringBuilder、ToStringBuilder(Commons Lang...平均操作次数/秒 用’+'连接字符串 142.075,167 String builder 141.463,438 Objects.toString 140.791,365 Guava 110.111,808 ToStringBuilder...(append) 75.165,552 ToStringBuilder (reflectionToString) 34.930,630 ReflectionToStringBuilder 23.204,479
tmpFilePath); //文件名,机构编码,文件日期 不能重复 log.info("call 需求信息附件 Param {}:", ToStringBuilder.reflectionToString...CommandResDTO resDTO = DfsClient.upload(insertReqDTO); log.info("call 需求信息附件 result {}", ToStringBuilder.reflectionToString...reqDTO.setOperation(Operation.QUERY); log.info("downloadExcel QueryReqDTO:" + ToStringBuilder.reflectionToString
: package com.typhoon.demo1.consumer; import java.util.Map; import org.apache.commons.lang3.builder.ToStringBuilder...UserService service1 = SpringContextUtil.getBean(UserService.class); System.out.println("方式1结果:" + ToStringBuilder.reflectionToString...); UserService service2 = SpringContextUtil.getBean("userService"); System.out.println("方式2结果:" + ToStringBuilder.reflectionToString...service3 = SpringContextUtil.getBean("userService", UserService.class); System.out.println("方式3结果:" + ToStringBuilder.reflectionToString
领取专属 10元无门槛券
手把手带您无忧上云