-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
54 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
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; | ||
|
||
|
@@ -20,75 +21,13 @@ | |
public class CodeController { | ||
|
||
@RequestMapping("/code") | ||
public String code(@RequestParam String id) { | ||
String htmlFront = "<!DOCTYPE html>\n" + | ||
"<html lang=\"en\">\n" + | ||
"<head>\n" + | ||
" <meta charset=\"UTF-8\">\n" + | ||
" <title>"; | ||
String htmlTitle ="</title>\n" + | ||
" <link href=\"css/prism.css\" rel=\"stylesheet\">\n" + | ||
" <link rel=\"stylesheet\" href=\"css/bootstrap.min.css\"/>\n" + | ||
" <link href=\"https://cdn.bootcdn.net/ajax/libs/toastr.js/latest/css/toastr.min.css\" rel=\"stylesheet\">"+ | ||
"</head>\n" + | ||
"<body>\n" + | ||
" <pre>\n" + | ||
" <code id=\"code\" class=\"language-"; | ||
String type = null; | ||
String text = null; | ||
String remark = null; | ||
String htmlLast = " </code>\n" + | ||
" </pre>\n" + | ||
"<button id=\"button\" class=\"btn btn-success\" class=\"btn btn-success\" onclick=\"copy()\" data-clipboard-target=\"#code\" data-clipboard-action=\"copy\">一键复制</button>"+ | ||
" <script src=\"js/prism.js\"></script>\n"+ | ||
"<script src=\"js/jquery-3.6.0.min.js\"></script>\n" + | ||
"<script src=\"https://cdn.jsdelivr.net/npm/[email protected]/dist/clipboard.min.js\"></script>\n"+ | ||
"<script src=\"js/code.js\"></script>\n" + | ||
"<script src=\"https://cdn.bootcdn.net/ajax/libs/toastr.js/latest/js/toastr.min.js\"></script>"; | ||
|
||
String htmlEnd = "</body>\n" + | ||
"</html>"; | ||
StringBuilder html = new StringBuilder(htmlFront); | ||
|
||
String cHtml = "<script src=\"js/prism-c.min.js\"></script>\n" + | ||
"<script src=\"js/prism-cpp.min.js\"></script>\n"; | ||
String javaHtml = "<script src=\"js/prism-java.min.js\"></script>\n"; | ||
String pythonHtml = "<script src=\"js/prism-python.min.js\"></script>\n"; | ||
|
||
|
||
CodeSQL codesql = new CodeSQL(); | ||
List<Entity> list = codesql.findCode(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", "<br>"); | ||
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); | ||
|
||
return html.toString(); | ||
public ModelAndView code(@RequestParam String id){ | ||
ModelAndView mav = new ModelAndView("/code.html?id=" + id); | ||
return mav; | ||
} | ||
|
||
|
||
@RequestMapping("/codes") | ||
public JSONObject codes(@RequestParam String id){ | ||
@RequestMapping("/selectCode") | ||
public JSONObject selectCode(@RequestParam String id){ | ||
|
||
JSONObject json = JSONUtil.createObj(); | ||
String type = null; | ||
|
@@ -102,17 +41,10 @@ public JSONObject codes(@RequestParam String id){ | |
text = (String) list.get(0).get("text"); | ||
remark = (String) list.get(0).get("remark"); | ||
|
||
// text = text.replaceAll("<", "<"); | ||
// text = text.replaceAll(">", ">"); | ||
// text = text.replaceAll("\n", "<br>"); | ||
// text = text.replaceAll(" ", " "); | ||
|
||
|
||
json.append("text", text); | ||
json.append("type", type); | ||
json.append("remark", remark); | ||
|
||
|
||
return json; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,25 +9,14 @@ | |
</head> | ||
<body> | ||
<pre> | ||
<code class="language-java" id="code"> | ||
package com.mewhz.paste; | ||
|
||
public class Main{ | ||
public static void main(String[] args) { | ||
System.out.println("Hello World"); | ||
} | ||
} | ||
<code id="code"> | ||
</code> | ||
</pre> | ||
<!-- <button id="button" class="btn btn-success" onclick="copy()" data-clipboard-target="#code" data-clipboard-action="copy">一键复制</button>--> | ||
<button id="button" class="btn btn-success" onclick="copy()" data-clipboard-target="#code" data-clipboard-action="copy">一键复制</button> | ||
<script src="js/prism.js"></script> | ||
<!-- <script src="js/prism-c.min.js"></script>--> | ||
<!-- <script src="js/prism-cpp.min.js"></script>--> | ||
<!--<script src="js/jquery-3.6.0.min.js"></script>--> | ||
<!-- <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/clipboard.min.js"></script>--> | ||
<!--<script src="js/code.js"></script>--> | ||
<!--<script src="https://cdn.bootcdn.net/ajax/libs/toastr.js/latest/js/toastr.min.js"></script>--> | ||
<script src="js/prism-java.min.js"></script> | ||
<!-- <script src="js/prism-python.min.js"></script>--> | ||
<script src="js/jquery-3.6.0.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/clipboard.min.js"></script> | ||
<script src="js/code.js"></script> | ||
<script src="https://cdn.bootcdn.net/ajax/libs/toastr.js/latest/js/toastr.min.js"></script><script src="js/prism-java.min.js"></script> | ||
</body> | ||
</html> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.