일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- development
- restapi
- mssql
- ojdbc
- Tomcat #SpringFramework
- Web
- 스프링부트 #springboot #project #Intellij
- install
- 스프링부트
- Maven
- SpringSecurity
- RESTful
- undefined
- Developer
- Oracle11g
- SpringInitializer
- IntelliJ
- oracle
- 웹개발
- springboot #controller #jsp
- Database
- sqldeveloper
- mysql
- postman
- tcping
- HATEOAS
- 환경변수
- apache
- springboot
- 스프링시큐리티
Archives
- Today
- Total
여백에 도장 찍기
HATEOAS 본문
HATEOAS: Hypermedia As a The Engine Of Application State
사용방법
1. pom.xml 에 HATEOAS 관련 dependency 추가
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
2. 테스트 코드를 작성해보자.
import org.springframework.hateoas.ResourceSupport;
public class Customer extends ResourceSupport {
private String customerId;
private String customerName;
private String companyName;
public Customer() {
}
public Customer(String customerId, String customerName, String companyName) {
this.customerId = customerId;
this.customerName = customerName;
this.companyName = companyName;
}
public String getCustomerId() {
return customerId;
}
public void setCustomerId(String customerId) {
this.customerId = customerId;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
}
import analysis.data.system.model.Customer;
import org.springframework.hateoas.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
@RestController
public class ApiController {
@GetMapping(value = "/api/customer", produces = "application/json; charset=UTF-8")
public Resource<Customer> getCustomer() {
Customer customer = new Customer();
customer.setCustomerId("1234");
customer.setCustomerName("seo");
customer.setCompanyName("mycompany");
Resource<Customer> customerResource = new Resource<>(customer);
customerResource.add(linkTo(methodOn(ApiController.class).getCustomer()).withSelfRel());
return customerResource;
}
}
※ trouble shooting
: @GetMapping() 어노테이션에 produces 의 값으로 "application/json" 주지 않으면 마샬링 에러 발생.
3. Postman을 이용해 결과를 확인해보자.
'Web Framework > Spring Boot ' 카테고리의 다른 글
SLF4J (0) | 2019.07.09 |
---|---|
Spring boot - myBatis (0) | 2019.07.08 |
Spring boot - MSSQL 연동 설정 (0) | 2019.07.04 |
Spring Security - configure method override (0) | 2019.07.03 |
Spring Boot - 웹 디렉터리 생성 및 설정 (0) | 2019.07.03 |
Comments