반응형

 

Spring Boot에서 데이터를 JSON형식으로 표현하는 가장 기본적인 방법으로는 클래스를 이용하는 방법이다.

이 방법을 알아야 다음에 Deserialization한 JSON을 만들 수 있다.

 

Spring boot Json 2편, 3편, 4편, 마지막

1. 2018/11/07 - [Develop/Spring Boot] - Spring Boot Json, Gson을 이용한 JsonObject to String, String to JsonObject- JSON 2편

2. 2018/11/09 - [Develop/Spring Boot] - Spring Boot Json, Jackson을 이용한 JsonParsing - Json 3편

3. 2018/11/12 - [Develop/Spring Boot] - Spring Boot Deserialization Json, Deserialization JsonString to JsonObject - Json 4편

4. 2018/11/13 - [Develop/Spring Boot] - Spring Boot Json, hashmap to json , JsonObject 만들기- JSON 마지막

 

번외 Database의 값을 Json으로 select하는 방법.

1. 2018/10/24 - [Spring Boot] - Spring boot jpa map, hashmap, JSON형식

2. 2018/10/28 - [Spring Boot] - Spring boot JPA EntityManager를 이용한 Map형식으로 mapping하기

 

Spring boot에서 MySQL JSON 타입 SELECT하는 방법

1. 2018/11/30 - [Develop/Spring Boot] - Spring boot MySQL JSON - MySQL JSON DATA TYPE 값 가져오기

 

 

 

먼저 DTO를 생성한다.

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형식으로 출력되지 않는다.

Json형식으로 출력되게 하려면 다음에 할 2편을 참고.

 

기초는 마무리.

 

반응형
반응형


파이썬에서 beautiful soup과 같은 기능을하는 Jsoup라는 것이 있다.

Html을 파싱하는 것이고




	org.jsoup
	jsoup
	1.11.3

xml에 dependency를 추가하고



Jsoup.parse("내용").body().text();

이렇게 사용하면 각종 html코드들을 삭제한 순수 text들이 파싱된다.


기타 사용법은 라이브러리 사이트에서 확인할 수 있다

https://jsoup.org/


반응형
반응형

Python 3.7 버전을 사용하고 있는 도중 Sqlite3 를 사용하게 되었는 데, Parameterized Query(매개변수 쿼리)를 사용하는 도중


sql = "SELECT name FROM test WHERE id=?"
self.cur.execute(sql, (100))

ValueError: parameters are of unsupported type


이런 오류가 발생하였다.

레퍼런스를 찾아보니 https://docs.python.org/2/library/sqlite3.html

아래와 같이 사용해야 된다.

sql = "SELECT name FROM test WHERE id=?"
self.cur.execute(sql, (100,))


반응형

+ Recent posts