feat: thymeleaf的使用
This commit is contained in:
parent
4df0d12992
commit
e808411049
|
@ -1,4 +1,8 @@
|
||||||
# SpringMVC笔记
|
# `SpringMVC`笔记
|
||||||
|
|
||||||
|
- 公共AI网站:https://chatgptplus.cn/
|
||||||
|
- vue3官网:https://cn.vuejs.org/
|
||||||
|
- SpringBoot官网:https://docs.spring.io/spring-boot/index.html
|
||||||
|
|
||||||
## 访问控制
|
## 访问控制
|
||||||
|
|
||||||
|
@ -93,6 +97,17 @@ public List<String> getJson() {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### 将视图和模型拆开
|
||||||
|
|
||||||
|
```java
|
||||||
|
// 将视图和模型拆开
|
||||||
|
@GetMapping("page/test3")
|
||||||
|
public String test3(Model model) {
|
||||||
|
model.addAttribute("test3", "测试3");
|
||||||
|
return "page/test3";
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### 使用`@RestController`
|
### 使用`@RestController`
|
||||||
|
|
||||||
#### 使用方式1
|
#### 使用方式1
|
||||||
|
@ -144,3 +159,275 @@ public ModelAndView test2(ModelAndView modelAndView) {
|
||||||
return modelAndView;
|
return modelAndView;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Thymeleaf快速入门
|
||||||
|
|
||||||
|
Thymeleaf 是一种现代化的 Java 模板引擎,广泛用于生成 HTML、XML、JavaScript 等内容。它有许多内置的指令和功能,用于渲染动态内容、条件渲染、循环、处理表达式等。以下是 Thymeleaf 中常见的指令和属性的详细介绍:
|
||||||
|
|
||||||
|
### 1. **`th:text`**
|
||||||
|
|
||||||
|
用于替换元素的文本内容。
|
||||||
|
|
||||||
|
```html
|
||||||
|
<span th:text="${message}"></span>
|
||||||
|
```
|
||||||
|
|
||||||
|
- `${message}` 的值会替换 `span` 元素的文本。
|
||||||
|
|
||||||
|
> 如果需要格式化日期,需要注意,使用`temporals`进行操作
|
||||||
|
>
|
||||||
|
> ```html
|
||||||
|
> <td class="text-success" th:text="${#temporals.format(bill.transactionDate,'yyyy-MM-dd HH:mm:ss')}"></td>
|
||||||
|
> ```
|
||||||
|
|
||||||
|
### 2. **`th:utext`**
|
||||||
|
|
||||||
|
用于替换元素的文本内容,并允许处理 HTML 标签(不会转义 HTML)。
|
||||||
|
|
||||||
|
```html
|
||||||
|
<span th:utext="${htmlContent}"></span>
|
||||||
|
```
|
||||||
|
|
||||||
|
- `${htmlContent}` 的内容直接插入,并解析其中的 HTML。
|
||||||
|
|
||||||
|
### 3. **`th:value`**
|
||||||
|
|
||||||
|
设置表单元素的 `value` 属性,通常用于输入框或选择框。
|
||||||
|
|
||||||
|
```html
|
||||||
|
<input type="text" th:value="${user.name}" />
|
||||||
|
```
|
||||||
|
|
||||||
|
- 将 `${user.name}` 的值赋给该输入框的 `value` 属性。
|
||||||
|
|
||||||
|
### 4. **`th:each`**
|
||||||
|
|
||||||
|
用于循环遍历集合或数组。
|
||||||
|
|
||||||
|
```html
|
||||||
|
<ul>
|
||||||
|
<li th:each="person : ${people}">
|
||||||
|
<span th:text="${person.name}"></span>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
```
|
||||||
|
|
||||||
|
- 遍历 `people` 集合,输出每个 `person.name`。
|
||||||
|
|
||||||
|
### 5. **`th:if`**
|
||||||
|
|
||||||
|
用于条件渲染,只有满足条件时才渲染元素。
|
||||||
|
|
||||||
|
```html
|
||||||
|
<div th:if="${user.isAdmin}">
|
||||||
|
<p>Welcome, admin!</p>
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
- 如果 `user.isAdmin` 为 `true`,渲染该 `div`。
|
||||||
|
|
||||||
|
### 6. **`th:unless`**
|
||||||
|
|
||||||
|
与 `th:if` 相反,只有条件为 `false` 时才渲染元素。
|
||||||
|
|
||||||
|
```html
|
||||||
|
<div th:unless="${user.isAdmin}">
|
||||||
|
<p>You are not an admin!</p>
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
- 如果 `user.isAdmin` 为 `false`,渲染该 `div`。
|
||||||
|
|
||||||
|
### 7. **`th:attr`**
|
||||||
|
|
||||||
|
用于设置元素的多个属性。
|
||||||
|
|
||||||
|
```html
|
||||||
|
<img th:attr="src=${imageUrl}" th:attr="alt=${imageDescription}" />
|
||||||
|
```
|
||||||
|
|
||||||
|
- 设置 `img` 元素的 `src` 和 `alt` 属性。
|
||||||
|
|
||||||
|
### 8. **`th:src` / `th:href`**
|
||||||
|
|
||||||
|
用于动态设置 `src` 或 `href` 属性。
|
||||||
|
|
||||||
|
```html
|
||||||
|
<img th:src="@{${imageUrl}}" alt="Image">
|
||||||
|
<a th:href="@{${linkUrl}}">Click Here</a>
|
||||||
|
```
|
||||||
|
|
||||||
|
- `th:src` 用于设置图片的 `src` 属性,`th:href` 用于设置链接的 `href` 属性。
|
||||||
|
|
||||||
|
### 9. **`th:class`**
|
||||||
|
|
||||||
|
动态设置 `class` 属性,支持条件表达式。
|
||||||
|
|
||||||
|
```html
|
||||||
|
<div th:class="${isActive} ? 'active' : 'inactive'">...</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
- 如果 `isActive` 为 `true`,设置 `class="active"`,否则为 `inactive`。
|
||||||
|
|
||||||
|
### 10. **`th:classappend` / `th:classprepend`**
|
||||||
|
|
||||||
|
分别在现有的 `class` 属性上追加或前置新类。
|
||||||
|
|
||||||
|
```html
|
||||||
|
<div th:classappend="'newClass'">...</div>
|
||||||
|
<div th:classprepend="'prefixClass'">...</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
- `th:classappend` 会将新的类追加到现有类的后面。
|
||||||
|
- `th:classprepend` 会将新的类添加到现有类的前面。
|
||||||
|
|
||||||
|
### 11. **`th:id`**
|
||||||
|
|
||||||
|
设置元素的 `id` 属性。
|
||||||
|
|
||||||
|
```html
|
||||||
|
<input type="text" th:id="${elementId}" />
|
||||||
|
```
|
||||||
|
|
||||||
|
- 设置 `input` 元素的 `id` 为 `${elementId}` 的值。
|
||||||
|
|
||||||
|
### 12. **`th:action`**
|
||||||
|
|
||||||
|
设置表单的 `action` 属性。
|
||||||
|
|
||||||
|
```html
|
||||||
|
<form th:action="@{/submitForm}" method="post">
|
||||||
|
<!-- form fields -->
|
||||||
|
</form>
|
||||||
|
```
|
||||||
|
|
||||||
|
- 设置表单的 `action` 为 `/submitForm`。
|
||||||
|
|
||||||
|
### 13. **`th:style`**
|
||||||
|
|
||||||
|
设置元素的 `style` 属性。
|
||||||
|
|
||||||
|
```html
|
||||||
|
<div th:style="'color: ' + ${color}"></div>
|
||||||
|
```
|
||||||
|
|
||||||
|
- 动态设置 `style` 属性,`${color}` 的值会成为 `color` 样式的值。
|
||||||
|
|
||||||
|
### 14. **`th:fragment`**
|
||||||
|
|
||||||
|
定义一个可重用的片段,通常在模板中调用。
|
||||||
|
|
||||||
|
```html
|
||||||
|
<div th:fragment="userFragment">
|
||||||
|
<p>Welcome, <span th:text="${user.name}"></span></p>
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
- 定义一个 `userFragment` 片段,可以在其他模板中引用。
|
||||||
|
|
||||||
|
### 15. **`th:replace`**
|
||||||
|
|
||||||
|
替换当前元素,并将一个片段或其他模板插入其中。
|
||||||
|
|
||||||
|
```html
|
||||||
|
<div th:replace="~{userFragment}"></div>
|
||||||
|
```
|
||||||
|
|
||||||
|
- `th:replace` 会将 `userFragment` 片段的内容插入到当前 `div` 中。
|
||||||
|
|
||||||
|
### 16. **`th:include`**
|
||||||
|
|
||||||
|
将另一个模板的内容插入当前模板中,但不会替换当前元素。
|
||||||
|
|
||||||
|
```html
|
||||||
|
<div th:include="~{userFragment}"></div>
|
||||||
|
```
|
||||||
|
|
||||||
|
- 插入 `userFragment` 的内容,但保留当前 `div` 元素。
|
||||||
|
|
||||||
|
### 17. **`th:with`**
|
||||||
|
|
||||||
|
局部变量声明,用于在模板中定义临时变量。
|
||||||
|
|
||||||
|
```html
|
||||||
|
<div th:with="total=${cart.totalPrice}">
|
||||||
|
<p th:text="'Total price: ' + ${total}"></p>
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
- `th:with` 用于在当前元素的上下文中定义变量,类似于局部变量。
|
||||||
|
|
||||||
|
### 18. **`th:block`**
|
||||||
|
|
||||||
|
在模板中定义一个不会渲染任何 HTML 标签的块元素。用于组合多个元素。
|
||||||
|
|
||||||
|
```html
|
||||||
|
<th:block th:each="person : ${people}">
|
||||||
|
<p th:text="${person.name}"></p>
|
||||||
|
</th:block>
|
||||||
|
```
|
||||||
|
|
||||||
|
- `th:block` 不会渲染任何标签,但可以用来包装多个元素进行条件判断或循环。
|
||||||
|
|
||||||
|
### 19. **`th:switch` / `th:case`**
|
||||||
|
|
||||||
|
类似于 Java 中的 `switch` 语句,用于条件选择。
|
||||||
|
|
||||||
|
```html
|
||||||
|
<div th:switch="${status}">
|
||||||
|
<span th:case="'active'">Active</span>
|
||||||
|
<span th:case="'inactive'">Inactive</span>
|
||||||
|
<span th:case="*">Unknown</span>
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
- 根据 `${status}` 的值,渲染对应的 `span` 元素。
|
||||||
|
|
||||||
|
### 20. **`th:object`**
|
||||||
|
|
||||||
|
用来为表单元素绑定一个对象。
|
||||||
|
|
||||||
|
```html
|
||||||
|
<form th:action="@{/submit}" th:object="${user}">
|
||||||
|
<input type="text" th:field="*{name}" />
|
||||||
|
<input type="text" th:field="*{email}" />
|
||||||
|
<button type="submit">Submit</button>
|
||||||
|
</form>
|
||||||
|
```
|
||||||
|
|
||||||
|
- `th:object` 绑定整个表单到 `user` 对象。
|
||||||
|
- `th:field` 用于绑定每个表单字段到对象的属性。
|
||||||
|
|
||||||
|
### 21. **`th:href` / `th:src`**
|
||||||
|
|
||||||
|
用于动态设置 URL 值。
|
||||||
|
|
||||||
|
```html
|
||||||
|
<a th:href="@{/users/{id}(id=${user.id})}">Profile</a>
|
||||||
|
<img th:src="@{/images/{imageName}(imageName=${image.name})}" />
|
||||||
|
```
|
||||||
|
|
||||||
|
- 动态生成 URL,支持路径变量的替换。
|
||||||
|
|
||||||
|
### 22. **`th:placeholder`**
|
||||||
|
|
||||||
|
设置表单输入框的 `placeholder` 属性。
|
||||||
|
|
||||||
|
```html
|
||||||
|
<input type="text" th:placeholder="${placeholderText}" />
|
||||||
|
```
|
||||||
|
|
||||||
|
- 设置 `input` 的 `placeholder` 为 `${placeholderText}` 的值。
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
### 总结
|
||||||
|
|
||||||
|
Thymeleaf 提供了许多强大的指令来处理模板中的动态内容、条件渲染、迭代和属性绑定。常见的指令包括:
|
||||||
|
|
||||||
|
- `th:text`、`th:utext`:用于设置文本内容。
|
||||||
|
- `th:each`:用于循环遍历。
|
||||||
|
- `th:if`、`th:unless`:用于条件判断。
|
||||||
|
- `th:attr`、`th:id`、`th:class`:用于设置 HTML 属性。
|
||||||
|
- `th:replace`、`th:include`:用于片段包含。
|
||||||
|
- `th:switch`、`th:case`:用于类似 `switch` 的条件语句。
|
37
mvc/pom.xml
37
mvc/pom.xml
|
@ -13,22 +13,14 @@
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<name>mvc</name>
|
<name>mvc</name>
|
||||||
<description>mvc</description>
|
<description>mvc</description>
|
||||||
<url/>
|
|
||||||
<licenses>
|
|
||||||
<license/>
|
|
||||||
</licenses>
|
|
||||||
<developers>
|
|
||||||
<developer/>
|
|
||||||
</developers>
|
|
||||||
<scm>
|
|
||||||
<connection/>
|
|
||||||
<developerConnection/>
|
|
||||||
<tag/>
|
|
||||||
<url/>
|
|
||||||
</scm>
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>17</java.version>
|
<java.version>17</java.version>
|
||||||
|
<mybatis-plus.version>3.5.6</mybatis-plus.version>
|
||||||
|
<mysql.version>8.0.30</mysql.version>
|
||||||
|
<HikariCP.version>5.1.0</HikariCP.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
@ -51,6 +43,7 @@
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- lombok -->
|
<!-- lombok -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
|
@ -63,6 +56,24 @@
|
||||||
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
|
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
|
||||||
<version>4.5.0</version>
|
<version>4.5.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- mybatis-plus -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
|
||||||
|
<version>${mybatis-plus.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- mysql -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>${mysql.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- mysql连接池 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.zaxxer</groupId>
|
||||||
|
<artifactId>HikariCP</artifactId>
|
||||||
|
<version>${HikariCP.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
package cn.bunny.mvc.configuration;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.DbType;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mybatis-Plus配置类
|
||||||
|
*/
|
||||||
|
@EnableTransactionManagement
|
||||||
|
@Configuration
|
||||||
|
@Slf4j
|
||||||
|
public class MybatisPlusConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||||
|
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||||
|
// 分页插件
|
||||||
|
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
|
||||||
|
// 设置最大分页为 600
|
||||||
|
paginationInnerInterceptor.setMaxLimit(600L);
|
||||||
|
interceptor.addInnerInterceptor(paginationInnerInterceptor);
|
||||||
|
// 乐观锁
|
||||||
|
interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
|
||||||
|
// 防止全表删除
|
||||||
|
interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
|
||||||
|
|
||||||
|
return interceptor;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package cn.bunny.mvc.controller;
|
||||||
|
|
||||||
|
import cn.bunny.mvc.dao.entity.Bill;
|
||||||
|
import cn.bunny.mvc.service.ThymeleafService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RequestMapping("thymeleaf")
|
||||||
|
@Controller
|
||||||
|
public class ThymeleafController {
|
||||||
|
|
||||||
|
private final ThymeleafService thymeleafService;
|
||||||
|
|
||||||
|
public ThymeleafController(ThymeleafService thymeleafService) {
|
||||||
|
this.thymeleafService = thymeleafService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "查看账单信息")
|
||||||
|
@GetMapping("bill")
|
||||||
|
public String bill(Model model) {
|
||||||
|
List<Bill> billList = thymeleafService.bill();
|
||||||
|
model.addAttribute("billList", billList);
|
||||||
|
|
||||||
|
return "thymeleaf/bill";
|
||||||
|
}
|
||||||
|
}
|
|
@ -51,6 +51,6 @@ public class UseController {
|
||||||
@GetMapping("test3")
|
@GetMapping("test3")
|
||||||
public String test3(Model model) {
|
public String test3(Model model) {
|
||||||
model.addAttribute("test3", "测试3");
|
model.addAttribute("test3", "测试3");
|
||||||
return "page/test3";
|
return "test/test3";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ public class UseRestController {
|
||||||
@GetMapping("page/test")
|
@GetMapping("page/test")
|
||||||
public ModelAndView test() {
|
public ModelAndView test() {
|
||||||
ModelAndView modelAndView = new ModelAndView();
|
ModelAndView modelAndView = new ModelAndView();
|
||||||
modelAndView.setViewName("page/test");
|
modelAndView.setViewName("test/test");
|
||||||
modelAndView.addObject("message", "这是消息内容");
|
modelAndView.addObject("message", "这是消息内容");
|
||||||
return modelAndView;
|
return modelAndView;
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ public class UseRestController {
|
||||||
@GetMapping("page/test2")
|
@GetMapping("page/test2")
|
||||||
public ModelAndView test2(ModelAndView modelAndView) {
|
public ModelAndView test2(ModelAndView modelAndView) {
|
||||||
modelAndView.addObject("hello", "你好");
|
modelAndView.addObject("hello", "你好");
|
||||||
modelAndView.setViewName("page/test2");
|
modelAndView.setViewName("test/test2");
|
||||||
return modelAndView;
|
return modelAndView;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
package cn.bunny.mvc.dao;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Schema(name = "BaseEntity", title = "基础信息字段", description = "基础信息字段")
|
||||||
|
public class BaseEntity implements Serializable {
|
||||||
|
|
||||||
|
@Schema(name = "id", title = "唯一标识")
|
||||||
|
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||||
|
@JsonFormat(shape = JsonFormat.Shape.STRING)
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(name = "createTime", title = "创建时间")
|
||||||
|
@TableField(fill = FieldFill.INSERT)
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
@Schema(name = "updateTime", title = "更新时间")
|
||||||
|
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
|
||||||
|
@Schema(name = "createUser", title = "创建用户")
|
||||||
|
@TableField(fill = FieldFill.INSERT)
|
||||||
|
@JsonFormat(shape = JsonFormat.Shape.STRING)
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
private Long createUser;
|
||||||
|
|
||||||
|
@Schema(name = "updateUser", title = "操作用户")
|
||||||
|
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||||
|
@JsonFormat(shape = JsonFormat.Shape.STRING)
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
private Long updateUser;
|
||||||
|
|
||||||
|
@Schema(name = "isDeleted", title = "是否被删除")
|
||||||
|
@TableLogic
|
||||||
|
private Boolean isDeleted;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package cn.bunny.mvc.dao;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
@Schema(name = "BaseUserEntity", title = "基础信息字段包含用户信息", description = "基础信息字段包含用户信息")
|
||||||
|
public class BaseUserEntity extends BaseEntity {
|
||||||
|
|
||||||
|
@Schema(name = "username", title = "用户名")
|
||||||
|
private String createUsername;
|
||||||
|
|
||||||
|
@Schema(name = "nickname", title = "昵称")
|
||||||
|
private String updateUsername;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
package cn.bunny.mvc.dao.entity;
|
||||||
|
|
||||||
|
import cn.bunny.mvc.dao.BaseEntity;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 账单信息
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Bunny
|
||||||
|
* @since 2024-11-07
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@TableName("t_bill")
|
||||||
|
@Schema(name = "Bill对象", title = "账单信息", description = "账单信息")
|
||||||
|
public class Bill extends BaseEntity {
|
||||||
|
|
||||||
|
@Schema(name = "username", title = "类型:1 - 收入,-1 - 支出")
|
||||||
|
private Byte type;
|
||||||
|
|
||||||
|
@Schema(name = "userId", title = "绑定的用户id")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
@Schema(name = "amount", title = "金额")
|
||||||
|
private BigDecimal amount;
|
||||||
|
|
||||||
|
@Schema(name = "description", title = "描述")
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@Schema(name = "transactionDate", title = "交易日期")
|
||||||
|
private LocalDateTime transactionDate;
|
||||||
|
|
||||||
|
@Schema(name = "categoryId", title = "类别id")
|
||||||
|
private Long categoryId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
package cn.bunny.mvc.dao.entity;
|
||||||
|
|
||||||
|
import cn.bunny.mvc.dao.BaseEntity;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 预算分类表
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Bunny
|
||||||
|
* @since 2024-11-11
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@TableName("t_budget_category")
|
||||||
|
@Schema(name = "BudgetCategory对象", title = "预算分类表", description = "预算分类表")
|
||||||
|
public class BudgetCategory extends BaseEntity {
|
||||||
|
|
||||||
|
@Schema(name = "parentId", title = "父级id")
|
||||||
|
private Long parentId;
|
||||||
|
|
||||||
|
@Schema(name = "userId", title = "绑定的用户id")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
@Schema(name = "categoryName", title = "分类名称")
|
||||||
|
private String categoryName;
|
||||||
|
|
||||||
|
@Schema(name = "budgetName", title = "预算名称")
|
||||||
|
private String budgetName;
|
||||||
|
|
||||||
|
@Schema(name = "statusType", title = "完成状态")
|
||||||
|
private String statusType;
|
||||||
|
|
||||||
|
@Schema(name = "amount", title = "预算金额")
|
||||||
|
private BigDecimal amount;
|
||||||
|
|
||||||
|
@Schema(name = "useAmount", title = "已使用预算金额")
|
||||||
|
private BigDecimal useAmount;
|
||||||
|
|
||||||
|
@Schema(name = "period", title = "预算周期")
|
||||||
|
private LocalDateTime startPeriod;
|
||||||
|
|
||||||
|
@Schema(name = "period", title = "预算周期")
|
||||||
|
private LocalDateTime endPeriod;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package cn.bunny.mvc.dao.entity;
|
||||||
|
|
||||||
|
import cn.bunny.mvc.dao.BaseEntity;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 分类信息
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Bunny
|
||||||
|
* @since 2024-11-08
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@TableName("t_category")
|
||||||
|
@Schema(name = "Category对象", title = "分类信息", description = "分类信息")
|
||||||
|
public class Category extends BaseEntity {
|
||||||
|
|
||||||
|
@Schema(name = "userId", title = "绑定的用户id")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
@Schema(name = "categoryName", title = "分类名称")
|
||||||
|
private String categoryName;
|
||||||
|
|
||||||
|
@Schema(name = "isBuiltin", title = "是否内置字段")
|
||||||
|
private Boolean isBuiltin;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
package cn.bunny.mvc.dao.entity;
|
||||||
|
|
||||||
|
import cn.bunny.mvc.dao.BaseEntity;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 债务还款计划表
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Bunny
|
||||||
|
* @since 2024-11-11
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@TableName("t_debt_repayment_plan")
|
||||||
|
@Schema(name = "DebtRepaymentPlan对象", title = "债务还款计划表", description = "债务还款计划表")
|
||||||
|
public class DebtRepaymentPlan extends BaseEntity {
|
||||||
|
|
||||||
|
@Schema(name = "userId", title = "绑定的用户id")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
@Schema(name = "installmentNumber", title = "债务金额")
|
||||||
|
private BigDecimal installmentNumber;
|
||||||
|
|
||||||
|
@Schema(name = "installmentAmount", title = "每期应还金额")
|
||||||
|
private BigDecimal installmentAmount;
|
||||||
|
|
||||||
|
@Schema(name = "dueDate", title = "还款截止日期")
|
||||||
|
private LocalDateTime dueDate;
|
||||||
|
|
||||||
|
@Schema(name = "paidAmount", title = "已还金额")
|
||||||
|
private BigDecimal paidAmount;
|
||||||
|
|
||||||
|
@Schema(name = "paymentStatus", title = "还款状态")
|
||||||
|
private String paymentStatus;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
package cn.bunny.mvc.dao.entity;
|
||||||
|
|
||||||
|
import cn.bunny.mvc.dao.BaseEntity;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 债务追踪表
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Bunny
|
||||||
|
* @since 2024-11-11
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@TableName("t_debt_tracking")
|
||||||
|
@Schema(name = "DebtTracking对象", title = "债务追踪", description = "债务追踪")
|
||||||
|
public class DebtTracking extends BaseEntity {
|
||||||
|
|
||||||
|
@Schema(name = "userId", title = "绑定的用户")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
@Schema(name = "debtorName", title = "债务人姓名")
|
||||||
|
private String debtorName;
|
||||||
|
|
||||||
|
@Schema(name = "debtAmount", title = "债务金额")
|
||||||
|
private BigDecimal debtAmount;
|
||||||
|
|
||||||
|
@Schema(name = "debtType", title = "债务类型")
|
||||||
|
private String debtType;
|
||||||
|
|
||||||
|
@Schema(name = "debtStatus", title = "债务状态")
|
||||||
|
private String debtStatus;
|
||||||
|
|
||||||
|
@Schema(name = "dueDate", title = "还款截止日期")
|
||||||
|
private LocalDateTime dueDate;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
package cn.bunny.mvc.dao.entity;
|
||||||
|
|
||||||
|
import cn.bunny.mvc.dao.BaseEntity;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 用户储值
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Bunny
|
||||||
|
* @since 2024-11-11
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@TableName("t_saving_goal")
|
||||||
|
@Schema(name = "SavingGoal对象", title = "用户储值", description = "用户储值")
|
||||||
|
public class SavingGoal extends BaseEntity {
|
||||||
|
|
||||||
|
@Schema(name = "userId", title = "绑定的用户id")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
@Schema(name = "statusType", title = "完成状态")
|
||||||
|
private String statusType;
|
||||||
|
|
||||||
|
@Schema(name = "savingGoalName", title = "储值目标名称")
|
||||||
|
private String savingGoalName;
|
||||||
|
|
||||||
|
@Schema(name = "amount", title = "目标金额")
|
||||||
|
private BigDecimal amount;
|
||||||
|
|
||||||
|
@Schema(name = "amountDeposited", title = "已存入金额")
|
||||||
|
private BigDecimal amountDeposited;
|
||||||
|
|
||||||
|
@Schema(name = "startDuration", title = "开始目标时长")
|
||||||
|
private LocalDateTime startDuration;
|
||||||
|
|
||||||
|
@Schema(name = "endDuration", title = "结束目标时长")
|
||||||
|
private LocalDateTime endDuration;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package cn.bunny.mvc.mapper;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.bunny.mvc.dao.entity.Bill;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface BillMapper extends BaseMapper<Bill> {
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package cn.bunny.mvc.service;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.bunny.mvc.dao.entity.Bill;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface ThymeleafService extends IService<Bill> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查看账单信息
|
||||||
|
*
|
||||||
|
* @return 账单列表
|
||||||
|
*/
|
||||||
|
List<Bill> bill();
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package cn.bunny.mvc.service.impl;
|
||||||
|
|
||||||
|
import cn.bunny.mvc.dao.entity.Bill;
|
||||||
|
import cn.bunny.mvc.mapper.BillMapper;
|
||||||
|
import cn.bunny.mvc.service.ThymeleafService;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ThymeleafServiceImpl extends ServiceImpl<BillMapper, Bill> implements ThymeleafService {
|
||||||
|
/**
|
||||||
|
* 查看账单信息
|
||||||
|
*
|
||||||
|
* @return 账单列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Bill> bill() {
|
||||||
|
IPage<Bill> billIPage = new Page<>(1, 30);
|
||||||
|
return list(billIPage);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
server:
|
||||||
|
port: 8080
|
||||||
|
logging:
|
||||||
|
level:
|
||||||
|
cn.bunny.service.mapper: info
|
||||||
|
cn.bunny.service.controller: info
|
||||||
|
cn.bunny.service.service: info
|
||||||
|
root: info
|
||||||
|
pattern:
|
||||||
|
dateformat: HH:mm:ss:SSS
|
||||||
|
file:
|
||||||
|
path: "logs/${spring.application.name}"
|
||||||
|
|
||||||
|
#mybatis-plus:
|
||||||
|
# configuration:
|
||||||
|
# map-underscore-to-camel-case: true
|
||||||
|
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 查看日志
|
||||||
|
|
||||||
|
bunny:
|
||||||
|
master:
|
||||||
|
host: 192.168.3.130
|
||||||
|
port: 3306
|
||||||
|
database: family_financial
|
||||||
|
username: root
|
||||||
|
password: "123456"
|
||||||
|
|
||||||
|
mongodb:
|
||||||
|
database: financial
|
||||||
|
host: 192.168.3.130
|
||||||
|
port: 27017
|
||||||
|
username: admin
|
||||||
|
password: "123456"
|
||||||
|
authentication-database: admin
|
||||||
|
additional-hosts: 192.168.3.130
|
||||||
|
|
||||||
|
redis:
|
||||||
|
host: 192.168.3.130
|
||||||
|
port: 6379
|
||||||
|
database: 0
|
||||||
|
password: "123456"
|
||||||
|
|
||||||
|
minio:
|
||||||
|
endpointUrl: "http://192.168.3.130:9000"
|
||||||
|
accessKey: bunny
|
||||||
|
secretKey: "02120212"
|
||||||
|
bucket-name: financial
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
#mybatis-plus:
|
||||||
|
# configuration:
|
||||||
|
# map-underscore-to-camel-case: true
|
||||||
|
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 查看日志
|
||||||
|
server:
|
||||||
|
port: 8080
|
||||||
|
|
||||||
|
logging:
|
||||||
|
level:
|
||||||
|
cn.bunny.service.mapper: warn
|
||||||
|
cn.bunny.service.controller: warn
|
||||||
|
cn.bunny.service.service: warn
|
||||||
|
root: warn
|
||||||
|
pattern:
|
||||||
|
dateformat: HH:mm:ss:SSS
|
||||||
|
file:
|
||||||
|
path: "logs/${spring.application.name}"
|
||||||
|
|
||||||
|
# 线上禁用文档
|
||||||
|
knife4j:
|
||||||
|
enable: true
|
||||||
|
production: true
|
||||||
|
|
||||||
|
bunny:
|
||||||
|
master:
|
||||||
|
host: rm-bp12z6hlv46vi6g8mro.mysql.rds.aliyuncs.com
|
||||||
|
port: 3306
|
||||||
|
database: family_financial
|
||||||
|
username: family_financial_prod
|
||||||
|
password: 0212family_financial
|
||||||
|
|
||||||
|
mongodb:
|
||||||
|
database: financial
|
||||||
|
host: 111.229.137.235
|
||||||
|
port: 27017
|
||||||
|
username: admin
|
||||||
|
password: "02120212"
|
||||||
|
authentication-database: admin
|
||||||
|
additional-hosts: 111.229.137.235
|
||||||
|
|
||||||
|
redis:
|
||||||
|
host: 47.120.65.66
|
||||||
|
port: 6379
|
||||||
|
database: 6
|
||||||
|
password: "02120212"
|
||||||
|
|
||||||
|
minio:
|
||||||
|
endpointUrl: "http://116.196.101.14:9000"
|
||||||
|
accessKey: bunny
|
||||||
|
secretKey: "02120212"
|
||||||
|
bucket-name: financial
|
||||||
|
|
|
@ -1,3 +1,19 @@
|
||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
name: mvc
|
name: mvc
|
||||||
|
profiles:
|
||||||
|
active: dev
|
||||||
|
servlet:
|
||||||
|
multipart:
|
||||||
|
max-file-size: 6MB
|
||||||
|
|
||||||
|
datasource:
|
||||||
|
type: com.zaxxer.hikari.HikariDataSource
|
||||||
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
|
url: jdbc:mysql://${bunny.master.host}:${bunny.master.port}/${bunny.master.database}?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true
|
||||||
|
username: ${bunny.master.username}
|
||||||
|
password: ${bunny.master.password}
|
||||||
|
|
||||||
|
jackson:
|
||||||
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
|
time-zone: GMT+8
|
|
@ -0,0 +1,42 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en" xmlns:th="http://www.thymeleaf.org">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<link crossorigin="anonymous" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"
|
||||||
|
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" rel="stylesheet">
|
||||||
|
<script crossorigin="anonymous" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
|
||||||
|
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
<title>账单信息</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<table class="table table-striped">
|
||||||
|
<!-- 表头 -->
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col">序号</th>
|
||||||
|
<th scope="col">支出类型</th>
|
||||||
|
<th scope="col">交易金额</th>
|
||||||
|
<th scope="col">交易详情</th>
|
||||||
|
<th scope="col">交易时间</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<!-- 当数据为空 -->
|
||||||
|
<tr th:if="${#lists.isEmpty(billList)}">
|
||||||
|
<td colspan="4">数据为空</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<!-- 渲染数据 -->
|
||||||
|
<tr th:each="bill,state : ${billList}" th:unless="${#lists.isEmpty(billList)}">
|
||||||
|
<th scope="row" th:text="${state.index + 1}">1</th>
|
||||||
|
<td th:class="${bill.type==-1 ? 'text-danger' : 'text-success'}" th:text="${bill.type==-1?'支出':'收入'}"></td>
|
||||||
|
<td th:text="'¥' + ${bill.amount}"></td>
|
||||||
|
<td th:text="${bill.description}"></td>
|
||||||
|
<td class="text-success" th:text="${#temporals.format(bill.transactionDate,'yyyy-MM-dd HH:mm:ss')}"></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue