- 在idea中 alt+ins 调出toString,选择
- 点击settings
3. 新增Templates
4. 粘贴此模板
public java.lang.String toString() {
final java.lang.StringBuilder sb = new java.lang.StringBuilder("{");
#set ($i = 0)
#foreach ($member in $members)#if ($i == 0)
sb.append("#####
#else
sb.append(",####
#end#if ($member.string || $member.date)
\"$member.name\":").append($member.name == null ? "":"\"")
#else
\"$member.name\":")
#end
#if ($member.primitiveArray || $member.objectArray)
.append(java.util.Arrays.toString($member.name));
#elseif ($member.string || $member.date)
.append($member.accessor).append($member.name == null ? "":"\"");
#else
.append($member.accessor);
#end
#set ($i = $i + 1)
#end
sb.append('}');
return sb.toString();
}
新增完成!!