整合作业

This commit is contained in:
2026-11-03 16:21:29 +08:00
parent 28d82a5581
commit 243a87e0d2
7 changed files with 7 additions and 6 deletions
@@ -8,8 +8,8 @@ import javax.crypto.SecretKey;
import java.util.Date;
public class JwtUtil {
private static final String SECRET = "asdfg"; // 密钥
private static final SecretKey KEY = Keys.hmacShaKeyFor(SECRET.getBytes()); // 密钥对象
// private static final String SECRET = "qwertyuiopasdfghjklzxcvbnmqwerty"; // 密钥
private static final SecretKey KEY = Jwts.SIG.HS256.key().build(); // 密钥对象, 每次服务器重启就重新生成
private static final long EXPIRE_MS = 24 * 60 * 60 * 1000L; // 过期时间
// 生成JWT
@@ -85,6 +85,6 @@ public class WebAppConfig implements WebMvcConfigurer {
registry.addResourceHandler("/**")
.addResourceLocations("classpath:/static/");
registry.addResourceHandler("/upload/**")
.addResourceLocations("file:" + System.getProperty("user.dir") + File.separator + "upload" + File.separator);
.addResourceLocations("file:Z:/Spring-study/Spring-ZY-crud/upload/");
}
}
@@ -60,7 +60,7 @@ public class ProductController {
String fileName = product.getImage().replaceFirst("^/", "");
byte[] bytes;
try {
java.io.File diskFile = new java.io.File(System.getProperty("user.dir"), fileName);
java.io.File diskFile = new java.io.File("Z:/Spring-study/Spring-ZY-crud", fileName);
if (!diskFile.exists()) return ResponseEntity.notFound().build();
bytes = java.nio.file.Files.readAllBytes(diskFile.toPath());
} catch (Exception e) {
@@ -19,7 +19,7 @@ public class UploadController {
String ext = originalFilename.substring(originalFilename.lastIndexOf("."));
String fileName = UUID.randomUUID().toString().replace("-", "") + ext;
File dir = new File(System.getProperty("user.dir") + "/upload");
File dir = new File("Z:/Spring-study/Spring-ZY-crud/upload");
if (!dir.exists()) dir.mkdirs();
file.transferTo(new File(dir, fileName));
+2 -1
View File
@@ -29,7 +29,8 @@ create table demo_product
)
UPDATE demo_product SET image = 'upload/a.png' WHERE image = '/a.png';
UPDATE demo_product SET image = 'upload/a.png' WHERE image = '/a.png';
SELECT id, name, image FROM demo_product;
-- 模拟商品数据
INSERT INTO demo_product (name, p_desc, price, image)
VALUES ('iPhone 15', 'Apple最新款智能手机,A16芯片', 5999.00, '/a.png'),
Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB