JPA쇼핑몰만들기(05).indd 1 2021-08-26 오후 8:26:04

34

Transcript of JPA쇼핑몰만들기(05).indd 1 2021-08-26 오후 8:26:04



JPA(05).indd 3 2021-08-26 8:26:05
.
. , ,
.
, .
. MVC , , HTML, CSS,
.
.
,
.
.
.

. .
.
Thymeleaf, Spring Data JPA , ,
.
,
.
,
.
.
,
. .
, .

.
.
. JPA,
, Thymeleaf
,
. ‘’
. . !
_

.
. JPA Thymeleaf
.
· .
.
.
.
_

.
.
,
JPA, Thymleaf, Test(Junit)
.
.
_

5. : MySQL

, , , , / & JPA
.

.
. 6, 7, 8
HTML ,
. .
: https://github.com/roadbook2/shop

1: .
2: (VCS > Get from Version Control ).
3: .
4: URL .
( )

[ ] .
, .
3 Thymeleaf 137
15
17
21
1 layout html layout .
2 th:replace html html .
fragments header.html “th:fragment=header” .
3 layout fragment .
.
4 header fragments footer.html “th:fragment="footer"
.
[ 3-24] Thymeleaf : thymeleaf
resources/templates/thymeleafEx07.html
05
07 . 08 </div> 09
10 </html>
1 layouts layout1.html .
2 layout1.html <div layout:fragment="content"> .
JPA(02).indd 137 2021-08-06 12:53:30

JPA(05).indd 7 2021-08-26 8:26:05
,
.
[ 2-5] JPAQuery

T fetchOne 1
T fetchFirst() 1
Long fetchCount()
QueryResult<T> fetchResults() QueryResults
JPAQuery where
, .
.
[ 2-32] QueryDsl
QuerydslPredicateExecutor . Predicate ‘
’ . Repository Predicate
QueryDslPredicateExecutor .
JPA(02).indd 105 2021-08-06 12:59:20

.
100
@Query . @Query JPQL

. .
Querydsl .
[ 2-8] ‘where’ ‘wheere’
. [ 2-27]

.
[ 2-27] JPQL wheere
Querydsl. Querydsl JPQL
API. Querydsl SQL
. .
. JPQL
. Querydsl .
Querydsl
SQL .
.
.
IDE
.
Querydsl . pom.xml <dependencies>
</dependencies> .
JPA(02).indd 100 2021-08-06 1:03:02

“ ”
. HTML5 , C#, Vue.js,

.
.

, , (WAS) 16
‘ ’ 17
XML 17
17
1.2 JDK 18
1.3 23
1.4 27
1.4.2 31
1.4.3 (application.properties) 34
1.5 Lombok 39
1.6 MySQL 46
[ 1-2] Hello World 36
[ 1-3] 38
[ 1-4] Lombok 42
2 Spring Data JPA
2.2.1 67
2.2.2 application.properties 69
2.4 Repository 80
2.5 86
2.7 Spring DATA JPA Querydsl 98
[ 2-1] _Ver01 74
[ 2-2] _Ver02 78
[ 2-3] Repository 81
[ 2-4] 86
[ 2-5] OR 90
[ 2-6] LessThan 91
[ 2-7] OrderBy 92
[ 2-8] @Query 94
[ 2-9] @Query–nativeQuery 96
[ 2-10] JPAQueryFactory 101
[ 2-11] QuerydslPredicateExecutor 104
3 Thymeleaf
3.3.1 th:text 119
3.3.2 th:each 122
3.3.5 th:href 128
3.4.1 Thymeleaf Layout Dialect dependency 133
3.5 header, footer 137
3.5.1 Bootstrap CDN 137
3.5.2 Bootstrap Navbar Component 139
[ 3-1] Thymeleaf 110
[ 3-2] Thymeleaf 111
[ 3-3] Thymeleaf 112
[ 3-4] pom.xml 114
[ 3-5] application.properties Live Reload 116
[ 3-6] application.properties Property Defaults 118
[ 3-7] th:text Dto 119
[ 3-8] th:text 120
[ 3-9] th:text thymeleaf 121
[ 3-10] th:each 122
[ 3-11] th:each thymeleaf 123
[ 3-12] th:if, th:unless 124
[ 3-13] th:if, th:unless thymeleaf 125
[ 3-14] th:switch, th:case thymeleaf 127
[ 3-15] th:href 129
[ 3-16] th:href thymeleaf 129
[ 3-17] th:href thymeleaf 130
[ 3-18] th:href 131
[ 3-19] th:href thymeleaf 131
[ 3-20] pom.xml Thymeleaf Layout Dialect 133
[ 3-21] Thymeleaf : 134
[ 3-22] Thymeleaf : 134
[ 3-23] Thymeleaf : 134
[ 3-24] Thymeleaf : thymeleaf 135
[ 3-25] Thymeleaf : 136
[ 3-26] Bootstrap CDN 138
[ 3-27] Navbar 140
[ 3-28] 141
[ 3-29] CSS 142
[ 3-30] CSS HTML 143
JPA(05).indd 11 2021-08-26 8:26:05
4
4.1 146
4.2 147
4.2.1 security dependency 147
4.2.2 150
4.3 152
4.4 / 169
[ 4-1] 148
[ 4-2] SecurityConfig 150
[ 4-3] 152
[ 4-4] 156
[ 4-5] 159
[ 4-6] 162
[ 4-7] 165
[ 4-8] / 170
[ 4-9] 175
[ 4-10] / 178
[ 4-11] 181
[ 4-12] 186
5
5.1.1 191
5.1.2 196
5.1.3 / 198
5.1.4 202
5.2 205
5.2.1 ? 205
5.3 213
[ 5-1] 191
[ 5-2] ( ) 193
[ 5-3] 196
[ 5-4] 198
[ 5-5] 206
[ 5-6] 210
[ 5-7] ( ) 213
[ 5-8] 219
[ 5-9] Auditing 222
6
6.1 230
6.2 256
6.3 265
6.4 280
[ 6-1] 230
[ 6-2] 256
[ 6-3] 266
[ 6-4] 280
JPA(05).indd 13 2021-08-26 8:26:06
7
7.3 321
[ 7-4] 309
[ 7-5] 321
[ 7-6] 325
[ 7-7] 326
8
[ 8-1] 330
[ 8-2] 336
[ 8-3] 339
[ 8-4] 341
[ 8-5] 351
[ 8-6] 356
[ 8-7] 360
368


16
1.1

. .
.
.
.
‘ ’
. ‘ ’ .
, .
.
1.
2. , (WAS)
3. ‘Spring Boot Starter’
4. XML
5. JAR
6.
, , (WAS)
Tomcat .

. Jetty Undertow pom.
xml .
JPA(05).indd 16 2021-08-26 8:26:06
1 17
‘ ’
stater .
.

.
XML
XML . XML
.
.
.


. Spring Actuator
.
!
JPA(05).indd 17 2021-08-26 8:26:06
18
JDK(Java Development Kit) . JDK

.
.
Maven . JDK 1.8 .
SDK
.
1. : Window 10
5. : MySQL
jdk11-archive-downloads.html JDK
. .
JDK .
JPA(05).indd 18 2021-08-26 8:26:06
1 19
[ 1-1] JDK 11
Path JDK
.
[]–[ ]–[] .
[ 1-2] 1
JPA(05).indd 19 2021-08-26 8:26:06
20
[ 1-3] 2
< > .
s
JPA(05).indd 20 2021-08-26 8:26:06
1 21
JDK 11 JAVA_HOME .
[ 1-5] 4
JAVA_HOME , Path .
[ 1-6] 5
JPA(05).indd 21 2021-08-26 8:26:06
22
< (N)> [ 1-7] .
[ 1-7] 6
(CMD) .
java -version
1.3
.
https://www.jetbrains.com/ko-kr/idea/download
. Ultimate Community ,
Community . Ultimate Community
.
JPA(05).indd 23 2021-08-26 8:26:07
24
Ultaimate 30 ,
. [ 1-9]
<Community > .
. <Next> .
[ 1-10] IntelliJ Community 1
JPA(05).indd 24 2021-08-26 8:26:07
1 25
<Next>, 4 <Next> .
[ 1-11] IntelliJ Community 2
[ 1-12] IntelliJ Community 3
JPA(05).indd 25 2021-08-26 8:26:07
26
<Install> .
[ 1-13] IntelliJ Community 4
[ 1-14] IntelliJ Community 5
JPA(05).indd 26 2021-08-26 8:26:07
1 27
1.4
“Hello World!”
.
1.4.1 Spring Boot Project
Spring Initializr
. https://start.spring.io/ .
.

.
Maven
. [ 1-15]
<ADD DEPENDENCIES> ‘Spring Web’ .
. artifact
. id
spring-demo . com.example .
Package name spring-demo .

• –
• –Java 11
( Java 1.8 )
• : 2.5.2
28
[ 1-15] 1
<GENERATE> spring-demo.zip
. ( , C test
C:\test ) .
C:\Users\dksek\IdeaProjects . . [
1-17] <Open or Import> spring initializr
.
[ 1-16] ‘Do not import settings’
<OK> .
JPA(05).indd 28 2021-08-26 8:26:07
1 29
<Open or Import> .
[ 1-17] 3
[ 1-18] <OK> .
[ 1-18] 4
JPA(05).indd 29 2021-08-26 8:26:07
30
[ 1-19]
.
[ 1-20]
JPA(05).indd 30 2021-08-26 8:26:07
1 31
1: src/main/java .
2: src/main/resources HTML, CSS, JS,
.
3: thymeleaf src/
main/resources/templates . HTML ,
Controller Class html .
4: src/test/java .
1.4.2
.
pom.xml
. jar
.
pom.xml
21 <groupId>org.springframework.boot</groupId>
32
25 <dependency> 3
32 <build> 33 <plugins> 34 <plugin> 35 <groupId>org.springframework.boot</groupId> 36 <artifactId>spring-boot-maven-plugin</artifactId> 37 </plugin> 38 </plugins> 39 </build> 40
41 </project>
2
3 Spring Test Framework
[ 1-21] [Maven] . [Maven]
‘Dependencies’ pom.xml ‘spring-boot-starter-web’ ‘spring-boot-
starter-test’ .
[ 1-21] maven dependency
JPA(05).indd 32 2021-08-26 8:26:07
1 33
Local repository .
‘Build Tools Settings’ . 2 [Maven Settings]
.
[ 1-22] maven settings
[ 1-23] Maven Local repository .
[ 1-23] local maven repository
JPA(05).indd 33 2021-08-26 8:26:07
34
.

Local repository .
[ 1-24] local maven repository
1.4.3 (application.properties)
.
‘src/main/resources’ .
.
, , , port, debug level
.
application-{profile}.properties
, application-dev.properties
application-prod.properties . jar
VM .
JPA(05).indd 34 2021-08-26 8:26:07
1 35
application.properties @Value
.
[ 1-1] application.properties
01 server.port = 80 1
02 application.name = spring-demo 2
1 . 8080. 80 url
.
2 ‘spring-demo’ .
@Value .
?
(Annotation) . JDK5 (
) . , ‘@’ .
, .
@Override .
.
.
application.yml .
application.properties
.
server: port: 9091
.
.
application.properties .
JPA(05).indd 35 2021-08-26 8:26:08