๐ฟ Spring33 [Spring Boot/RESTful] Response ๋ฐ์ดํฐ ํ์ ๋ฐํ(XML format) XML ํ์ผ ํธ์ถ Postman header์์ key: Accept, value: application/xml๋ก ๋ณํ ์ xmlํ์ผ ํธ์ถ ๊ฐ๋ฅ XML ํ์ผ ๋ฐํ ํ์ฉ pom.xml ํ์ผ์ ๊ด๋ จ dependency ์ถ๊ฐ com.fasterxml.jackson.dataformat jackson-dataformat-xml 2.10.2 ⇒ ์ค์ ํ์ง ์์ ๊ฒฝ์ฐ 406 ์๋ฌ๊ฐ ๋๋ค 406 Not Acceptable ์๋ฒ๊ฐ ์์ฒญ์ ์ฌ์ ์ฝํ ์ธ ํ์ ํค๋์ ์ ์ฉ๋ ํ์ฉ ๊ฐ๋ฅํ ๊ฐ ๋ชฉ๋ก๊ณผ ์ผ์นํ๋ ์๋ต์ ์์ฑํ ์ ์์ผ๋ฉฐ ์๋ฒ๊ฐ ๊ธฐ๋ณธ ํํ์ ์ ๊ณตํ ์์ฌ๊ฐ ์์ด์ ๋ฐ์ [์ฌ์ ์ฝํ ์ธ ํ์ ํค๋์ ์ข ๋ฅ] [Accept]() [Accept-Encoding]() [Accept-Language]() ์๋ฒ๋ ๋ณดํต ๊ด๋ จ ํค๋๋ฅผ ๋ฌด.. 2022. 2. 18. [Spring Boot/RESTful] Validation API์ Internationalization Validation API ์ฌ์ฉ์๊ฐ ์ ๋ ฅํ ๋ฐ์ดํฐ์ ๋ํ ์ ํจ์ฑ ์ฒดํฌ -> @Valid annotation ์ฌ์ฉ 1. dependency ์ถ๊ฐ org.hibernate.validator hibernate-validator 6.0.7.Final 2. dto์ ์ ์ฝ์กฐ๊ฑด ์ถ๊ฐ @Data @AllArgsConstructor public class User { private Integer id; @Size(min=2, message = "Name์ 2๊ธ์ ์ด์ ์ ๋ ฅํด์ฃผ์ธ์.") private String name; private String password; @Past // ๊ณผ๊ฑฐ ๋ ์ง๋ง ๊ฐ๋ฅํ ์ ์ฝ ์กฐ๊ฑด private Date joinDate; } 3. controller์ ์ถ๊ฐ JDK์ ํฌํจ๋ API์ hibe.. 2022. 2. 18. [Spring Boot/RESTful] User Service API ๊ตฌํ 1) domain ํด๋์ค ์์ฑ ๋๋ฉ์ธ ํน์ ์ ๋ฌธ ๋ถ์ผ์์ ์ฌ์ฉ๋๋ ์ ๋ฌธ ์ง์ ์คํ ๋ ์คํ์ ํด๋น ํด๋์ค๊ฐ ์ด๋ ์ฉ๋๋ก ์ฌ์ฉ๋ ๊ฒ์ธ์ง ๋ํ๋ด๋ ๊ฒ → ์์กด์ฑ ์ฃผ์ ํ ๋ ๋์์ด ๋๋ค. ex) @RestController, @Service User domain ์ฌ๊ธฐ์์๋ @Data annotation์ ์ฌ์ฉํ์ง๋ง @Data ์ฌ์ฉ์ ๋๋๋ก ์์ ํ๊ณ @Getter @Setter ๋ฑ์ ๋ฐ๋ก ์ง์ ํด์ฃผ๋ ๊ฒ์ด ์ข๋ค. (@Data ๊ฐ์ ๊ฒฝ์ฐ๋ ํ๊บผ๋ฒ์ ๋ง์ ๊ธฐ๋ฅ์ ๋ถ๋ฌ์ค๊ธฐ๋ ํ๊ณ , @ToString์ ์๋ชป ์ฐ๋ฉด JPA์์ ๋ฌธ์ ๊ฐ ์๊ธธ ์ ์๊ธฐ ๋๋ฌธ) @Data @AllArgsConstructor public class User { private Integer id; private String name; private Da.. 2022. 2. 17. [Spring Boot/RESTful] Spring Boot๋ก ๊ฐ๋ฐํ๋ RESTful Service ํ๋ก์ ํธ ์์ฑ ์ง๊ธ๊น์ง๋ ํญ์ start.spring.io๋ฅผ ์ด์ฉํด์๋๋ฐ, IntelliJ ์์์ ๋ฐ๋ก ํ๋ก์ ํธ๋ฅผ ์์ฑํ ์๋ ์๋ค! ์๋์ฒ๋ผ dependency๋ฅผ ์ถ๊ฐํ๋ฉด pom.xml์ ์๋์ผ๋ก ์ถ๊ฐ๋๋ค. Spring web → embedded tomcat ์คํ ๊ฐ๋ฅ REST API ์ค๊ณ HTTPS API Name GET /users retrieve all users POST /users create a user GET /users/{id} retrieve one user DELETE /users/{id} delete a user GET /users/{id}/posts retrieve all posts for a user POST /users/{id}/posts create a post for a u.. 2022. 2. 17. ์ด์ 1 2 3 4 5 6 7 8 9 ๋ค์