Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

application.properties 설정파일 추가 #4

Merged
merged 5 commits into from
Jan 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 32 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@
<java.version>1.8</java.version>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand All @@ -33,6 +39,20 @@
<version>2.1.4</version>
</dependency>

<!-- DB -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>

<!-- Template Engine -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

<!-- Util -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand All @@ -44,25 +64,21 @@
<scope>runtime</scope>
<optional>true</optional>
</dependency>

<!-- Encryption Library -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>3.0.3</version>
</dependency>

<!-- Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</dependencies>

</project>
63 changes: 63 additions & 0 deletions src/main/java/com/hwangwongyu/news/config/DateTimeConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.hwangwongyu.news.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.Formatter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

@Configuration
public class DateTimeConfig {

@Bean
public Formatter<LocalDate> localDateFormatter() {
return new Formatter<LocalDate>() {
@Override
public LocalDate parse(String text, Locale locale) {
return LocalDate.parse(text, DateTimeFormatter.ofPattern("yyyyMMdd", locale));
}

@Override
public String print(LocalDate object, Locale locale) {
return DateTimeFormatter.ISO_DATE.format(object);
}
};
}


@Bean
public Formatter<LocalDateTime> localDateTimeFormatter() {
return new Formatter<LocalDateTime>() {
@Override
public LocalDateTime parse(String text, Locale locale) {
return LocalDateTime.parse(text, DateTimeFormatter.ofPattern("yyyyMMddHHmmss", locale));
}

@Override
public String print(LocalDateTime object, Locale locale) {
return DateTimeFormatter.ISO_DATE_TIME.format(object);
}
};
}

@Bean
public Formatter<LocalTime> DateFormatter() {
return new Formatter<LocalTime>() {
@Override
public LocalTime parse(String text, Locale locale) throws ParseException {
return LocalTime.parse(text, DateTimeFormatter.ofPattern("HHmmss", locale));
}

@Override
public String print(LocalTime object, Locale locale) {
return new SimpleDateFormat("HH:mm:ss").format(object);
}
};
}
}
22 changes: 22 additions & 0 deletions src/main/java/com/hwangwongyu/news/config/StringToConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.hwangwongyu.news.config;

import com.hwangwongyu.news.user.UserDTO;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;

@Configuration
public class StringToConverter {

@Bean
public Converter<String, UserDTO.Sex> stringToSexConverter() {
return new Converter<String, UserDTO.Sex>()
{
@Override
public UserDTO.Sex convert(String source) {
return UserDTO.Sex.valueOf(source.toUpperCase());
}
};
}

}
21 changes: 21 additions & 0 deletions src/main/java/com/hwangwongyu/news/encrypt/JasyptConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.hwangwongyu.news.encrypt;

import org.jasypt.encryption.StringEncryptor;
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class JasyptConfig {

@Bean("jasyptStringEncryptor")
public StringEncryptor stringEncryptor() {
PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
SimpleStringPBEConfig config = new SimpleStringPBEConfig();
config.setPassword("wgh");
config.setPoolSize(1);
encryptor.setConfig(config);
return encryptor;
}
}
61 changes: 61 additions & 0 deletions src/main/java/com/hwangwongyu/news/user/UserController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.hwangwongyu.news.user;

import java.util.List;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserController {

private final UserService userService;

public UserController(UserService userService)
{
this.userService = userService;
}

@Value("${spring.webservice.index}")
private String indexURL;


@GetMapping("/allusers")
public List<UserDTO> allUsers() {
return userService.allUsers();
}

@PostMapping("/user")
public String addUser(UserDTO user)
{
userService.addUser(user);
return "redirect:" + indexURL;
}

@PutMapping("/user")
public String updateUser(UserDTO user) {
userService.updateUser(user);
return "redirect:" + indexURL;
}

@DeleteMapping("/user")
public String deleteUser(String loginId)
{
userService.deleteUser(loginId);
return "redirect:" + indexURL;
}

@GetMapping("/user/{id}")
public UserDTO findUserById(@PathVariable long id)
{
UserDTO user = userService.findUserById(id);
if(user != null)
return user;
else
return null;
}





}
38 changes: 38 additions & 0 deletions src/main/java/com/hwangwongyu/news/user/UserDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.hwangwongyu.news.user;

import lombok.*;

import java.time.LocalDate;

@Setter
@Getter
@ToString
@NoArgsConstructor
public class UserDTO {

@Getter
@ToString
public enum Sex {
MALE,
FEMALE
}

String loginId;
String name;
LocalDate birthDate;
Sex sex;
String password;
String nickname;
String phoneNumber;

@Builder
private UserDTO(String loginId, String name, LocalDate birthDate, Sex sex, String password, String nickname, String phoneNumber) {
this.loginId = loginId;
this.name = name;
this.birthDate = birthDate;
this.sex = sex;
this.password = password;
this.nickname = nickname;
this.phoneNumber = phoneNumber;
}
}
19 changes: 19 additions & 0 deletions src/main/java/com/hwangwongyu/news/user/UserMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.hwangwongyu.news.user;

import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

List<UserDTO> allUsers();

Integer addUser(UserDTO user);

Integer updateUser(UserDTO user);

Integer deleteUser(String loginId);

UserDTO findUserById(long id);
}
16 changes: 16 additions & 0 deletions src/main/java/com/hwangwongyu/news/user/UserService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.hwangwongyu.news.user;

import java.util.List;

public interface UserService {

List<UserDTO> allUsers();

Integer addUser(UserDTO user);

Integer updateUser(UserDTO user);

Integer deleteUser(String loginId);

UserDTO findUserById(long id);
}
42 changes: 42 additions & 0 deletions src/main/java/com/hwangwongyu/news/user/UserServiceImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.hwangwongyu.news.user;

import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

private final UserMapper userMapper;

UserServiceImpl(UserMapper userMapper)
{
this.userMapper = userMapper;
}

@Override
public List<UserDTO> allUsers() {
return userMapper.allUsers();
}

@Override
public Integer addUser(UserDTO user)
{
return userMapper.addUser(user);
}

@Override
public Integer updateUser(UserDTO user) {
return userMapper.updateUser(user);
}

@Override
public Integer deleteUser(String loginId) {
return userMapper.deleteUser(loginId);
}

@Override
public UserDTO findUserById(long id) {
return userMapper.findUserById(id);
}
}
23 changes: 23 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
##Database
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/news?serverTimezone=UTC
spring.datasource.username=ENC(pqDIZXI0lbgUqqM7Wi20yQ==)
spring.datasource.password=ENC(QbpvVIGq2C2+Mls7PcWnJx5DpratEzGx)

##MyBatis
mybatis.type-aliases-package=com.hwangwongyu.news.user
mybatis.mapper-locations=classpath:mappers/*.xml

##Lombok
lombok.allArgsConstructor.flagUsage=error
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# @AllArgsConstructor 사용 지양~
이런 주석은 굳이 필요할까?..?
팀단위 개발시에 가독성만 해칠거같은데 한번 생각해봐.

Copy link
Owner Author

@HwangWonGyu HwangWonGyu Jan 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

application.properties에는 '프로퍼티', git commit log에는 '프로퍼티에 대한 설명' 이라는 역할을 나눠서
각각 책임에 맞는 정보를 저장해서 가독성 높일 수 있다고 생각해봤다

문제 되는 주석 제거하고 commit log로 옮겨볼게
괜찮은 생각이야?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

application.properties에는 '프로퍼티', git commit log에는 '프로퍼티에 대한 설명' 이라는 역할을 나눠서
각각 책임에 맞는 정보를 저장해서 가독성 높일 수 있다고 생각해봤다

문제 되는 주석 제거하고 commit log로 옮겨볼게
괜찮은 생각이야?

이거는 오히려 관심사 분리가 아니고
같은 관심사인데 다른 class로 분리하는 느낌이라 한곳에서 다 관리하는게 좋아보여!

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

application.properties에는 '프로퍼티', git commit log에는 '프로퍼티에 대한 설명' 이라는 역할을 나눠서
각각 책임에 맞는 정보를 저장해서 가독성 높일 수 있다고 생각해봤다
문제 되는 주석 제거하고 commit log로 옮겨볼게
괜찮은 생각이야?

이거는 오히려 관심사 분리가 아니고
같은 관심사인데 다른 class로 분리하는 느낌이라 한곳에서 다 관리하는게 좋아보여!

응~ 주석 복구하고
주석 내용, 관리방법 재검토해서 반영할게

lombok.experimental.flagUsage=error

##Web Index
spring.webservice.index= /

##Jasypt
jasypt.encryptor.bean=jasyptStringEncryptor
jasypt.encryptor.algorithm=PBEWithMD5AndDES
jasypt.encryptor.property.prefix=ENC(
jasypt.encryptor.property.suffix=)
jasypt.encryptor.poolSize=1
Loading