Browse Source

freemarker 추가

tobby48 5 years ago
parent
commit
d1af74c11b

+ 12
- 0
opensource.log.20200120 View File

@@ -0,0 +1,12 @@
1
+[13:16:04.229][ERROR][LoggingService           :   24] - 에러가 발생했어요.
2
+[13:16:04.235][ERROR][Log4jMain                :   28] - Didn't do it.
3
+[13:16:04.237][FATAL][Log4jMain                :   32] - [FATAL] 로그를 출력합니다.
4
+[13:16:04.237][ERROR][Log4jMain                :   33] - [ERROR] 로그를 출력합니다.
5
+[13:16:04.237][WARN ][Log4jMain                :   34] - [WARN] 로그를 출력합니다.
6
+[13:16:04.237][INFO ][Log4jMain                :   35] - [INFO] 로그를 출력합니다.
7
+[19:13:33.873][INFO ][SchedulerProcessor       :   31] - 돌아요.
8
+[19:13:34.002][INFO ][SchedulerProcessor       :   31] - 돌아요.
9
+[19:13:35.004][INFO ][SchedulerProcessor       :   31] - 돌아요.
10
+[19:13:36.004][INFO ][SchedulerProcessor       :   31] - 돌아요.
11
+[19:13:37.003][INFO ][SchedulerProcessor       :   31] - 돌아요.
12
+[19:13:38.006][INFO ][SchedulerProcessor       :   31] - 돌아요.

+ 6
- 0
pom.xml View File

@@ -221,6 +221,12 @@
221 221
 			<version>63.1</version>
222 222
 		</dependency>
223 223
 
224
+		<dependency>
225
+			<groupId>org.scala-lang</groupId>
226
+			<artifactId>scala-library</artifactId>
227
+			<!-- <version>2.12.7</version> -->
228
+			<version>2.11.8</version>
229
+		</dependency>
224 230
 	    <dependency>
225 231
 	        <groupId>org.bitbucket.eunjeon</groupId>
226 232
 			<artifactId>seunjeon_2.11</artifactId>

+ 1
- 1
src/main/java/kr/co/swh/lecture/opensource/sparkjava/FreeMarkerTemplateEngine.java View File

@@ -13,7 +13,7 @@ public class FreeMarkerTemplateEngine extends TemplateEngine {
13 13
 
14 14
     private Configuration configuration;
15 15
 
16
-    protected FreeMarkerTemplateEngine() {
16
+    public FreeMarkerTemplateEngine() {
17 17
         this.configuration = createFreemarkerConfiguration();
18 18
     }
19 19
 

+ 59
- 0
src/main/java/kr/co/swh/lecture/opensource/sparkjava/news/DB_newsGet.java View File

@@ -0,0 +1,59 @@
1
+package kr.co.swh.lecture.opensource.sparkjava.news;
2
+
3
+
4
+import static spark.Spark.get;
5
+import static spark.Spark.modelAndView;
6
+import static spark.Spark.port;
7
+
8
+import java.sql.Connection;
9
+import java.sql.DriverManager;
10
+import java.sql.ResultSet;
11
+import java.sql.Statement;
12
+import java.util.ArrayList;
13
+import java.util.HashMap;
14
+import java.util.Map;
15
+
16
+import com.google.gson.Gson;
17
+
18
+import kr.co.swh.lecture.opensource.sparkjava.FreeMarkerTemplateEngine;
19
+
20
+
21
+public class DB_newsGet {
22
+	
23
+	static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
24
+	static final String DB_URL = "jdbc:mysql://dev-swh.ga:3306/IyHyeon";
25
+	
26
+	static final String USERNAME = "root";
27
+	static final String PASSWORD = "swhacademy!";
28
+	
29
+	static Statement stmt;
30
+	static ResultSet res;
31
+	static Connection conn = null;
32
+
33
+	public static void main(String[] args) {
34
+		port(45678);
35
+		ArrayList<Object> jArr = new ArrayList<Object>();
36
+		Map<String, Object> attributes = new HashMap<>();
37
+		
38
+		get("/news/:0or1/:column/:row", (request, response) -> {
39
+			String acc = request.params("0or1");
40
+			String column = request.params("column");
41
+			String row = request.params("row");
42
+			Class.forName(JDBC_DRIVER);
43
+			conn = DriverManager.getConnection(DB_URL, USERNAME, PASSWORD);
44
+			stmt = conn.createStatement();
45
+			String acQuery = "select * from NEWS where " + column + " = " + "'" +  row + "'";
46
+			String inacQuery = "select * from NEWS where " + column + " like " + "'%" +  row + "%'";
47
+			if(acc.equals("1")) res = stmt.executeQuery(acQuery);
48
+			else res = stmt.executeQuery(inacQuery);
49
+			while (res.next()) {
50
+				Input i = new Input(res.getString("category"), res.getString("id"), res.getString("date"), res.getString("title"), res.getString("script"));
51
+				String academy2Json = new Gson().toJson(i);		
52
+				jArr.add(i);		// json문자열로 넣지 말고, 객체형태로 추가
53
+			}
54
+			attributes.put("message", jArr);
55
+			return modelAndView(attributes, "news.ftl");
56
+		}, new FreeMarkerTemplateEngine());
57
+		
58
+	}
59
+}

+ 47
- 0
src/main/java/kr/co/swh/lecture/opensource/sparkjava/news/Input.java View File

@@ -0,0 +1,47 @@
1
+package kr.co.swh.lecture.opensource.sparkjava.news;
2
+
3
+public class Input {
4
+	private String category;
5
+	private String id;
6
+	private String date;
7
+	private String title;
8
+	private String script;
9
+	
10
+	public Input(String category, String id, String date, String title, String script) {
11
+		this.category = category;
12
+		this.id = id;
13
+		this.date = date;
14
+		this.title = title;
15
+		this.script = script;
16
+	}
17
+	public String getCategory() {
18
+		return category;
19
+	}
20
+	public void setCategory(String category) {
21
+		this.category = category;
22
+	}
23
+	public String getId() {
24
+		return id;
25
+	}
26
+	public void setId(String id) {
27
+		this.id = id;
28
+	}
29
+	public String getDate() {
30
+		return date;
31
+	}
32
+	public void setDate(String date) {
33
+		this.date = date;
34
+	}
35
+	public String getTitle() {
36
+		return title;
37
+	}
38
+	public void setTitle(String title) {
39
+		this.title = title;
40
+	}
41
+	public String getScript() {
42
+		return script;
43
+	}
44
+	public void setScript(String script) {
45
+		this.script = script;
46
+	}
47
+}

+ 24
- 0
src/main/resources/freemarker/news.ftl View File

@@ -0,0 +1,24 @@
1
+<html>
2
+<body>
3
+
4
+<table style="width:100%">
5
+  <tr>
6
+    <th>id</th>
7
+    <th>category</th> 
8
+    <th>date</th>
9
+    <th>title</th>
10
+    <th>script</th>
11
+ </tr>
12
+ 
13
+ <#list message as i>
14
+     <tr>
15
+	   <td>${i.id}</td>
16
+	   <td>${i.category}</td>
17
+	   <td>${i.title}</td>
18
+	   <td>${i.date}</td>
19
+	   <td>${i.script}</td>
20
+	 </tr>
21
+ </#list>
22
+
23
+</body>
24
+</html>