Ioc, DI
BackEnd/패캠 2022. 1. 18. 00:00

@Component //야야야 이거 스프링 니가 관리해!!!!(스프링이 의존성 주입 : 의존의 역치, Inversion of Control : IoC) => 클래스를 bean으로 등록한 것 //스프링이 실행되면 스프링이 @component가 붙은 클래스를 찾아서 객체를 싱글톤으로 만들어 스프링 컨테이너에서 모든 생명주기를 관리 //@Component("bean이름")으로 이름도 만들어 줄 수 있음, 지정안하면 클래스이름의 첫글자를 소문자로 바꾼 것이 된다. public class Base64Encoder implements IEncoder { @Override public String encode(String message) { return Base64.encode(message.getBytes()); ..

모범사례 - Object Mapper
BackEnd/패캠 2022. 1. 17. 00:00

여태 우리가 한건 컨트롤러에서 request(json=text) -> Object Object -> response(json=text) 기능을 이용했다. but 컨트롤러에서 알아서 매핑해주는게 아니라 그 외의 영역에서도 json과 object를 서로 매핑해주는 기능을 만들어보자 ObjectMapper objectMapper=new ObjectMapper(); //1. object -> text //객체에서 텍스트를 추출할 땐 get method를 이용하므로 클래스 내에 get메서드 생성 필요! User user=new User("이민혁",16,"010-0000-0000"); String text=objectMapper.writeValueAsString(user); //throw 필요 System.out...

Response 내려주기 및 모범사례
BackEnd/패캠 2022. 1. 16. 00:00

응답의 종류! 1. text => RequestParam 2. 요청의 객체 - json형태 => RequestBody로 객체 3. 요청에 대한 응답객체 - 응답 (+ 2도 보낼 수 있음(body지정으로)) => ResponseEntity 4. html파일(페이지) 4-1. 객체 -정말 잘 안쓰는 창법,, ResponseApiController.java (방법1,2,3) @GetMapping("/text") public String text(@RequestParam String account){ return account; } @PostMapping("/json") public User json(@RequestBody User user){ //요청 --(object mapper)-> 객체 return us..

POST/PUT/DELETE API
BackEnd/패캠 2022. 1. 15. 00:00

-post- dto/PostRequestDto @JsonProperty("phone_number") //body를 줄 때 key 이름을 이 이름으로 해야 등록됨. (phoneNumber 포함 다른걸로 하면 null) private String phoneNumber; -put- @PutMapping("/put") public PostRequestDto put(@RequestBody PostRequestDto requestDto){ System.out.println(requestDto); return requestDto; } @PutMapping("/put2/{id}") public PostRequestDto put2(@RequestBody PostRequestDto requestDto, @PathVaria..

GET API
BackEnd/패캠 2022. 1. 14. 00:00

@RestController //해당 클래스는 REST API를 처리하는 Controller @RequestMapping("/api") //RequestMapping URI를 지정해주는 Annotation // => 전체 주소가 ~/api/~로 시작을 한다는 의미 public class ApiController { @GetMapping("/hello") //http://localhost:8080/api/hello public String hello(){ return "hello spring boot!"; } //1. 일반 GET MAPPING~ @GetMapping("/hello") //http://localhost:8080/api/get/hello public String hello(){ return ..