add jpa module
This commit is contained in:
@@ -24,8 +24,8 @@ repositories {
|
|||||||
java {
|
java {
|
||||||
withSourcesJar()
|
withSourcesJar()
|
||||||
withJavadocJar()
|
withJavadocJar()
|
||||||
sourceCompatibility = org.gradle.api.JavaVersion.VERSION_1_8
|
sourceCompatibility = org.gradle.api.JavaVersion.VERSION_17
|
||||||
targetCompatibility = org.gradle.api.JavaVersion.VERSION_1_8
|
targetCompatibility = org.gradle.api.JavaVersion.VERSION_17
|
||||||
}
|
}
|
||||||
|
|
||||||
configurations {
|
configurations {
|
||||||
|
|||||||
@@ -14,5 +14,4 @@ plugins {
|
|||||||
dependencies{
|
dependencies{
|
||||||
//implementation("org.jetbrains:annotations:24.0.0")
|
//implementation("org.jetbrains:annotations:24.0.0")
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
29
jpa/README.md
Normal file
29
jpa/README.md
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# spring-boot-validation-examples
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
implementation ("org.springframework.boot:spring-boot-starter-validation")
|
||||||
|
```
|
||||||
|
|
||||||
|
## Annotations
|
||||||
|
|
||||||
|
* @Digits
|
||||||
|
* @Email
|
||||||
|
* @Max
|
||||||
|
* @Min
|
||||||
|
* @Negative
|
||||||
|
* @NotBlank
|
||||||
|
* @NotEmpty
|
||||||
|
* @NotNull
|
||||||
|
* @Null
|
||||||
|
* @Pattern
|
||||||
|
* @Positive
|
||||||
|
* @Size
|
||||||
|
|
||||||
|
https://docs.jboss.org/hibernate/beanvalidation/spec/2.0/api/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
developed by Elex
|
||||||
|
|
||||||
|
https://www.elex-project.com
|
||||||
34
jpa/build.gradle.kts
Normal file
34
jpa/build.gradle.kts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Spring-boot Examples
|
||||||
|
*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id("elex-spring-boot")
|
||||||
|
id("org.springframework.boot") version "3.2.3"
|
||||||
|
id("io.spring.dependency-management") version "1.1.4"
|
||||||
|
}
|
||||||
|
java {
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
|
||||||
|
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
|
||||||
|
implementation("org.springframework.boot:spring-boot-starter-web")
|
||||||
|
|
||||||
|
// https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jsr310
|
||||||
|
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
|
||||||
|
runtimeOnly("org.mariadb.jdbc:mariadb-java-client")
|
||||||
|
|
||||||
|
implementation ("org.springframework.boot:spring-boot-starter-validation")
|
||||||
|
|
||||||
|
compileOnly("org.projectlombok:lombok")
|
||||||
|
developmentOnly("org.springframework.boot:spring-boot-devtools")
|
||||||
|
|
||||||
|
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
|
||||||
|
annotationProcessor("org.projectlombok:lombok")
|
||||||
|
|
||||||
|
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||||
|
}
|
||||||
20
jpa/src/main/java/kr/pe/elex/examples/Application.java
Normal file
20
jpa/src/main/java/kr/pe/elex/examples/Application.java
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Spring-boot Examples
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class Application {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(Application.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
29
jpa/src/main/java/kr/pe/elex/examples/Config.java
Normal file
29
jpa/src/main/java/kr/pe/elex/examples/Config.java
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Configuration
|
||||||
|
@EnableScheduling
|
||||||
|
public class Config {
|
||||||
|
@Autowired
|
||||||
|
private PersonRepository repository;
|
||||||
|
@Scheduled(fixedRate = 1, timeUnit = TimeUnit.MINUTES)
|
||||||
|
public void task1(){
|
||||||
|
log.info("TASK executed.");
|
||||||
|
repository.deleteAllInBatch(repository
|
||||||
|
.findByCreatedAtLessThan(LocalDateTime.now().minusMinutes(2)));
|
||||||
|
}
|
||||||
|
}
|
||||||
42
jpa/src/main/java/kr/pe/elex/examples/MyController.java
Normal file
42
jpa/src/main/java/kr/pe/elex/examples/MyController.java
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Spring-boot Examples
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
public class MyController {
|
||||||
|
@Autowired
|
||||||
|
private PersonRepository repository;
|
||||||
|
|
||||||
|
@GetMapping({"/"})
|
||||||
|
public String index() {
|
||||||
|
return "home";
|
||||||
|
}
|
||||||
|
@GetMapping({"/list"})
|
||||||
|
public List<PersonDto> list() {
|
||||||
|
return repository.findAll().stream()
|
||||||
|
.map(PersonDto::of)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping(value = {"/add/{name}"})
|
||||||
|
public PersonDto addPerson(@PathVariable String name) {
|
||||||
|
|
||||||
|
Person person = repository.save(Person.builder().name(name).build());
|
||||||
|
return PersonDto.of(person);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
33
jpa/src/main/java/kr/pe/elex/examples/Person.java
Normal file
33
jpa/src/main/java/kr/pe/elex/examples/Person.java
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021-2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.hibernate.annotations.CreationTimestamp;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Entity
|
||||||
|
@AllArgsConstructor@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class Person {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
@Column
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Column
|
||||||
|
@CreationTimestamp
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
}
|
||||||
40
jpa/src/main/java/kr/pe/elex/examples/PersonDto.java
Normal file
40
jpa/src/main/java/kr/pe/elex/examples/PersonDto.java
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||||
|
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class PersonDto {
|
||||||
|
@JsonProperty
|
||||||
|
private Long id;
|
||||||
|
@JsonProperty
|
||||||
|
private String name;
|
||||||
|
@JsonProperty
|
||||||
|
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||||
|
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
|
||||||
|
public static PersonDto of(Person person){
|
||||||
|
return PersonDto.builder()
|
||||||
|
.id(person.getId())
|
||||||
|
.name(person.getName())
|
||||||
|
.createdAt(person.getCreatedAt())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
17
jpa/src/main/java/kr/pe/elex/examples/PersonRepository.java
Normal file
17
jpa/src/main/java/kr/pe/elex/examples/PersonRepository.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024. Elex. All Rights Reesrved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface PersonRepository extends JpaRepository<Person, Long> {
|
||||||
|
public List<Person> findByCreatedAtLessThan(LocalDateTime date);
|
||||||
|
}
|
||||||
8
jpa/src/main/java/kr/pe/elex/examples/package-info.java
Normal file
8
jpa/src/main/java/kr/pe/elex/examples/package-info.java
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
/*
|
||||||
|
* Spring-boot Examples
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples;
|
||||||
22
jpa/src/main/resources/application.yaml
Normal file
22
jpa/src/main/resources/application.yaml
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: My spring-boot project
|
||||||
|
datasource:
|
||||||
|
url: jdbc:mariadb://localhost:3306/test
|
||||||
|
driver-class-name: org.mariadb.jdbc.Driver
|
||||||
|
username: testuser
|
||||||
|
password: _test_
|
||||||
|
jpa:
|
||||||
|
open-in-view: false
|
||||||
|
generate-ddl: true
|
||||||
|
show-sql: true
|
||||||
|
hibernate:
|
||||||
|
ddl-auto: update
|
||||||
|
properties:
|
||||||
|
hibernate:
|
||||||
|
dialect: org.hibernate.dialect.MariaDBDialect
|
||||||
|
thymeleaf:
|
||||||
|
prefix: classpath:/view/
|
||||||
|
suffix: .html
|
||||||
|
server:
|
||||||
|
port: 8080
|
||||||
10
jpa/src/main/resources/banner.txt
Normal file
10
jpa/src/main/resources/banner.txt
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
('-. ('-. ) (`-.
|
||||||
|
_( OO) _( OO) ( OO ).
|
||||||
|
(,------.,--. (,------.(_/. \_)-.
|
||||||
|
| .---'| |.-') | .---' \ `.' /
|
||||||
|
| | | | OO ) | | \ /\
|
||||||
|
(| '--. | |`-' |(| '--. \ \ |
|
||||||
|
| .--'(| '---.' | .--' .' \_)
|
||||||
|
| `---.| | | `---. / .'. \
|
||||||
|
`------'`------' `------''--' '--'
|
||||||
|
powered by ELEX
|
||||||
47
jpa/src/main/resources/logback-spring.xml
Normal file
47
jpa/src/main/resources/logback-spring.xml
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ Spring-boot Examples
|
||||||
|
~
|
||||||
|
~ Copyright (c) 2020-2021. Elex. All Rights Reserved.
|
||||||
|
~ https://www.elex-project.com/
|
||||||
|
-->
|
||||||
|
|
||||||
|
<configuration>
|
||||||
|
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
|
||||||
|
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
|
||||||
|
|
||||||
|
<springProperty name="LOG_DIR" source="logging.path"
|
||||||
|
defaultValue="${user.home}/logs"/>
|
||||||
|
<property name="LOG_PATH" value="${LOG_DIR}/stephanie.log"/>
|
||||||
|
|
||||||
|
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<appender name="ROLLING-FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||||
|
<charset>UTF-8</charset>
|
||||||
|
<pattern>${FILE_LOG_PATTERN}</pattern>
|
||||||
|
</encoder>
|
||||||
|
<file>${LOG_PATH}</file>
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<fileNamePattern>${LOG_DIR}/sebastian_%d{yyyy-MM-dd}_%i.log.gz</fileNamePattern>
|
||||||
|
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||||
|
<maxFileSize>10MB</maxFileSize>
|
||||||
|
</timeBasedFileNamingAndTriggeringPolicy>
|
||||||
|
<maxHistory>60</maxHistory>
|
||||||
|
</rollingPolicy>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<logger name="kr.pe.elex" level="debug" additivity="false">
|
||||||
|
<appender-ref ref="CONSOLE"/>
|
||||||
|
<appender-ref ref="ROLLING-FILE"/>
|
||||||
|
</logger>
|
||||||
|
<root level="info">
|
||||||
|
<appender-ref ref="CONSOLE"/>
|
||||||
|
<appender-ref ref="ROLLING-FILE"/>
|
||||||
|
</root>
|
||||||
|
|
||||||
|
</configuration>
|
||||||
1
jpa/src/main/resources/templates/home.mustache
Normal file
1
jpa/src/main/resources/templates/home.mustache
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<h1>Test</h1>
|
||||||
@@ -8,8 +8,8 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id("elex-spring-boot")
|
id("elex-spring-boot")
|
||||||
|
|
||||||
id("org.springframework.boot") version "2.5.3"
|
id("org.springframework.boot") version "3.2.3"
|
||||||
id("io.spring.dependency-management") version "1.0.11.RELEASE"
|
id("io.spring.dependency-management") version "1.1.4"
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|||||||
@@ -10,5 +10,5 @@ include(
|
|||||||
"file-upload", "security", "security-with-jpa", "validation", "testing",
|
"file-upload", "security", "security-with-jpa", "validation", "testing",
|
||||||
"mqtt", "websocket", "restful", "swing", "rest-doc",
|
"mqtt", "websocket", "restful", "swing", "rest-doc",
|
||||||
"cache", "security-with-jwt", "exception", "i18n", "i18n-mustache","mvc",
|
"cache", "security-with-jwt", "exception", "i18n", "i18n-mustache","mvc",
|
||||||
"thymeleaf", "interceptor"
|
"thymeleaf", "interceptor", "jpa"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user