반응형
자바 enum 클래스와 apache common-lang3 의 ToStringBuilder 를 사용하여 toString 메서드 구현 (멀티라인 처리용)
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
* @author gavin
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
public class Shoes {
private String name;
private int size;
private Type type;
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
}
}
/**
* @author gavin
*/
public enum Type {
WALKING,
RUNNING,
TRACKING,HIKING
}
@Test
public void enuTest(){
Shoes shoes = new Shoes();
shoes.setName("Nike");
shoes.setSize(2400);
shoes.setType(Type.HIKING);
Assert.assertNull(shoes.toString());
}
com.example.demo.demo.Shoes@332f25c8[
name=Nike
size=2400
type=HIKING
]
반응형
'SpringBoot' 카테고리의 다른 글
Springboot jar execute script (1) | 2018.05.15 |
---|---|
Intellij kotlin var inspection disable (0) | 2018.04.19 |
spring cloud config (0) | 2018.02.18 |
spring boot admin server (0) | 2018.02.11 |
JPA 와 JDBCTemplate 저장 속도 비교 (0) | 2017.09.28 |