반응형
무작정 따라해보자, 필드를 만드는 방법도 무진장 쉽다. clazz에 field 메소드를 통해서 생성이 가능하다.
File rootDir = new File(outputConfig.getRootDirectory());
JCodeModel codeModel = new JCodeModel();
try {
JDefinedClass clazz = codeModel._class(outputConfig.getClassName());
clazz.field(JMod.PRIVATE, String.class, "name");
clazz.field(JMod.PRIVATE, int.class, "age");
clazz.field(JMod.PRIVATE, ArrayList.class, "test");
codeModel.build(rootDir);
} catch (JClassAlreadyExistsException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
결과 클래스는 다음과 같다.
package net.daum.domaingen.json;
import java.util.ArrayList;
public class SimpleClass {
private String name;
private int age;
private ArrayList test;
}
반응형
'Programming > JCodeModel' 카테고리의 다른 글
JCodeModel로 클래스 생성하기 (0) | 2015.01.07 |
---|