![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FcO9PBJ%2FbtrTefXCA3l%2F7MKhykLRt26L1tPBR9uCk0%2Fimg.png)
Spring Boot 수정 폼 만들기
2022. 12. 9. 13:56
Study/SpringBoot WebProject
링크 걸기 - a 태그 {{>layouts/header}} ID Title Content {{#article}} {{id}} {{title}} {{content}} {{/article}} Edit Go to Article List {{>layouts/footer}} 수정 페이지 작성 {{>layouts/header}} {{#article}} 제목 내용 {{content}} Submit back {{/article}} {{>layouts/footer}} 요청 받기 - 컨트롤러, GetMapping. @GetMapping("/articles/{id}/edit") public String edit(@PathVariable Long id, Model model){ //수정할 데이터를 가져오기! Article a..
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FCo3NR%2FbtrTe6FARKh%2FT6NotuivaBYgxKk4eJtGnK%2Fimg.png)
Spring Boot 링크와 리다이렉트
2022. 12. 9. 13:32
Study/SpringBoot WebProject
목록에서 새 글작성 페이지로 {{>layouts/header}} ID Title Content {{#articleList}} {{id}} {{title}} {{content}} {{/articleList}} new article {{>layouts/footer}} 목록페이지로 돌아가기 {{>layouts/header}} 제목 내용 Submit back {{>layouts/footer}} 리다이렉트 - 새 글저장 후, 상세 페이지로 @PostMapping("/articles/create") public String createArticle(ArticleForm form){ log.info(form.toString()); //System.out.println(form.toString()); //1. DTO를..
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FcsQZtM%2FbtrTaNHJ3WW%2FmwFsayfJa2PFZJBmIkKA31%2Fimg.png)
Spring Boot 데이터 목록 조회하기
2022. 12. 9. 11:17
Study/SpringBoot WebProject
브라우저 요청 받기 모델과 데이터 등록 - addAttribute() @GetMapping("/articles") public String index(Model model){ // 1. 모든 Article을 가져온다 List articleEntityList = articleRepository.findAll(); // 2. 가져온 Article 묶음을 뷰로 전달! model.addAttribute("articleList", articleEntityList); // 3. 뷰페이지를 설정! return "articles/index"; //articles/index.mustache } 라파지터리 오버라이딩 - findAll() public interface ArticleRepository extends Crud..
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fbgv2E1%2FbtrTe6r1AJN%2F92haSiaiQot5jadkSkvjZ0%2Fimg.png)
Spring boot 데이터 조회하기 with JPA
2022. 12. 9. 10:47
Study/SpringBoot WebProject
DB데이터 조회하기 URL 요청받기 - PathVariable 컨트롤러 - 처리 흐름 리파지터리 - id 조회, findById() @GetMapping("/articles/{id}") // 해당 URL요청을 처리 선언 public String show(@PathVariable Long id, Model model){ // URL에서 id를 변수로 가져옴 log.info("id=" + id); // 1: id로 데이터를 가져옴! Article articleEntity = articleRepository.findById(id).orElse(null); // 2: 가져온 데이터를 모델에 등록! model.addAttribute("article",articleEntity); // 3: 보여줄 페이지를 설정! ..
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FG1Rom%2FbtrQjm5ARGs%2FqPHiqOnvRi9OHIhiPqIpb0%2Fimg.png)
Spring Boot lombok과 refactoring
2022. 11. 3. 09:54
Study/SpringBoot WebProject
롬복을 활용하여 기존 코드를 리팩토링 해보자 롬복이란? 코드를 간소화 시켜주는 라이브러리 (게터,세터,생성자등) 반복최소화 할수 있고 로깅(Slf4j)기능을 통해 pringln기능 개선, 리팩토링할수 있다 리팩토링이란? 코드의 구조 성능 개선 작업 로깅이란? 프로그램 수행과정을 기록으로 남긴다 SLF4J 동작과정 SLF4J은 간략히 아래와 같은 과정을 거쳐요. 개발할 때, SLF4J API를 사용하여 로깅 코드를 작성 배포할 때, 바인딩된 Logging Framework가 실제 로깅 코드를 수행 -롬복 설치 firstproject/build.gradle //롬복 추가 compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok..
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fd2UMIz%2FbtrQfLFghEV%2FJaXhK2APgHBOV7MX5EVHS0%2Fimg.png)
Spring Boot DB테이블과 SQL
2022. 11. 3. 08:58
Study/SpringBoot WebProject
application.properties파일에 아래와 같은 문구 작성 # h2 DB, 웹 콘솔 접근 허용 spring.h2.console.enabled=true h2데이터 베이스 접속 http://localhost:8080/h2-consol 접속 화면의 URL에 파란 부분의 경로를 복사해서 옮겨적고 실행 -SELECT, 데이터 조회하기 테이블을 클릭하면 전체 Select 화면이 나오고 조회를 하면 아무것도 나오지 않는다 메모리 모드로 돌리고 있어 서버를 재시작할 경우 DB가 다 날라간다 다시 데이터를 넣고 확인하면 잘 저장이 된다 -INSERT, 데이터 생성하기 쿼리문작성 insert into article( id,title,content) values(4,'ccc','ccc'); 하게되면 잘 나온다
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FSG1v5%2FbtrP45Famh7%2FUWv4ilBRFGpSUwCdrgKOqK%2Fimg.png)
Spring Boot 데이터 생성 with JPA
2022. 11. 1. 17:36
Study/SpringBoot WebProject
데이터베이스는 데이터를 관리하는 창고 JPA : 자바언어를 DB가 이해할수있는 기능 DTO를 Etity로 변환하고 Repository를 통해 DB까지 저장해보자 ./controller/ArticleController ArticleController생성 package com.example.firstproject.controller; import com.example.firstproject.dto.ArticleForm; import com.example.firstproject.entity.Article; import com.example.firstproject.repository.ArticleRepository; import org.springframework.beans.factory.annotation.A..
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FdlLDRj%2FbtrP6cXTd3D%2FXiezPeROd5k0IbRHG2ZQjK%2Fimg.png)
Spring Boot 폼 데이터 주고받기
2022. 11. 1. 16:51
Study/SpringBoot WebProject
게시글 만들기 기초 폼데이터 주고 받기 -게시글 쓰기 1. 글작성 페이지 만들기 new.mustache {{>layouts/header}} 제목 내용 Submit {{>layouts/footer}} 2. 글작성 컨트롤러 만들기 ArticleController 생성 package com.example.firstproject.controller; import com.example.firstproject.dto.ArticleForm; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation...
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FcW6O8w%2FbtrP902LhrK%2FNfAfGc3wKCZOj8mocRii7K%2Fimg.png)
Spring Boot 뷰 템플릿/ 레이아웃
2022. 11. 1. 16:26
Study/SpringBoot WebProject
레이아웃 나누기 header는 네비게이션 역할 footer는 인포메이션 역할을 한다. 지금까지 과정의 페이지에 레이아웃을 만들어보자 -헤더 레이아웃 Navbar Home Link Dropdown Action Another action Something else here Disabled Search -풋터 레이아웃 ⓒ CloudStudying | Privacy | Terms 만든다음에 greetings.mustache 와 goodbye.mustache 에 적용시켜보자 greetings.mustache {{>layouts/header}} {{username}}님, 반갑습니다. {{>layouts/footer}} goodbye.mustache {{>layouts/header}} {{nickname}}님 안녕히..
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FleQ3v%2FbtrP4wvYJF7%2F7jiZ5viPMbG2FiWCeWQ2k1%2Fimg.png)
Spring Boot MVC역할과 흐름
2022. 11. 1. 15:38
Study/SpringBoot WebProject
client의 요청은 컨드롤러가 받는다 @GetMapping("/hi")라는 어노테이션을 통해서 받는다 리턴값이 보여줄 페이지(greetings)가 되고 그 페이지에서 사용한 변수는 모델에서 등록이 된다! - localhost:8080/bye를 입력 받았을때 출력하자 goodbye.mustache를 만들고 **doc누른 뒤 탭을 누르면 {{nickname}}님 안녕히 가세요 작성하고 Controller에서 bye에 대한 코드 작성 @GetMapping("/bye") public String seeYouNext(Model model){ model.addAttribute("nickname","동명"); return "goodbye"; } nick네임에 모델에 담고 동명이란 값을 넘겨주면 값이 잘 나오는 것을..