국비수업/수업정리
RestController
밀김
2023. 6. 15. 15:17
728x90
- SPA: Single-page application
- sap는 프론트엔드 프로그램중 하나
- 목록을 요청할때는 쿼리스트링을 사용한다
- 상태에 대한 내용을 그대로 출력하는
@RestController
@RestController("apiMenuController")
@RequestMapping("api/menus")
public class MenuController {
@GetMapping
public String list() {
return "list";
}
@GetMapping("5")
public String detail() {
return "메뉴 1개";
}
@PutMapping("5")
public String edit(Menu menu) {
return "okay~~수정완료";
}
@DeleteMapping("5")
public String delete(int id) {
return "삭제 완료~~";
}
@PostMapping
public String add(Menu menu) {
return "새로 추가된 메뉴 감삼감삼다";
}
- 이렇게 하고 http://localhost:8080/api/menus/5 이거 검색하면 list라는 문자가 나온다
Postman API Platform | Sign Up for Free
Postman is an API platform for building and using APIs. Postman simplifies each step of the API lifecycle and streamlines collaboration so you can create better APIs—faster.
www.postman.com
https://velog.io/@dyunge_100/Spring-Controller%EC%99%80-RestController%EC%9D%98-%EC%B0%A8%EC%9D%B4
[Spring] @Controller와 @RestController의 차이
0. @RequestBody, @ResponseBody 어노테이션 보통 웹에서 화면 전환이 없이 이루어지는 동작들은 대부분 비동기 통신으로 이루어진다. 비동기 통신을 하기 위해선 클라이언트가 서버로 요청 메시지의 본
velog.io
<script>
window.addEventListener("load",function(e){
let tabSection = document.querySelector(".tab-section");
tabsection.onclick = function(e)
e.preventDefault();
if(e.target.tagName !== 'A')
return ;
fetch("http://localhost:8080/api/menus?c=3")
.then(response=>response.json())
.then(json=>json[0])
.then(menu=>menu.korName)
.then(name=>{
console.log(name);
});
//이 도구의 데이터 수신처리 방법: then()을 이용한 별도의 콜백을 사용
})
</script>
728x90