
+++ .gitignore
... | ... | @@ -0,0 +1,13 @@ |
1 | +/target/ | |
2 | +/.idea/ | |
3 | +/.classpath | |
4 | +/.project | |
5 | +/.settings | |
6 | +/.jsdtscope | |
7 | +/org.eclipse.jdt.core.prefs | |
8 | +/org.eclipse.wst.common.component | |
9 | +/org.eclipse.wst.common.project.facet.core.xml | |
10 | +/org.eclipse.wst.jsdt.ui.superType.container | |
11 | +/org.eclipse.wst.jsdt.ui.superType.name | |
12 | +/org.eclipse.wst.validation.prefs | |
13 | + |
+++ client/WEB-INF/index.jsp
... | ... | @@ -0,0 +1,16 @@ |
1 | +<%-- | |
2 | + Created by IntelliJ IDEA. | |
3 | + User: chlwj | |
4 | + Date: 2023-04-27 | |
5 | + Time: 오후 12:34 | |
6 | + To change this template use File | Settings | File Templates. | |
7 | +--%> | |
8 | +<%@ page contentType="text/html;charset=UTF-8" language="java" %> | |
9 | +<html> | |
10 | + <head> | |
11 | + <title>spring edu</title> | |
12 | + </head> | |
13 | + <body> | |
14 | + Hello World | |
15 | + </body> | |
16 | +</html>(파일 끝에 줄바꿈 문자 없음) |
+++ client/WEB-INF/web.xml
... | ... | @@ -0,0 +1,10 @@ |
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | +<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" | |
3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
4 | + xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" | |
5 | + version="4.0"> | |
6 | + | |
7 | + <display-name>project-setting-manual</display-name> | |
8 | + | |
9 | + | |
10 | +</web-app>(파일 끝에 줄바꿈 문자 없음) |
+++ client/views/index.html
... | ... | @@ -0,0 +1,14 @@ |
1 | +<!DOCTYPE html> | |
2 | +<html lang="en"> | |
3 | +<head> | |
4 | + <meta charset="UTF-8"> | |
5 | + <title>Title</title> | |
6 | +</head> | |
7 | +<body> | |
8 | +Hello World | |
9 | + | |
10 | +<script> | |
11 | + console.log('Hello World'); | |
12 | +</script> | |
13 | +</body> | |
14 | +</html>(파일 끝에 줄바꿈 문자 없음) |
+++ pom.xml
... | ... | @@ -0,0 +1,178 @@ |
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | +<!-- | |
3 | + 작성자: 하석형 | |
4 | + 작성일: 230814 | |
5 | + 내용 : Maven Spring Legacy Proejct 세팅 | |
6 | +--> | |
7 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
8 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd"> | |
9 | + | |
10 | + <modelVersion>4.0.0</modelVersion><!-- modelVersion: Maven POM의 버전 --> | |
11 | + <groupId>kr.co.takensoft</groupId><!-- groupId: 기관(소속) 식별자 --> | |
12 | + <artifactId>Data_Quailty</artifactId><!-- artifactId: 현재 project의 식별자 --> | |
13 | + <name>Data_Quailty</name><!-- name: 현재 project의 명칭 --> | |
14 | + <packaging>war</packaging><!-- packaging: 어떤 파일 형식으로 패키징할 것인가를 정의, jar, war, exe 등이 올 수 있음 --> | |
15 | + <version>1.0.0-BUILD-SNAPSHOT</version><!-- version: 해당 artifact(컴포넌트)의 version, 뒤쪽 SNAPSHOT은 아직 개발 중임을 의미함 --> | |
16 | + | |
17 | + <!-- properties: POM.xml에서 사용할 변수 --> | |
18 | + <properties> | |
19 | + <java-version>15</java-version> | |
20 | + <org.springframework.version>5.3.22</org.springframework.version> | |
21 | + <egovframework.rte.version>3.10.0</egovframework.rte.version> | |
22 | + | |
23 | + <back-end-path>${project.basedir}/server</back-end-path> | |
24 | + <front-end-path>${project.basedir}/client</front-end-path> | |
25 | + </properties> | |
26 | + | |
27 | + | |
28 | + <!-- repositories: 라이브러리를 다운로드 받을 위치들을 설정 하는 곳 --> | |
29 | + <repositories> | |
30 | + <!-- repository: 라이브러리를 다운로드 받을 위치 설정, 기술되지 않을 시 기본적인 위치: https://repo1.maven.org/maven2/ --> | |
31 | + <!-- Apache재단 Maven 의존성 라이브러리 저장소 --> | |
32 | + <repository> | |
33 | + <id>mvn2s</id> | |
34 | + <url>https://repo1.maven.org/maven2/</url> | |
35 | + <releases> | |
36 | + <enabled>true</enabled> | |
37 | + </releases> | |
38 | + <snapshots> | |
39 | + <enabled>true</enabled> | |
40 | + </snapshots> | |
41 | + </repository> | |
42 | + <!-- 전자정부프레임워크 Maven 의존성 라이브러리 저장소 --> | |
43 | + <repository> | |
44 | + <id>egovframe</id> | |
45 | + <url>https://repo.maven.apache.org/maven2/</url> | |
46 | + <releases> | |
47 | + <enabled>true</enabled> | |
48 | + </releases> | |
49 | + <snapshots> | |
50 | + <enabled>false</enabled> | |
51 | + </snapshots> | |
52 | + </repository> | |
53 | + </repositories> | |
54 | + | |
55 | + | |
56 | + <!-- dependencies: 의존성 라이브러리들을 설정하는 곳 --> | |
57 | + <dependencies> | |
58 | + | |
59 | + <!-- servlet 라이브러리 --> | |
60 | + <dependency> | |
61 | + <groupId>javax.servlet</groupId> | |
62 | + <artifactId>javax.servlet-api</artifactId> | |
63 | + <version>4.0.1</version> | |
64 | + <scope>provided</scope> | |
65 | + </dependency> | |
66 | + | |
67 | + <!-- Spring Framwork 라이브러리 - 해당 라이브러리 다운로드 시 core, context, beans, expression, web, aop, jcl 이 같이 다운 받아짐 --> | |
68 | + <dependency> | |
69 | + <groupId>org.springframework</groupId> | |
70 | + <artifactId>spring-webmvc</artifactId> | |
71 | + <version>${org.springframework.version}</version> | |
72 | + </dependency> | |
73 | + <!-- Spring Framwork JDBC 라이브러리 - 특정 JDBC를 Bean 등록 해야 한다면 꼭 필요 함 --> | |
74 | + <dependency> | |
75 | + <groupId>org.springframework</groupId> | |
76 | + <artifactId>spring-jdbc</artifactId> | |
77 | + <version>${org.springframework.version}</version> | |
78 | + </dependency> | |
79 | + | |
80 | + <!-- JSON Parsing 라이브러리 - 해당 라이브러리 다운로드 시 core, annotations 이 같이 다운 받아짐 --> | |
81 | + <dependency> | |
82 | + <groupId>com.fasterxml.jackson.core</groupId> | |
83 | + <artifactId>jackson-databind</artifactId> | |
84 | + <version>2.13.3</version> | |
85 | + </dependency> | |
86 | + | |
87 | + <!-- DB Connection Pool : HikariCP --> | |
88 | + <dependency> | |
89 | + <groupId>com.zaxxer</groupId> | |
90 | + <artifactId>HikariCP</artifactId> | |
91 | + <version>5.0.1</version> | |
92 | + </dependency> | |
93 | + | |
94 | + <!-- JDBC : MariaDB --> | |
95 | + <dependency> | |
96 | + <groupId>org.mariadb.jdbc</groupId> | |
97 | + <artifactId>mariadb-java-client</artifactId> | |
98 | + <version>3.0.7</version> | |
99 | + </dependency> | |
100 | + <!-- JDBC : PostgreSQL --> | |
101 | + <dependency> | |
102 | + <groupId>org.postgresql</groupId> | |
103 | + <artifactId>postgresql</artifactId> | |
104 | + <version>42.5.0</version> | |
105 | + </dependency> | |
106 | + | |
107 | + <!-- SQL 작성 및 DBCP, JDBC 인터페이스 기능 담당 라이브러리 Mybatis --> | |
108 | + <dependency> | |
109 | + <groupId>org.mybatis</groupId> | |
110 | + <artifactId>mybatis</artifactId> | |
111 | + <version>3.5.10</version> | |
112 | + </dependency> | |
113 | + | |
114 | + <!-- SQL 작성 및 DBCP, JDBC 인터페이스 기능 담당 라이브러리 Mybatis(SpringFramework와 인터페이스 용) - 해당 라이브러리 활용 시 의존성 라이브러리's mybatis, spring-context, spring-jdbc, spring-batch-infrastructure --> | |
115 | + <dependency> | |
116 | + <groupId>org.mybatis</groupId> | |
117 | + <artifactId>mybatis-spring</artifactId> | |
118 | + <version>2.0.7</version> | |
119 | + </dependency> | |
120 | + | |
121 | + </dependencies> | |
122 | + | |
123 | + | |
124 | + <!-- build: Compile ~ Depoly에 대한 과정을 설정하는 곳 --> | |
125 | + <build> | |
126 | + <!-- finalName: 최종 packaging된 file의 이름 --> | |
127 | + <finalName>ROOT</finalName> | |
128 | + <!-- directory: 빌드 경로 (다른 곳에서 ${deploy.path} 활용하면 됨) --> | |
129 | + <directory>${project.basedir}/target</directory> | |
130 | + <!-- sourceDirectory: Java 및 관련 자원 소스 경로 --> | |
131 | + <sourceDirectory>${back-end-path}/main/java</sourceDirectory> | |
132 | + <!-- testSourceDirectory: Test용 Java 소스 경로 --> | |
133 | + <testSourceDirectory>${back-end-path}/test/java</testSourceDirectory> | |
134 | + <!-- outputDirectory: 컴파일 후 .class 파일 저장 경로 --> | |
135 | + <outputDirectory>${build.directory}/classes</outputDirectory> | |
136 | + | |
137 | + <!-- resources: JAVA File 이외의 자원들을 classpath로 설정하기 위한 곳 --> | |
138 | + <resources> | |
139 | + <resource> | |
140 | + <directory>${back-end-path}/main/resources</directory> | |
141 | + </resource> | |
142 | + </resources> | |
143 | + | |
144 | + <!-- plugins: Maven Plugin을 설정하는 곳 --> | |
145 | + <plugins> | |
146 | + <!-- maven compile plugin --> | |
147 | + <plugin> | |
148 | + <groupId>org.apache.maven.plugins</groupId> | |
149 | + <artifactId>maven-compiler-plugin</artifactId> | |
150 | + <version>3.10.1</version> | |
151 | + <configuration> | |
152 | + <source>${java-version}</source><!-- 소스코드 Java 버전 --> | |
153 | + <target>${java-version}</target><!-- compile시 결과물 Java 버전 --> | |
154 | + </configuration> | |
155 | + </plugin> | |
156 | + | |
157 | + <!-- maven war package plugin --> | |
158 | + <plugin> | |
159 | + <groupId>org.apache.maven.plugins</groupId> | |
160 | + <artifactId>maven-war-plugin</artifactId> | |
161 | + <version>3.3.2</version> | |
162 | + <configuration> | |
163 | + <!-- webResources: web 관련 자원들의 (html, js, css 등..) 경로 --> | |
164 | + <webResources> | |
165 | + <resource> | |
166 | + <directory>${front-end-path}</directory> | |
167 | + </resource> | |
168 | + </webResources> | |
169 | + <!-- webappDirectory: package된 후 web관련 자원들이 배포될 경로 --> | |
170 | + <!-- <webappDirectory>${build.directory}</webappDirectory>--> | |
171 | + <!-- web.xml 경로 --> | |
172 | + <webXml>client/WEB-INF/web.xml</webXml> | |
173 | + </configuration> | |
174 | + </plugin> | |
175 | + </plugins> | |
176 | + </build> | |
177 | + | |
178 | +</project> |
+++ server/main/java/common/util/bean/ApplicationContextProvider.java
... | ... | @@ -0,0 +1,43 @@ |
1 | +package common.util.bean; | |
2 | + | |
3 | +import org.springframework.beans.BeansException; | |
4 | +import org.springframework.context.ApplicationContext; | |
5 | +import org.springframework.context.ApplicationContextAware; | |
6 | + | |
7 | +/** | |
8 | + * @author 하석형 | |
9 | + * @since 2023.08.21 | |
10 | + * | |
11 | + * Spring 컨테이너(ApplicationContext)에 접근하기 위한 Class 입니다. | |
12 | + * ApplicationContextAware 구현체 | |
13 | + */ | |
14 | +public class ApplicationContextProvider implements ApplicationContextAware { | |
15 | + | |
16 | + /** | |
17 | + * 해당 어플리케이션의 인스턴스(bean)들의 정보를 담은 객체 | |
18 | + */ | |
19 | + private static ApplicationContext applicationContext; | |
20 | + | |
21 | + /** | |
22 | + * @author 하석형 | |
23 | + * @since 2023.08.21 | |
24 | + * | |
25 | + * ApplicationContextAware를 구현하기 위한 메소드 | |
26 | + * Spring 구동 시, 해당 Class가 스캔 당하면 applicationContext 객체가 생성됨 | |
27 | + */ | |
28 | + @Override | |
29 | + public void setApplicationContext(ApplicationContext ctx) throws BeansException { | |
30 | + applicationContext = ctx; | |
31 | + } | |
32 | + | |
33 | + /** | |
34 | + * @author 하석형 | |
35 | + * @since 2023.08.21 | |
36 | + * | |
37 | + * applicationContext 객체 호출 | |
38 | + */ | |
39 | + public static ApplicationContext getApplicationContext() { | |
40 | + return applicationContext; | |
41 | + } | |
42 | + | |
43 | +} |
+++ server/main/java/common/util/bean/BeanUtil.java
... | ... | @@ -0,0 +1,44 @@ |
1 | +package common.util.bean; | |
2 | + | |
3 | +import org.springframework.beans.BeansException; | |
4 | + | |
5 | +/** | |
6 | + * ApplicationContextProvider에서 bean객체를 얻어 활용할 수 있도록 해주는 Util 입니다. | |
7 | + * | |
8 | + * @author 하석형 | |
9 | + * @since 2023.08.21 | |
10 | + */ | |
11 | +public class BeanUtil { | |
12 | + | |
13 | + /** | |
14 | + * 해당 어플리케이션에서 스프링 컨테이너가 관리하는 bean으로 등록된 객체를 이름으로 호출 | |
15 | + * | |
16 | + * @author 하석형 | |
17 | + * @since 2023.08.21 | |
18 | + */ | |
19 | + public static Object getBean(String beanName) { | |
20 | + System.out.println("BeanUtil getBean(param (String) beanName : " + beanName + ")"); | |
21 | + try { | |
22 | + return ApplicationContextProvider.getApplicationContext().getBean(beanName); | |
23 | + } catch (BeansException e) { | |
24 | + e.printStackTrace(); | |
25 | + return null; | |
26 | + } | |
27 | + } | |
28 | + | |
29 | + /** | |
30 | + * 해당 어플리케이션에서 스프링 컨테이너가 관리하는 bean으로 등록된 객체를 객체의 타입으로 호출 | |
31 | + * | |
32 | + * @author 하석형 | |
33 | + * @since 2023.08.21 | |
34 | + */ | |
35 | + public static Object getBean(Class<?> classType) { | |
36 | + System.out.println("BeanUtil getBean(param (Class<?>) classType : " + classType.getName() + ")"); | |
37 | + try { | |
38 | + return ApplicationContextProvider.getApplicationContext().getBean(classType); | |
39 | + } catch (BeansException e) { | |
40 | + e.printStackTrace(); | |
41 | + return null; | |
42 | + } | |
43 | + } | |
44 | +}(파일 끝에 줄바꿈 문자 없음) |
+++ server/main/java/kr/co/takensoft/projectSettingManual/test/dao/TestDAO.java
... | ... | @@ -0,0 +1,51 @@ |
1 | +package kr.co.takensoft.projectSettingManual.test.dao; | |
2 | + | |
3 | +import org.apache.ibatis.annotations.Mapper; | |
4 | +import org.springframework.web.bind.annotation.RequestMapping; | |
5 | +import org.springframework.web.bind.annotation.RequestMethod; | |
6 | + | |
7 | +import java.util.HashMap; | |
8 | +import java.util.List; | |
9 | + | |
10 | +/** | |
11 | + * 테스트용 DAO 입니다. | |
12 | + * | |
13 | + * @author 하석형 | |
14 | + * @since 2023.08.21 | |
15 | + */ | |
16 | +//@Repository <-- Class 객체로 생성 해야 됨 | |
17 | +@Mapper | |
18 | +public interface TestDAO { | |
19 | + | |
20 | + /** | |
21 | + * todoList 데이터 조회 | |
22 | + * | |
23 | + * @author 방선주 | |
24 | + * @since 2024.01.09 | |
25 | + */ | |
26 | + public List<HashMap<String, Object>> selectTodoList (HashMap<String, Object> params) throws Exception; | |
27 | + | |
28 | + /** | |
29 | + * todoList 데이터 등록 | |
30 | + * | |
31 | + * @author 방선주 | |
32 | + * @since 2024.01.09 | |
33 | + */ | |
34 | + public int insertTodoList(HashMap<String, Object> params) throws Exception; | |
35 | + | |
36 | + /** | |
37 | + * todoList 데이터 삭제 | |
38 | + * | |
39 | + * @author 방선주 | |
40 | + * @since 2024.01.09 | |
41 | + */ | |
42 | + public int deleteTodoList(HashMap<String, Object> params) throws Exception; | |
43 | + | |
44 | + /** | |
45 | + * todoList 데이터 수정 | |
46 | + * | |
47 | + * @author 방선주 | |
48 | + * @since 2024.01.09 | |
49 | + */ | |
50 | + public int updateTodoList(HashMap<String, Object> params) throws Exception; | |
51 | +}(파일 끝에 줄바꿈 문자 없음) |
+++ server/main/java/kr/co/takensoft/projectSettingManual/test/service/TestService.java
... | ... | @@ -0,0 +1,63 @@ |
1 | +package kr.co.takensoft.projectSettingManual.test.service; | |
2 | + | |
3 | +import kr.co.takensoft.projectSettingManual.test.dao.TestDAO; | |
4 | +import org.springframework.beans.factory.annotation.Autowired; | |
5 | +import org.springframework.stereotype.Service; | |
6 | +import org.springframework.web.bind.annotation.RequestMapping; | |
7 | +import org.springframework.web.bind.annotation.RequestMethod; | |
8 | + | |
9 | +import java.util.HashMap; | |
10 | +import java.util.List; | |
11 | + | |
12 | +@Service | |
13 | +public class TestService { | |
14 | + | |
15 | + @Autowired | |
16 | + private TestDAO testDAO; | |
17 | + | |
18 | + /** | |
19 | + * todoList 데이터 조회 | |
20 | + * | |
21 | + * @author 방선주 | |
22 | + * @since 2024.01.09 | |
23 | + */ | |
24 | + public List<HashMap<String, Object>> selectTodoList (HashMap<String, Object> params) throws Exception { | |
25 | + return testDAO.selectTodoList(params); | |
26 | + } | |
27 | + | |
28 | + /** | |
29 | + * todoList 데이터 등록 | |
30 | + * | |
31 | + * @author 방선주 | |
32 | + * @since 2024.01.09 | |
33 | + */ | |
34 | + public int insertTodoList(HashMap<String, Object> params) throws Exception { | |
35 | + int result = testDAO.insertTodoList(params); | |
36 | + System.out.println("insertTodoList result: " + result); | |
37 | + return result; | |
38 | + } | |
39 | + | |
40 | + /** | |
41 | + * todoList 데이터 삭제 | |
42 | + * | |
43 | + * @author 하관우 | |
44 | + * @since 2023.08.30 | |
45 | + */ | |
46 | + public int deleteTodoList(HashMap<String, Object> params) throws Exception { | |
47 | + int result = testDAO.deleteTodoList(params); | |
48 | + System.out.println("deleteTodoList result: " + result); | |
49 | + return result; | |
50 | + } | |
51 | + | |
52 | + /** | |
53 | + * todoList 데이터 수정 | |
54 | + * | |
55 | + * @author 하관우 | |
56 | + * @since 2023.08.30 | |
57 | + */ | |
58 | + public int updateTodoList(HashMap<String, Object> params) throws Exception { | |
59 | + int result = testDAO.updateTodoList(params); | |
60 | + System.out.println("updateTodoList result: " + result); | |
61 | + return result; | |
62 | + } | |
63 | +}(파일 끝에 줄바꿈 문자 없음) |
+++ server/main/java/kr/co/takensoft/projectSettingManual/test/web/TestController.java
... | ... | @@ -0,0 +1,75 @@ |
1 | +package kr.co.takensoft.projectSettingManual.test.web; | |
2 | + | |
3 | +import kr.co.takensoft.projectSettingManual.test.service.TestService; | |
4 | +import org.springframework.beans.factory.annotation.Autowired; | |
5 | +import org.springframework.stereotype.Controller; | |
6 | +import org.springframework.web.bind.annotation.RequestBody; | |
7 | +import org.springframework.web.bind.annotation.RequestMapping; | |
8 | +import org.springframework.web.bind.annotation.RequestMethod; | |
9 | +import org.springframework.web.servlet.ModelAndView; | |
10 | + | |
11 | +import java.util.HashMap; | |
12 | + | |
13 | +@Controller | |
14 | +public class TestController { | |
15 | + | |
16 | + @Autowired | |
17 | + private TestService testService; | |
18 | + | |
19 | + /** | |
20 | + * todoList 테스트 데이터 조회 | |
21 | + * | |
22 | + * @author 방선주 | |
23 | + * @since 2024.01.09 | |
24 | + */ | |
25 | + @RequestMapping(value = "/selectTodoList.json", method = RequestMethod.POST) | |
26 | + public ModelAndView selectTodoList(@RequestBody HashMap<String, Object> params) throws Exception { | |
27 | + System.out.println("selectTodoList Controller"); | |
28 | + ModelAndView mav = new ModelAndView("jsonView"); | |
29 | + mav.addObject("result", testService.selectTodoList(params)); | |
30 | + return mav; | |
31 | + } | |
32 | + | |
33 | + /** | |
34 | + * todoList 데이터 등록 | |
35 | + * | |
36 | + * @author 방선주 | |
37 | + * @since 2024.01.09 | |
38 | + */ | |
39 | + @RequestMapping(value = "/insertTodoList.json", method = RequestMethod.POST) | |
40 | + public ModelAndView insertTodoList(@RequestBody HashMap<String, Object> params) throws Exception { | |
41 | + System.out.println("insertTodoList Controller" + params); | |
42 | + ModelAndView mav = new ModelAndView("jsonView"); | |
43 | + mav.addObject("result", testService.insertTodoList(params)); | |
44 | + return mav; | |
45 | + } | |
46 | + | |
47 | + /** | |
48 | + * todoList 데이터 삭제 | |
49 | + * | |
50 | + * @author 방선주 | |
51 | + * @since 2024.01.09 | |
52 | + */ | |
53 | + @RequestMapping(value = "/deleteTodoList.json", method = RequestMethod.POST) | |
54 | + public ModelAndView deleteTodoList(@RequestBody HashMap<String, Object> params) throws Exception { | |
55 | + System.out.println("deleteTodoList Controller" + params); | |
56 | + ModelAndView mav = new ModelAndView("jsonView"); | |
57 | + mav.addObject("result", testService.deleteTodoList(params)); | |
58 | + return mav; | |
59 | + } | |
60 | + | |
61 | + /** | |
62 | + * todoList 데이터 수정 | |
63 | + * | |
64 | + * @author 방선주 | |
65 | + * @since 2024.01.09 | |
66 | + */ | |
67 | + @RequestMapping(value = "/updateTodoList.json", method = RequestMethod.POST) | |
68 | + public ModelAndView updateTodoList(@RequestBody HashMap<String, Object> params) throws Exception { | |
69 | + System.out.println("updateTodoList Controller" + params); | |
70 | + ModelAndView mav = new ModelAndView("jsonView"); | |
71 | + mav.addObject("result", testService.updateTodoList(params)); | |
72 | + return mav; | |
73 | + } | |
74 | + | |
75 | +}(파일 끝에 줄바꿈 문자 없음) |
+++ server/main/java/spring/SpringStarter.java
... | ... | @@ -0,0 +1,53 @@ |
1 | +package spring; | |
2 | + | |
3 | +import org.springframework.web.WebApplicationInitializer; | |
4 | +import org.springframework.web.context.ContextLoaderListener; | |
5 | +import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; | |
6 | +import org.springframework.web.filter.CharacterEncodingFilter; | |
7 | +import org.springframework.web.servlet.DispatcherServlet; | |
8 | + | |
9 | +import javax.servlet.FilterRegistration; | |
10 | +import javax.servlet.ServletContext; | |
11 | +import javax.servlet.ServletException; | |
12 | +import javax.servlet.ServletRegistration; | |
13 | + | |
14 | +/** | |
15 | + * SpringFramework Context 구동 Class | |
16 | + * | |
17 | + * @author 하석형 | |
18 | + * @since 2023.08.14 | |
19 | + */ | |
20 | +public class SpringStarter implements WebApplicationInitializer { | |
21 | + | |
22 | + /** | |
23 | + * SpringFramework Context 구동 시, 동작하는 이벤트 기능 (web.xml의 기능을 대체함) | |
24 | + * | |
25 | + * @author 하석형 | |
26 | + * @since 2022.08.14 | |
27 | + */ | |
28 | + @Override | |
29 | + public void onStartup(ServletContext servletContext) throws ServletException { | |
30 | + | |
31 | + AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); | |
32 | + rootContext.register( | |
33 | + spring.config.RootContextConfig.class,//Root Context | |
34 | + spring.config.DataSourceContextConfig.class,//DataSource Context | |
35 | + spring.config.MybatisContextConfig.class//Mybatis Context | |
36 | + ); | |
37 | + servletContext.addListener(new ContextLoaderListener(rootContext)); | |
38 | + | |
39 | + // Web(Servlet) Context | |
40 | + AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); | |
41 | + dispatcherContext.register(spring.config.servlet.WebContextConfig.class); | |
42 | + | |
43 | + // Dispatcher Servlet | |
44 | + ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherContext)); | |
45 | + dispatcher.setLoadOnStartup(1); | |
46 | + dispatcher.addMapping("/"); | |
47 | + | |
48 | + // Filter | |
49 | + FilterRegistration.Dynamic filter = servletContext.addFilter("encodingFilter", CharacterEncodingFilter.class); | |
50 | + filter.setInitParameter("encoding","utf-8"); | |
51 | + filter.addMappingForServletNames(null,false,"dispatcher"); | |
52 | + } | |
53 | +}(파일 끝에 줄바꿈 문자 없음) |
+++ server/main/java/spring/config/DataSourceContextConfig.java
... | ... | @@ -0,0 +1,53 @@ |
1 | +package spring.config; | |
2 | + | |
3 | +import com.zaxxer.hikari.HikariConfig; | |
4 | +import com.zaxxer.hikari.HikariDataSource; | |
5 | +import org.springframework.context.annotation.Bean; | |
6 | +import org.springframework.context.annotation.Configuration; | |
7 | + | |
8 | +/** | |
9 | + * DB Connection 자원 관련 Bean 설정 Class | |
10 | + * DBCP: HikariCP | |
11 | + * JDBC: MariaDB or PostgreSQL | |
12 | + * | |
13 | + * @author 하석형 | |
14 | + * @since 2023.08.21 | |
15 | + */ | |
16 | +@Configuration | |
17 | +public class DataSourceContextConfig { | |
18 | + | |
19 | + /** | |
20 | + * HikariCP(DBCP) Config(설정 세팅) 객체 Bean 설정 | |
21 | + * | |
22 | + * @author 하석형 | |
23 | + * @since 2023.08.21 | |
24 | + */ | |
25 | + @Bean(name = "mainHikariConfig") | |
26 | + public HikariConfig getMainHikariConfig () { | |
27 | + HikariConfig hikariConfig = new HikariConfig(); | |
28 | + /*MariaDB*/ | |
29 | +// hikariConfig.setDriverClassName("org.mariadb.jdbc.Driver"); | |
30 | +// hikariConfig.setJdbcUrl("jdbc:mariadb://localhost:3306/test"); | |
31 | +// hikariConfig.setUsername("root"); | |
32 | +// hikariConfig.setPassword("1234"); | |
33 | + | |
34 | + /* PostgreSQL*/ | |
35 | + hikariConfig.setDriverClassName("org.postgresql.Driver"); | |
36 | + hikariConfig.setJdbcUrl("jdbc:postgresql://localhost/postgres?currentSchema=public"); | |
37 | + hikariConfig.setUsername("postgres"); | |
38 | + hikariConfig.setPassword("1234"); | |
39 | + return hikariConfig; | |
40 | + } | |
41 | + | |
42 | + /** | |
43 | + * HikariCP(DBCP) 객체 Bean 설정 | |
44 | + * | |
45 | + * @author 하석형 | |
46 | + * @since 2023.08.21 | |
47 | + */ | |
48 | + @Bean(name = "mainHikariDataSource") | |
49 | + public HikariDataSource getMainHikariDataSource () { | |
50 | + HikariDataSource hikariDataSource = new HikariDataSource(getMainHikariConfig()); | |
51 | + return hikariDataSource; | |
52 | + } | |
53 | +}(파일 끝에 줄바꿈 문자 없음) |
+++ server/main/java/spring/config/MybatisContextConfig.java
... | ... | @@ -0,0 +1,94 @@ |
1 | +package spring.config; | |
2 | + | |
3 | +import com.zaxxer.hikari.HikariDataSource; | |
4 | +import common.util.bean.BeanUtil; | |
5 | +import org.apache.ibatis.session.ExecutorType; | |
6 | +import org.apache.ibatis.session.SqlSessionFactory; | |
7 | +import org.apache.ibatis.type.TypeAliasRegistry; | |
8 | +import org.mybatis.spring.SqlSessionFactoryBean; | |
9 | +import org.mybatis.spring.SqlSessionTemplate; | |
10 | +import org.mybatis.spring.mapper.MapperScannerConfigurer; | |
11 | +import org.springframework.context.ApplicationContext; | |
12 | +import org.springframework.context.annotation.Bean; | |
13 | +import org.springframework.context.annotation.Configuration; | |
14 | + | |
15 | +/** | |
16 | + * Mybatis 관련 Bean 설정 Class | |
17 | + * | |
18 | + * @author 하석형 | |
19 | + * @since 2023.08.21 | |
20 | + */ | |
21 | +@Configuration | |
22 | +//@MapperScan(basePackages = {"kr.co.takensoft"}) <-- 이거 대신 mainMapperScannerConfigurer bean 등록 | |
23 | +public class MybatisContextConfig { | |
24 | + | |
25 | + //Mybatis 동작 설정 | |
26 | + //mybatis-config.xml 작성 대신 Class 활용 | |
27 | + private class Configuration extends org.apache.ibatis.session.Configuration { | |
28 | + private Configuration() { | |
29 | + super(); | |
30 | + super.setCacheEnabled(true);//mapper 캐시 전역 사용여부 | |
31 | + super.setLazyLoadingEnabled(false);//mybatis 지연 로딩 사용여부 | |
32 | + super.setMultipleResultSetsEnabled(true);//한개의 구문에서 여러개의 ResultSet 허용 여부 | |
33 | + super.setUseColumnLabel(true);//컬럼명 대신 컬럼라벨 사용 여부 | |
34 | + super.setUseGeneratedKeys(false);//키 자동 생성 | |
35 | + super.setDefaultExecutorType(ExecutorType.SIMPLE); | |
36 | + super.setDefaultStatementTimeout(25000); | |
37 | + super.setCallSettersOnNulls(true);//조회 조회시, null값 무조건 허용 | |
38 | + | |
39 | + //Mybatis SQL 작성시, 자주 활용하는 Class 별칭 세팅 | |
40 | + TypeAliasRegistry typeAliasRegistry = super.getTypeAliasRegistry(); | |
41 | + } | |
42 | + } | |
43 | + //Mybatis 동작 설정 객체 생성 | |
44 | + private Configuration configuration = new Configuration(); | |
45 | + | |
46 | + /** | |
47 | + * Main | |
48 | + * Mapper : SQL이 작성된 문서와, 작성된 SQL을 실행시킬 class(Mapper)를 매핑 시켜주기 위한 객체 Been 설정 (Main) | |
49 | + * | |
50 | + * @author 하석형 | |
51 | + * @since 2023.08.21 | |
52 | + */ | |
53 | + @Bean(name = "mainMapperScannerConfigurer") | |
54 | + public MapperScannerConfigurer getMainMapperScannerConfigurer () { | |
55 | + MapperScannerConfigurer mapperScannerConfigurer = null; | |
56 | + mapperScannerConfigurer = new MapperScannerConfigurer(); | |
57 | + mapperScannerConfigurer.setBasePackage("kr.co.takensoft.projectSettingManual"); | |
58 | + mapperScannerConfigurer.setAnnotationClass(org.apache.ibatis.annotations.Mapper.class);//Annotation을 지정해 줘야 service interface 를 Mapper라고 인식하지 않음 | |
59 | + mapperScannerConfigurer.setSqlSessionTemplateBeanName("mainSqlSessionTemplate"); | |
60 | + return mapperScannerConfigurer; | |
61 | + } | |
62 | + | |
63 | + /** | |
64 | + * Main | |
65 | + * Mybatis SqlSessionFactory Bean 설정 | |
66 | + * | |
67 | + * @author 하석형 | |
68 | + * @since 2023.08.21 | |
69 | + */ | |
70 | + @Bean(name = "mainSqlSessionFactory") | |
71 | + public SqlSessionFactory getMainSqlSessionFactory (ApplicationContext applicationContext) throws Exception { | |
72 | + SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); | |
73 | + sqlSessionFactoryBean.setDataSource((HikariDataSource) BeanUtil.getBean("mainHikariDataSource")); | |
74 | + sqlSessionFactoryBean.setConfiguration(this.configuration); | |
75 | + sqlSessionFactoryBean.setMapperLocations(applicationContext.getResources("classpath:mybatis/main/*-SQL.xml")); | |
76 | + return sqlSessionFactoryBean.getObject(); | |
77 | + } | |
78 | + | |
79 | + /** | |
80 | + * Main | |
81 | + * Mybatis SqlSessionTemplate Bean 설정 | |
82 | + * | |
83 | + * @author 하석형 | |
84 | + * @since 2023.08.21 | |
85 | + */ | |
86 | + @Bean(name = "mainSqlSessionTemplate") | |
87 | + public SqlSessionTemplate getMainSqlSessionTemplate (ApplicationContext applicationContext) throws Exception { | |
88 | + SqlSessionTemplate sqlSessionTemplate = new SqlSessionTemplate(getMainSqlSessionFactory(applicationContext)); | |
89 | + return sqlSessionTemplate; | |
90 | + } | |
91 | + | |
92 | + | |
93 | + | |
94 | +}(파일 끝에 줄바꿈 문자 없음) |
+++ server/main/java/spring/config/RootContextConfig.java
... | ... | @@ -0,0 +1,52 @@ |
1 | +package spring.config; | |
2 | + | |
3 | +import com.fasterxml.jackson.databind.ObjectMapper; | |
4 | +import com.fasterxml.jackson.databind.SerializationFeature; | |
5 | +import common.util.bean.ApplicationContextProvider; | |
6 | +import org.springframework.context.annotation.Bean; | |
7 | +import org.springframework.context.annotation.Configuration; | |
8 | + | |
9 | +import java.text.SimpleDateFormat; | |
10 | +import java.util.TimeZone; | |
11 | + | |
12 | +/** | |
13 | + * 현 프로젝트의 Global 자원 관련 Bean 설정 Class | |
14 | + * | |
15 | + * @author 하석형 | |
16 | + * @since 2023.08.14 | |
17 | + */ | |
18 | +@Configuration | |
19 | +public class RootContextConfig { | |
20 | + /** | |
21 | + * Spring Application Context 객체 Bean 설정 | |
22 | + * | |
23 | + * @author 하석형 | |
24 | + * @since 2023.08.24 | |
25 | + */ | |
26 | + @Bean(name = "applicationContextProvider") | |
27 | + public ApplicationContextProvider getApplicationContextProvider () { | |
28 | + ApplicationContextProvider applicationContextProvider = new ApplicationContextProvider(); | |
29 | + return applicationContextProvider; | |
30 | + } | |
31 | + | |
32 | + /** | |
33 | + * JSON Parser 라이브러리 Class Bean 설정 | |
34 | + * | |
35 | + * @author 하석형 | |
36 | + * @since 2023.08.24 | |
37 | + */ | |
38 | + @Bean(name = "objectMapper") | |
39 | + public ObjectMapper getObjectMapper() { | |
40 | + ObjectMapper mapper = new ObjectMapper(); | |
41 | + | |
42 | + //기본 날짜 포맷 비활성화 | |
43 | + mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); | |
44 | + | |
45 | + //새로운 날짜 포맷 세팅 | |
46 | + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
47 | + mapper.setDateFormat(dateFormat); | |
48 | + mapper.setTimeZone(TimeZone.getTimeZone("Asia/Seoul")); | |
49 | + | |
50 | + return mapper; | |
51 | + } | |
52 | +}(파일 끝에 줄바꿈 문자 없음) |
+++ server/main/java/spring/config/servlet/WebContextConfig.java
... | ... | @@ -0,0 +1,138 @@ |
1 | +package spring.config.servlet; | |
2 | + | |
3 | +import com.fasterxml.jackson.databind.ObjectMapper; | |
4 | +import com.fasterxml.jackson.databind.SerializationFeature; | |
5 | +import common.util.bean.ApplicationContextProvider; | |
6 | +import common.util.bean.BeanUtil; | |
7 | +import org.springframework.context.annotation.Bean; | |
8 | +import org.springframework.context.annotation.ComponentScan; | |
9 | +import org.springframework.context.annotation.Configuration; | |
10 | +import org.springframework.http.converter.HttpMessageConverter; | |
11 | +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; | |
12 | +import org.springframework.web.servlet.ViewResolver; | |
13 | +import org.springframework.web.servlet.config.annotation.EnableWebMvc; | |
14 | +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; | |
15 | +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | |
16 | +import org.springframework.web.servlet.view.BeanNameViewResolver; | |
17 | +import org.springframework.web.servlet.view.InternalResourceViewResolver; | |
18 | +import org.springframework.web.servlet.view.json.MappingJackson2JsonView; | |
19 | + | |
20 | +import java.text.SimpleDateFormat; | |
21 | +import java.util.List; | |
22 | +import java.util.TimeZone; | |
23 | + | |
24 | +/** | |
25 | + * Servlet 관련 설정 Class | |
26 | + * | |
27 | + * @author 하석형 | |
28 | + * @since 2023.08.14 | |
29 | + */ | |
30 | +@Configuration | |
31 | +@EnableWebMvc | |
32 | +@ComponentScan(basePackages = {"kr.co.takensoft"}) | |
33 | +public class WebContextConfig implements WebMvcConfigurer { | |
34 | + | |
35 | + /** | |
36 | + * 1. 특정 URL(Path)에 대한 HTTP Request 처리를 DispatcherServlet이 담당하지 않도록 만들어 주는 설정 (html, js, css, file 등..) | |
37 | + * 2. Client가 접근하지 못하는 WEB-INF 폴더안에 위치해 있는 정적 자원에 Clien가 접근할 수 있도록 만들어 주는 설정 | |
38 | + * | |
39 | + * @author 하석형 | |
40 | + * @since 2023.08.14 | |
41 | + */ | |
42 | + @Override | |
43 | + public void addResourceHandlers(ResourceHandlerRegistry registry) { | |
44 | + registry.addResourceHandler("/resources/**").addResourceLocations("/resources/"); | |
45 | + registry.addResourceHandler("/views/**").addResourceLocations("/views/"); | |
46 | + } | |
47 | + | |
48 | + /** | |
49 | + * HTTP Request Param Converter | |
50 | + * ex) JSON text => JAVA Object, text => String, Binary text => byte[] 등... 여러 데이터 타입에 대한 설정 가능 | |
51 | + * 현재 설정에서는 Spring의 기존 JSON Converter(MappingJackson2HttpMessageConverter)를 새로 덮어씌워 움 | |
52 | + * => 새로 덮어씌우는 MappingJackson2HttpMessageConverter에 프로젝트에서 설정한 ObjectMapper를 생성자로 넣어줌 | |
53 | + * @author 하석형 | |
54 | + * @since 2023.08.21 | |
55 | + */ | |
56 | + @Override | |
57 | + public void extendMessageConverters(List<HttpMessageConverter<?>> converters) { | |
58 | + converters.add(new MappingJackson2HttpMessageConverter((ObjectMapper) BeanUtil.getBean("objectMapper"))); | |
59 | + } | |
60 | + | |
61 | + /** | |
62 | + * Custom Bean Class ViewResolver를 제공해 주기 위한 Bean (파일 다운로드, JSON 등..) | |
63 | + * | |
64 | + * @author 하석형 | |
65 | + * @since 2023.08.14 | |
66 | + * @return BeanNameViewResolver | |
67 | + */ | |
68 | + @Bean(name="beanView") | |
69 | + public BeanNameViewResolver getBeanView () { | |
70 | + BeanNameViewResolver beanView = new BeanNameViewResolver(); | |
71 | + beanView.setOrder(0); | |
72 | + return beanView; | |
73 | + } | |
74 | + | |
75 | + /** | |
76 | + * JSP ViewResolver를 제공해 주기 위한 Bean | |
77 | + * | |
78 | + * @author 하석형 | |
79 | + * @since 2023.08.14 | |
80 | + * @return InternalResourceViewResolver | |
81 | + */ | |
82 | + @Bean(name="jspView") | |
83 | + public ViewResolver getJspView() { | |
84 | + InternalResourceViewResolver jspViewResolver = new InternalResourceViewResolver(); | |
85 | + jspViewResolver.setPrefix("/WEB-INF"); | |
86 | + jspViewResolver.setSuffix(".jsp"); | |
87 | + jspViewResolver.setOrder(1); | |
88 | + return jspViewResolver; | |
89 | + } | |
90 | + | |
91 | + /** | |
92 | + * JSON ViewResolver를 제공해 주기 위한 Bean | |
93 | + * | |
94 | + * @author 하석형 | |
95 | + * @since 2023.08.21 | |
96 | + * @return MappingJackson2JsonView | |
97 | + */ | |
98 | + @Bean(name="jsonView") | |
99 | + public MappingJackson2JsonView getJsonView () { | |
100 | + ObjectMapper objectMapper = (ObjectMapper) BeanUtil.getBean("objectMapper"); | |
101 | + MappingJackson2JsonView jsonView = new MappingJackson2JsonView(objectMapper); | |
102 | + jsonView.setExtractValueFromSingleKeyModel(true); | |
103 | + return jsonView; | |
104 | + } | |
105 | + | |
106 | + /** | |
107 | + * Spring Application Context 객체 Bean 설정 | |
108 | + * | |
109 | + * @author 하석형 | |
110 | + * @since 2023.08.14 | |
111 | + */ | |
112 | + @Bean(name = "applicationContextProvider") | |
113 | + public ApplicationContextProvider getApplicationContextProvider () { | |
114 | + ApplicationContextProvider applicationContextProvider = new ApplicationContextProvider(); | |
115 | + return applicationContextProvider; | |
116 | + } | |
117 | + | |
118 | + /** | |
119 | + * JSON Parser 라이브러리 Class Bean 설정 | |
120 | + * | |
121 | + * @author 하석형 | |
122 | + * @since 2023.08.21 | |
123 | + */ | |
124 | + @Bean(name = "objectMapper") | |
125 | + public ObjectMapper getObjectMapper() { | |
126 | + ObjectMapper mapper = new ObjectMapper(); | |
127 | + | |
128 | + //기본 날짜 포맷 비활성화 | |
129 | + mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); | |
130 | + | |
131 | + //새로운 날짜 포맷 세팅 | |
132 | + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
133 | + mapper.setDateFormat(dateFormat); | |
134 | + mapper.setTimeZone(TimeZone.getTimeZone("Asia/Seoul")); | |
135 | + | |
136 | + return mapper; | |
137 | + } | |
138 | +}(파일 끝에 줄바꿈 문자 없음) |
+++ server/main/resources/mybatis/main/test-SQL.xml
... | ... | @@ -0,0 +1,66 @@ |
1 | +<?xml version="1.0" encoding="UTF-8" ?> | |
2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
3 | + | |
4 | + | |
5 | +<!-- | |
6 | + 작성자 : 하석형 | |
7 | + 작성일 : 2023.08.21 | |
8 | + 내용 : Sample Mapper 입니다. | |
9 | + --> | |
10 | +<mapper namespace="kr.co.takensoft.projectSettingManual.test.dao.TestDAO"> | |
11 | + | |
12 | + <!-- | |
13 | + 작성자 : 방선주 | |
14 | + 작성일 : 2024.01.09 | |
15 | + 내용 : todoList 데이터 조회 | |
16 | + --> | |
17 | + <select id="selectTodoList" parameterType="HashMap" resultType="HashMap"> | |
18 | + SELECT | |
19 | + todo_num | |
20 | + , todo_comment | |
21 | + | |
22 | + FROM | |
23 | + todo_list | |
24 | + </select> | |
25 | + | |
26 | + <!-- | |
27 | + 작성자 : 방선주 | |
28 | + 작성일 : 2024.01.09 | |
29 | + 내용 : todoList 데이터 등록 | |
30 | + --> | |
31 | + <insert id="insertTodoList" parameterType="HashMap"> | |
32 | + INSERT INTO todo_list | |
33 | + ( | |
34 | + todo_comment | |
35 | + ) | |
36 | + VALUES | |
37 | + ( | |
38 | + #{todo_comment} | |
39 | + ) | |
40 | + </insert> | |
41 | + <!-- | |
42 | + 작성자 : 방선주 | |
43 | + 작성일 : 2024.01.09 | |
44 | + 내용 : todoList 데이터 등록 | |
45 | + --> | |
46 | + <delete id="deleteTodoList" parameterType="HashMap"> | |
47 | + DELETE | |
48 | + FROM | |
49 | + todo_list | |
50 | + WHERE | |
51 | + todo_num = #{todo_num} | |
52 | + </delete> | |
53 | + <!-- | |
54 | + 작성자 : 방선주 | |
55 | + 작성일 : 2024.01.09 | |
56 | + 내용 : todoList 데이터 수정 | |
57 | + --> | |
58 | + <update id="updateTodoList" parameterType="HashMap"> | |
59 | + UPDATE todo_list | |
60 | + SET | |
61 | + todo_comment = #{todo_comment} | |
62 | + WHERE | |
63 | + todo_num = #{todo_num} | |
64 | + </update> | |
65 | + | |
66 | +</mapper>(파일 끝에 줄바꿈 문자 없음) |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?