Skip to content

Commit

Permalink
🐛数据库连接更改为连接池并更换复制代码的JS
Browse files Browse the repository at this point in the history
  • Loading branch information
mewhz committed Nov 19, 2021
1 parent e7c598c commit 0595134
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/mewhz/paste/controller/CodeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ public String code(@RequestParam String id) {
String remark = null;
String htmlLast = " </code>\n" +
" </pre>\n" +
"<button id=\"button\" class=\"btn btn-success\">一键复制</button>"+
"<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>";

Expand Down
21 changes: 21 additions & 0 deletions src/main/java/com/mewhz/paste/controller/LoginController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.mewhz.paste.controller;

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;

/**
* @author mewhz
*/

@Controller
public class LoginController {

@ResponseBody
@RequestMapping("/login")
public String login(@RequestParam String user, @RequestParam String pass){
System.out.println(user + " " + pass);
return user + " " + pass;
}
}
9 changes: 8 additions & 1 deletion src/main/resources/db.setting
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
url = jdbc:mysql://127.0.0.1:3306/code_mewhz_com?useSSL=false&characterEncoding=UTF-8

user = root
pass = root
pass = root

# 初始化时建立物理连接的个数。初始化发生在显示调用init方法,或者第一次getConnection时
initialSize = 1
# 最大连接池数量
maxActive = 8
# 最小连接池数量
minIdle = 1
3 changes: 2 additions & 1 deletion src/main/resources/static/code.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
}
</code>
</pre>
<button id="button" class="btn btn-success">一键复制</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>-->
Expand Down
23 changes: 18 additions & 5 deletions src/main/resources/static/js/code.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
$(document).ready(()=>{
$("#button").click(()=>{
let text = $("#code").text();
navigator.clipboard.writeText(text);
// $(document).ready(()=>{
// $("#button").click(()=>{
// let text = $("#code").text();
// navigator.clipboard.writeText(text);
// toastr.success("复制成功,快去粘贴吧!");
// });
// });
function copy(){
let clipboard = new ClipboardJS('#button');
clipboard.on('success', function(e) {
e.clearSelection();
clipboard.destroy();
// 释放内存,如果不释放,下次总会多复制
toastr.success("复制成功,快去粘贴吧!");
});
});

clipboard.on('error', function(e) {
toastr.error("一键复制失败,请手动复制!")
});
}
14 changes: 14 additions & 0 deletions src/main/resources/static/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>登录后台</title>
</head>
<body>
<form action="/login" method="post">
<input type="text" placeholder="用户名" name="user"><br>
<input type="password" placeholder="密码" name="pass"><br>
<button>登录</button>
</form>
</body>
</html>

0 comments on commit 0595134

Please sign in to comment.