REST API
·
웹공부/SPRING
1. 기존기존 브라우저 GET : 요청정보를 URL에 담아서 HTML문서를 주세요.POST : 요청정보를 패킷에 담아서 HTML문서를 주세요.VS REST : 자원을 이름으로 구분하여 해당 자원의 상태를 주고 받으며 mustache가 필요없다.GET : 자원의 정보를 조회해주세요.POST : 자원을 생성해주세요.PUT, PATCH : 자원을 줄테니 업데이트해주세요. (PUT: 본문 전체, PATCH:일정 요소만) DELETE : 자원을 삭제해주세요 - 장점 API서버는 세션, 쿠키를 사용하지않고 API요청만 단순히 처리한다. 별도의 인프라 구축이 필요 없다.HTTP 표준만 지키면 모든 플랫폼에서 사용이 가능하다. - 단점표준 자체가 존재하지 않아 정의가 필요하다.HTTP Method 형태가 제한적이다.(..
예외 처리
·
웹공부/SPRING
- error/error.mustache{{>layouts/header}} 에러가 발생했습니다! 요청 경로 : {{path}} 에러 코드 : {{status}} 에러 메시지 : {{message}} {{>layouts/footer}} - NewsController.Java로 예외처리 넘기기 News news = newsRepository.findById(newsId) .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "해당 게시글이 존재하지 않습니다.")); - advice/GlobalExceptionHandler.Java@Con..
Delete, Update
·
웹공부/SPRING
1. Delete - detail.mustacheDelete - NewsController.class @GetMapping("/{newsId}/delete") public String deleteNews(@PathVariable("newsId") Long newsId){ newsRepository.deleteById(newsId); return "redirect:/news/list"; }  2. Edit 2-1. id로 데이터를 form에 가져오기- detail.mustacheEdit - NewsController.class @GetMapping("/{newsId}/edit") public String editNewsForm(@PathVariable(..
페이지네이션
·
웹공부/SPRING
- 참조 링크https://docs.spring.io/spring-data/jpa/reference/jpa/query-methods.html JPA Query Methods :: Spring Data JPABy default, Spring Data JPA uses position-based parameter binding, as described in all the preceding examples. This makes query methods a little error-prone when refactoring regarding the parameter position. To solve this issue, you can use @Param annotatidocs.spring.io - repository..
BootStrap 실습 (Create, Read)
·
웹공부/SPRING
Get started with Bootstrap · Bootstrap v5.3 Get started with BootstrapBootstrap is a powerful, feature-packed frontend toolkit. Build anything—from prototype to production—in minutes.getbootstrap.com 1. Header, Footer 만들기 1-1. 파일 설정resources/application.ymlserver: servlet: encoding: force-response: true  1-2. mustache 설정- header.mustache News Site ..
SPRING 기본
·
웹공부/SPRING
1. SPRING 3요소Spring은 자바 엔터프라이즈 기술을 사용함Spring Framework : 클래스의 인스턴스를 생성하여 의존성 주입Spring Container : 스프링에서 자바 객체들을 관리하는 공간Bean : Spring에 생성되고 관리되는 자바 객체기본적으로 객체 인스턴스를 싱글톤(클래스의 인스턴스 딱 1개만 생성됨)으로 관리 Controller : 사용자의 요청을 받아 결과를 뷰나 response로 전달Service : 요구 사항을 처리하는 비지니스, 서비스 로직을 작성Repository : DB를 통신@Auowired : 의존성 주입이 쉽고 참조 관계를 눈으로 확인하기 어렵다. src/main/javajava만 넣는 곳@SpringBootApplication이 있는 곳으로 실행pac..
Intellj Community Edition에서 SPRING 작동하는 법
·
웹공부/SPRING
1. 아래 사이트 들어가기https://start.spring.io/ 2. Spring Initializr원하는 설정을 지정 후 GENERATE버튼 누르기 - 저장된 ZIP파일 풀기- intellj에서 project 열기 3. 셋팅하기 - 라이브러리 다운로드밑에 사이트에서 라이브러리 검색 후 다운로드https://mvnrepository.com/dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' compileOnly 'org.projectlombok:lombok' runtimeOnly 'com.h2database:h2' developmentOnly 'org.springframework.boot:spring-boo..
스파르타 코딩 클럽 - Spring 4주차
·
웹공부/SPRING
마지막 4주차 시작! [개발자 입문]웹개발의 봄, Spring - 4주차 | NotionPDF 파일teamsparta.notion.site Ctrl + B : 코드에서 들어가기Shift + Shift : 자바클래스 검색 4-1 JPA란 무엇일까?ORM 이란 ?객체와 데이터베이스를 매핑해주는 도구JPA : 자바 ORM기술의 표준 명세 ≒ Hibernate (사실상 표준) 4-2 Entity 이해하기 1. jpa-core 이름의 새 프로젝트 생성Spring Intalizr환경이 아닌 그냥 자바환경 프로젝트 설정 2. META-INF (디레토리) > persistence.xml (파일) 생성 class의 경로 com.sparta.entity.Memo ..
스파르타 코딩 클럽 - Spring 3주차
·
웹공부/SPRING
3주차 시작! [개발자 입문]웹개발의 봄, Spring - 3주차 | NotionPDF 파일teamsparta.notion.site Ctrl + Alt + O : import 옵티마이저Ctrl + Alt + L : 코드 정렬Ctrl + / : 다 줄의 코드 주석처리Ctrl + E : 탭 변경Alt + Ins : 추가 3-1 3Layer Architecture서버에서의 처리 과정이 대부분 비슷하다는 걸 깨닫고,처리 과정을 크게 Controller, Service, Repository 3개로 분리Controller의 역할을 나누는 것  3-2 역할 분리하기패키지와 자바클래스 만들기 Ctrl + Alt + O : import 옵티마이저 1. Service로 요청과 데이터 보내기src > main > java ..