3. 메뉴로그는 날짜를 입력하게 되면 그날 어떤 음식이 자동으로 선택되었는지 알 수 있다.
항상 yyyy-mm-dd로 입력해준다. ex) 확인 2018-11-07
2. Sqlite3 Table
create table menu( name text not null primary key); create table menu_log( id integer primary key autoincrement, name text not null, time timestamp DATE DEFAULT(datetime('now', 'localtime')));
public class TestDTO { private Integer id; private String password; public TestDTO() { super(); } public TestDTO(Integer id, String password) { super(); this.id = id; this.password = password; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }
다음 컨트롤러를 하나 생성해준다.
@RestController @RequestMapping(value = "/jsontest") public class TestClass { @GetMapping() public TestDTO test() { TestDTO test = new TestDTO(1, "1111"); return test; } @GetMapping("/2") public List test2() { List test = new ArrayList(); test.add(0, new TestDTO(1, "1111")); test.add(1, new TestDTO(2, "2222")); test.add(2, new TestDTO(3, "3333")); return test; } }
그리고 실행하게 되면
1. test() 실행화면
2. test2() 실행화면
이렇게 Json 형태로 출력된다
참고로 Map은 Json형태로 출력되지 않고 {"id" = 1, "password"="1111"} 형식으로 출력된다. List만 Json형식으로 출력된다.
또한, 이렇게 클래스로 만든 JsonObject는 Return할 때만 Json으로 출력되지, log또는 print할 경우엔 Json형식으로 출력되지 않는다.