IDEA重写toString方法模板示例
设置
ALT+Insert选择toString,在弹出对话框选setting,然后选择Templates,点击加号新建,然后输入
public java.lang.String toString() {
java.lang.StringBuilder bulider = new java.lang.StringBuilder("$class.getName() [");
#set ($i = 0)
#foreach ($member in $members)#if ($i == 0)
bulider.append("#####
#else
bulider.append(",####
#end#if ($member.string || $member.date)
$member.name=")
#else
$member.name=")
#end#if ($member.primitiveArray || $member.objectArray)
.append(java.util.Arrays.toString($member.name));
#elseif ($member.string || $member.date)
.append($member.accessor);
#else
.append($member.accessor);
#end#set ($i = $i + 1)
#end
bulider.append(']');
return bulider.toString();
}