티스토리 뷰
728x90
반응형
GET
package com.example.demo.controller;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@RestController
@RequestMapping("/get")
public class GetController {
@GetMapping("/pathVariable/{name}")
public String pathVariable(@PathVariable String name) {
return "pathVariable " + name;
}
@GetMapping("pathVariable2/{name}/{email}")
public String pathVariable2(
@PathVariable(value="name") String name,
@PathVariable(value="email") String email
) {
return String.format("name=%s, email=%s", name, email);
}
@GetMapping("/requestParam")
public String requestParam(
@RequestParam String name,
@RequestParam String email
) {
return String.format("name=%s, email=%s", name, email);
}
@GetMapping("requestParam2")
public String requestParam2(@RequestParam Map<String, String> maps) {
StringBuilder sb = new StringBuilder();
maps.forEach((key, value) -> {
sb.append(String.format("%s : %s", key, value));
});
return sb.toString();
}
}
POST
package com.example.demo.controller;
import com.example.demo.dto.MemberDto;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@RestController
@RequestMapping("/post")
public class PostController {
@PostMapping("requestBody")
public String requestBody(@RequestBody MemberDto memberDto) {
return memberDto.toString();
}
@PostMapping("/requestBody2")
public String requestBody2(@RequestBody Map<String, String> maps) {
StringBuilder sb = new StringBuilder();
maps.forEach((key, value) -> {
sb.append(String.format("%s : %s, ", key, value) );
});
return sb.toString();
}
}
PUT
package com.example.demo.controller;
import com.example.demo.dto.MemberDto;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/put")
public class PutController {
@PutMapping("/requestBody")
public String requestBody(@RequestBody MemberDto memberDto) {
return memberDto.toString();
}
@PutMapping("/responseEntity")
public ResponseEntity<MemberDto> responseEntity(@RequestBody MemberDto memberDto) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body(memberDto);
}
}
DELETE
package com.example.demo.controller;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/delete")
public class DeleteController {
@DeleteMapping("/pathVariable/{name}")
public String pathVariable(@PathVariable String name) {
return "delete pathVariable " + name;
}
@DeleteMapping("/pathVariable2/{pathVariable2}/{pathVariable1}")
public String pathVariable2(
@PathVariable(value="pathVariable1") String pathVariable1,
@PathVariable(value="pathVariable2") String pathVariable2
) {
return "hi2 " + pathVariable1 + pathVariable2;
}
@DeleteMapping("/requestParam")
public String requestParam(
@RequestParam String name,
@RequestParam String email
) {
return String.format("%s, %s", name, email);
}
}
728x90
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- REST API
- system.io
- 진수 변환
- 메이븐(maven)
- 표현 언어(expression language)
- 스프링 프레임워크(spring framework)
- 상품 등록
- 문자 자르기
- error-java
- jstl(java standard tag library)-core
- System.Diagnostics
- 특정 문자를 기준으로 자르기
- java web-mvc
- .submit()
- MainActor
- jsp 오픈 소스
- jstl(java standard tag library)
- 인텔리제이(intellij)
- java 키워드 정리
- await
- java.sql
- 람다식(lambda expression)
- java-개발 환경 설정하기
- 제품 등록
- 스프링 시큐리티(spring security)-http basic 인증
- In App Purchase
- 스프링 프레임워크(spring framewordk)
- 스프링 시큐리티(spring security)
- nl2br
- React
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
글 보관함