整合:Thymeleaf

This commit is contained in:
MMS 2025-05-27 23:20:46 +08:00
parent 144d3840a0
commit 242941e369
5 changed files with 48 additions and 47 deletions

View File

@ -62,16 +62,6 @@
<groupId>com.sxpcwlkj</groupId>
<artifactId>mms-ai</artifactId>
</dependency>
<dependency>
<groupId>com.sxpcwlkj</groupId>
<artifactId>mms-doc</artifactId>
<exclusions>
<exclusion>
<groupId>com.sxpcwlkj</groupId>
<artifactId>ms-framework</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>

View File

@ -91,7 +91,10 @@ spring:
suffix: .html # 模板后缀(默认值)
servlet:
content-type: text/html # 设置响应的 Content-Type默认 text/html
static-resource-url: 'https://cdn.jsdelivr.net' # 注入静态资源 CDN 前缀(需在配置文件中定义)
static:
resource:
version: '1.0.0'
cdn: 'https://cdn.jsdelivr.net' # 注入静态资源 CDN 前缀(需在配置文件中定义)
web:
# 排除路径

View File

@ -6,12 +6,13 @@
<title>智能对话助手 | AI Chat</title>
<!-- 依赖库 -->
<script th:src="@{${staticCdn}+'/npm/marked/marked.min.js'}"></script>
<link th:href="@{${staticCdn}+'/npm/prismjs@1.29.0/themes/prism-okaidia.min.css'}" rel="stylesheet">
<script th:src="@{${staticCdn}+'/npm/prismjs@1.29.0/prism.min.js'}"></script>
<script th:src="@{${staticCdn}+'/npm/prismjs@1.29.0/plugins/autoloader/prism-autoloader.min.js'}"></script>
<link th:href="@{${staticCdn}+'/ajax/libs/font-awesome/6.4.0/css/all.min.css'}" rel="stylesheet">
<link th:href="@{/css/ai.css}" rel="stylesheet">
<script th:src="@{${cdn}+'/npm/marked/marked.min.js'}"></script>
<link th:href="@{${cdn}+'/npm/prismjs@1.29.0/themes/prism-okaidia.min.css'}" rel="stylesheet">
<script th:src="@{${cdn}+'/npm/prismjs@1.29.0/prism.min.js'}"></script>
<script th:src="@{${cdn}+'/npm/prismjs@1.29.0/plugins/autoloader/prism-autoloader.min.js'}"></script>
<link th:href="@{${cdn}+'/npm/font-awesome@4.7.0/css/font-awesome.min.css'}" rel="stylesheet">
<link th:href="@{${ctx}+'/css/ai.css?v='+${version}}" rel="stylesheet">
</head>
<body>
<div class="container">

View File

@ -0,0 +1,37 @@
package com.sxpcwlkj.framework.config;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ModelAttribute;
/**
* @author shanpengnian
*/
@ControllerAdvice
@RequiredArgsConstructor
public class ThymeleafConfig {
@Value("${spring.thymeleaf.static.resource.version:/}")
private String staticResourceVersion;
@Value("${spring.thymeleaf.static.resource.cdn:/}")
private String staticResourceCdn;
// 注入上下文路径 /myapp
@ModelAttribute("ctx")
public String contextPath(HttpServletRequest request) {
return request.getContextPath();
}
@ModelAttribute("cdn")
public String staticCdn() {
return staticResourceCdn;
}
@ModelAttribute("version")
public String staticVersion() {
return staticResourceVersion;
}
}

View File

@ -1,30 +0,0 @@
package com.sxpcwlkj.framework.controller;
import jakarta.servlet.ServletContext;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ModelAttribute;
@ControllerAdvice
@RequiredArgsConstructor
public class GlobalModelAttributes {
private final ServletContext servletContext;
// 注入上下文路径 /myapp
@ModelAttribute("ctx")
public String contextPath() {
return servletContext.getContextPath();
}
// 可选注入静态资源 CDN 前缀需在配置文件中定义
@Value("${spring.thymeleaf.static-resource-url:}")
private String staticResourceUrl;
@ModelAttribute("staticCdn")
public String staticCdn() {
return staticResourceUrl;
}
}