diff --git a/src/main/java/com/mewhz/paste/controller/CodeController.java b/src/main/java/com/mewhz/paste/controller/CodeController.java index 2fdd7f3..751ccf4 100644 --- a/src/main/java/com/mewhz/paste/controller/CodeController.java +++ b/src/main/java/com/mewhz/paste/controller/CodeController.java @@ -2,57 +2,37 @@ import cn.hutool.db.Entity; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; import com.mewhz.paste.utils.CodeSQL; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.servlet.ModelAndView; import java.util.List; /** * @author mewhz */ -@Controller +@RestController public class CodeController { @RequestMapping("/code") - @ResponseBody - public String code(@RequestParam String id) { - String htmlFront = "\n" + - "\n" + - "
\n" + - " \n" + - "\n" +
- " \n" +
- ""+
- " \n"+
- "\n" +
- "\n"+
- "\n" +
- "";
-
- String htmlEnd = "\n" +
- "";
- StringBuilder html = new StringBuilder(htmlFront);
-
- String cHtml = "\n" +
- "\n";
- String javaHtml = "\n";
- String pythonHtml = "\n";
-
CodeSQL codesql = new CodeSQL();
List list = codesql.findCode(id);
@@ -60,27 +40,11 @@ public String code(@RequestParam String id) {
type = (String) list.get(0).get("type");
text = (String) list.get(0).get("text");
remark = (String) list.get(0).get("remark");
- if ("".equals(remark)){
- remark = "贴代码";
- }
-
- text = text.replaceAll("<", "<");
- text = text.replaceAll(">", ">");
- text = text.replaceAll("\n", "
");
- text = text.replaceAll(" ", " ");
- html.append(remark).append(htmlTitle).append(type).append("\">").append(text).append(htmlLast);
- if ("cpp".equals(type)){
- html.append(cHtml);
- }
- else if ("java".equals(type)){
- html.append(javaHtml);
- }
- else if ("python".equals(type)){
- html.append(pythonHtml);
- }
- html.append(htmlEnd);
+ json.append("text", text);
+ json.append("type", type);
+ json.append("remark", remark);
- return html.toString();
+ return json;
}
}
diff --git a/src/main/java/com/mewhz/paste/controller/ListController.java b/src/main/java/com/mewhz/paste/controller/ListController.java
index 3e189bc..60cfaa7 100644
--- a/src/main/java/com/mewhz/paste/controller/ListController.java
+++ b/src/main/java/com/mewhz/paste/controller/ListController.java
@@ -1,22 +1,22 @@
package com.mewhz.paste.controller;
import cn.hutool.db.Entity;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
import com.mewhz.paste.utils.CodeSQL;
import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.servlet.ModelAndView;
import java.util.List;
/**
* @author mewhz
*/
-@Controller
+@RestController
public class ListController {
- @ResponseBody
@RequestMapping(value = "/list")
public String list(@RequestParam(value = "id", required = false) String id ){
@@ -82,4 +82,36 @@ public String list(@RequestParam(value = "id", required = false) String id ){
return html.toString();
}
+
+ @RequestMapping("/lists")
+ public ModelAndView lists(@RequestParam(value = "id", required = false) String id ){
+
+ ModelAndView mav = new ModelAndView("/list.html");
+
+ return mav;
+
+ }
+
+ @RequestMapping("/selectList")
+ @CrossOrigin("http://localhost:63343")
+ public JSONObject selectList(@RequestParam(value = "id", required = false) String id){
+ JSONObject json = JSONUtil.createObj();
+ CodeSQL codeSQL = new CodeSQL();
+
+ List list = codeSQL.findIdentifyingCode(id);
+ if (list.size() == 0){
+ json.append("info", "zero");
+ return json;
+ }
+ for (Entity e : list){
+ json.append("date", e.get("date"));
+ json.append("time_id", e.get("time_id"));
+ json.append("remark", e.get("remark"));
+ json.append("type", e.get("type"));
+ json.append("text", e.get("text"));
+ }
+ System.out.println(json);
+ return json;
+ }
+
}
diff --git a/src/main/java/com/mewhz/paste/controller/LoginController.java b/src/main/java/com/mewhz/paste/controller/LoginController.java
index 6842156..66ac47e 100644
--- a/src/main/java/com/mewhz/paste/controller/LoginController.java
+++ b/src/main/java/com/mewhz/paste/controller/LoginController.java
@@ -16,6 +16,9 @@ public class LoginController {
@RequestMapping("/login")
public String login(@RequestParam String user, @RequestParam String pass){
System.out.println(user + " " + pass);
- return user + " " + pass;
+ if (!"admin".equals(user) || !"admin".equals(pass)){
+ return "ERROR";
+ }
+ return "success";
}
}
diff --git a/src/main/resources/static/code.html b/src/main/resources/static/code.html
index 36fb04a..f5e6c4c 100644
--- a/src/main/resources/static/code.html
+++ b/src/main/resources/static/code.html
@@ -9,25 +9,14 @@
- #include <iostream>
-using namespace std;
-int main() {
- int n;
- cin >> n;
- cout << n << endl;
- return 0;
-}
+
-
+
-
-
-
+
-
-
-
-
+
+