WEB JAVA SPRING/PROJECT

[Day-2] 라이브러리, H2 DB

sshhhh 2023. 8. 25.

#라이브러리 살펴보기

의존관계를 볼 수 있다.

 

spring-boot-starter-thymeleaf

타임리프 템플릿 엔진(View)

 

spring-boot-starter-web

tomcat: 톰캣 (웹서버)

spring-webmvc: 스프링 웹 MVC

 

spring-boot-starter-data-jpa

spring-boot-starter-aop

spring-boot-starter-jdbc :HikariCP 커넥션 풀 (부트 2.0 기본) , DB 커넥션 가져다 쓴다

hibernate + JPA : 하이버네이트 + JPA

spring-data-jpa: 스프링 데이터 JPA

gradle 클릭

 

 

spring-boot-starter(공통): 스프링 부트 + 스프링 코어 + 로깅

 

 

spring-boot-starter-test

junit: 테스트 프레임워크

mockito: 목 라이브러리

assertj: 테스트 코드를 좀 더 편하게 작성하게 도와주는 라이브러리

spring-test: 스프링 통합 테스트 지원

junit 중요

spring-boot-starter-test

junit: 테스트 프레임워크

mockito: 목 라이브러리

assertj: 테스트 코드를 좀 더 편하게 작성하게 도와주는 라이브러리

spring-test: 스프링 통합 테스트 지원

 

 

핵심 라이브러리

스프링 MVC

스프링 ORM

JPA, 하이버네이트

스프링 데이터 JPA

 

기타 라이브러리

H2 데이터베이스 클라이언트

커넥션 풀: 부트 기본은 HikariCP

WEB(thymeleaf)

로깅 SLF4J & LogBack

테스트

 


#view 환경 설정

 

thymeleaf 템플릿 엔진

thymeleaf 공식 사이트

https://www.thymeleaf.org/

 

Thymeleaf

Integrations galore Eclipse, IntelliJ IDEA, Spring, Play, even the up-and-coming Model-View-Controller API for Java EE 8. Write Thymeleaf in your favourite tools, using your favourite web-development framework. Check out our Ecosystem to see more integrati

www.thymeleaf.org

스프링 공식 튜토리얼

https://spring.io/guides/gs/serving-web-content/

 

Serving Web Content with Spring MVC

this guide is designed to get you productive as quickly as possible and using the latest Spring project releases and techniques as recommended by the Spring team

spring.io

스프링부트 메뉴얼

https://docs.spring.io/spring-boot/docs/2.1.6.RELEASE/reference/html/boot-features-developing-web-applications.html#boot-features-spring-mvc-template- engines

 

 


파일구조

HelloCotroller

@Controller
public class HelloController {
    @GetMapping("hello") //hello url로 이동하면 컨트롤러를 실행하겠다.
    public String hello(Model model) {
        model.addAttribute("data", "hello!!");
        //model에 데이터를 컨트롤러에 실어서 view로 넘긴다.
        //name이 data인 value 값이 hello 인거 넘긴다
        return "hello"; //스프링부트의 타임리프가 설정을 걸면서 자동으로 hello.html로 매핑해서 이동

        /*
         스프링 부트 thymeleaf viewName 매핑
         resources:templates/ +{ViewName}+ .html
         */
    }
}

 

 

index.html

<!DOCTYPE HTML>
<html>
<head>
    <title>Hello</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
Hello
<a href="/hello">hello</a> <!--hello.html로 이동-->
</body>
</html>

<!--랜더링안하고 순수한 html파일만 뿌리겠다 ,정적
!!!리소스 파일에 넣었을땐 무조건 서버리스타트!!!-->

 

http://localhost:8080/hello
페이지 소스보기

서버사이드랜더링

 

 

hello.html

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org"> <!--타임리프-->
<head>
    <title>Hello</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p th:text="'안녕 ' + ${data}" >안녕하세요. 손님</p>
<!--th-->
</body>
</html>

http://localhost:8080/

 

 

th 속성 복습

https://lshh222777.tistory.com/21

 

스타트 스프링 부트 - 5장

Thymeleaf - 템플릿이 기본적으로 출력할 데이터가 없는 상황에서 HTML로 작성된 내용이 그대로 반영된다는 장점 - 유지보수가 쉽다. - JSP와 달리 Servlet Code로 변환되지 않는다. 비즈니스 로직과 분리

lshh222777.tistory.com

 

 


#H2데이터베이스

 

h2 console 실행

처음 : 연결

 

파일 연결 끊은 후

 

 

그 이후부터는 jdbc-url로 접근가능 :  jdbc:h2:tcp://localhost/~/jpashop

 

 

강의 : https://www.inflearn.com/course/%EC%8A%A4%ED%94%84%EB%A7%81%EB%B6%80%ED%8A%B8-JPA-%ED%99%9C%EC%9A%A9-1/dashboard

댓글