睿虎的博客

输入以下命令:

1
2
3
4
5
6
7
8
9
10
11
12
pkg install pure-ftpd
#安装

pure-pw useradd laiscdata -u 1001 -g 1001 -d /data/data/com.termux
#建立用户,用户名 laiscdata ,用户uid 1001 ,用户gid 1001 ,用户根目录 /data/data/com.termux,这里回车后需要设置密码,输入两遍

pure-pw mkdb
#建立数据库,每次更改完密码都要重建一次数据库

pure-ftpd -B -E -l puredb:$PREFIX/etc/pureftpd.pdb -S 0.0.0.0,3721
#启动 -B 后台运行 -E 禁止匿名登陆 -l 配置文件位置 -S 绑定ip和端口

这样写代码:

ValidateCodeUtil.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.laisc.wisefire_read.controller;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Random;

public class ValidateCodeUtil {

private static Random random = new Random();
private int width = 165; //验证码的宽
private int height = 45; //验证码的高
private int lineSize = 30; //验证码中夹杂的干扰线数量
private int lineLength = 20; //验证码中夹杂的干扰线长度
private int randomStrNum = 4; //验证码字符个数
private int colorMin = 0; //颜色最低值
private int colorMax = 127; //颜色最高值
private String randomString = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWSYZ";
Font font = new Font("Times New Roman", Font.ROMAN_BASELINE, 40);

private Color getRandomColor() {
int r = (int)(Math.random()*(colorMax-colorMin+1)+colorMin);
int g = (int)(Math.random()*(colorMax-colorMin+1)+colorMin);
int b = (int)(Math.random()*(colorMax-colorMin+1)+colorMin);

return new Color(r, g, b);
}

private void drawLine(Graphics g) {
int x = random.nextInt(width);
int y = random.nextInt(height);
int xl = random.nextInt(lineLength);
int yl = random.nextInt(lineLength);
g.drawLine(x, y, x + xl, y + yl);

}

public BufferedImage getRandomCodeImage(){

BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
Graphics g = image.getGraphics();
g.fillRect(0, 0, width, height);
g.setColor(getRandomColor());
g.setFont(font);
// 干扰线
for (int i = 0; i < lineSize; i++) {
drawLine(g);
}
// 随机字符
String randomStr = "";
for (int i = 0; i < randomStrNum; i++) {
g.setFont(font);
g.setColor(getRandomColor());
String str = String.valueOf(randomString.charAt(random.nextInt(randomString.length())));
g.translate(random.nextInt(3), random.nextInt(6));
g.drawString(str, 40 * i + 10, 25);
}
g.dispose();
return image;
}
}

ValidateCodeController.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.laisc.wisefire_read.controller;


import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;

@Controller
@RequestMapping("/validatecode")
public class ValidateCodeController {

@RequestMapping("/showcode")
public void getRandomCodeImage(HttpServletRequest request, HttpServletResponse response){
try {

response.setContentType("image/png");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Expire", "0");
response.setHeader("Pragma", "no-cache");
ValidateCodeUtil validateCode = new ValidateCodeUtil();

BufferedImage image = validateCode.getRandomCodeImage();
ImageIO.write(image, "PNG", response.getOutputStream());

} catch (Exception e) {
e.printStackTrace();
}
}

}

可以像下面这样写:

1
2
3
4
5
6
@ResponseBody
@RequestMapping("/info/{id}/{username}")
public String info(@PathVariable("id") Integer id, @PathVariable("username") String username){

return id.toString()+" : "+username;
}

按顺序执行命令即可:

1
2
3
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

mysql -u root
1
2
3
4
5
6
7
flush privileges;

set password for 'root'@'localhost'=password('123456');

GRANT ALL PRIVILEGES ON *.* TO 'uesrname'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;#添加可以被外网访问的用户

flush privileges;

重启设备,如果打开mysql出错,提示ERROR 2002 (HY000): Can't connect to local server through socket '/data/data/com.termux/files/usr/var/run/mysqld.sock' (2),使用以下命令启动mysql:

1
nohup mysqld &

按照以下的步骤创建项目:

然后在 application.properties 文件中写入以下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
spring.thymeleaf.prefix=classpath:/templates/
server.port=8010


spring.servlet.multipart.max-file-size=100MB
spring.servlet.multipart.max-request-size=1000MB



spring.datasource.url=jdbc:mysql://127.0.0.1:3306/paper?characterEncoding=utf-8&useSSL=false
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=yourpassword



mybatis.mapper-locations=classpath:mapper/*.xml
mybatis.configuration.map-underscore-to-camel-case=true

最后创建相关目录:

0%