From e80841104969f0bc6269870eab469172c089ccee Mon Sep 17 00:00:00 2001 From: Bunny <1319900154@qq.com> Date: Wed, 22 Jan 2025 21:52:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20thymeleaf=E7=9A=84=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mvc/SpringMVC笔记.md | 291 +++++++++++++++++- mvc/pom.xml | 37 ++- .../mvc/configuration/MybatisPlusConfig.java | 36 +++ .../mvc/controller/ThymeleafController.java | 31 ++ .../bunny/mvc/controller/UseController.java | 2 +- .../mvc/controller/UseRestController.java | 4 +- .../java/cn/bunny/mvc/dao/BaseEntity.java | 48 +++ .../java/cn/bunny/mvc/dao/BaseUserEntity.java | 18 ++ .../java/cn/bunny/mvc/dao/entity/Bill.java | 49 +++ .../bunny/mvc/dao/entity/BudgetCategory.java | 55 ++++ .../cn/bunny/mvc/dao/entity/Category.java | 35 +++ .../mvc/dao/entity/DebtRepaymentPlan.java | 49 +++ .../cn/bunny/mvc/dao/entity/DebtTracking.java | 51 +++ .../cn/bunny/mvc/dao/entity/SavingGoal.java | 51 +++ .../java/cn/bunny/mvc/mapper/BillMapper.java | 11 + .../bunny/mvc/service/ThymeleafService.java | 17 + .../service/impl/ThymeleafServiceImpl.java | 25 ++ mvc/src/main/resources/application-dev.yml | 47 +++ mvc/src/main/resources/application-prod.yml | 52 ++++ mvc/src/main/resources/application.yaml | 18 +- .../templates/{page => test}/test.html | 0 .../templates/{page => test}/test2.html | 0 .../templates/{page => test}/test3.html | 0 .../resources/templates/thymeleaf/bill.html | 42 +++ 24 files changed, 950 insertions(+), 19 deletions(-) create mode 100644 mvc/src/main/java/cn/bunny/mvc/configuration/MybatisPlusConfig.java create mode 100644 mvc/src/main/java/cn/bunny/mvc/controller/ThymeleafController.java create mode 100644 mvc/src/main/java/cn/bunny/mvc/dao/BaseEntity.java create mode 100644 mvc/src/main/java/cn/bunny/mvc/dao/BaseUserEntity.java create mode 100644 mvc/src/main/java/cn/bunny/mvc/dao/entity/Bill.java create mode 100644 mvc/src/main/java/cn/bunny/mvc/dao/entity/BudgetCategory.java create mode 100644 mvc/src/main/java/cn/bunny/mvc/dao/entity/Category.java create mode 100644 mvc/src/main/java/cn/bunny/mvc/dao/entity/DebtRepaymentPlan.java create mode 100644 mvc/src/main/java/cn/bunny/mvc/dao/entity/DebtTracking.java create mode 100644 mvc/src/main/java/cn/bunny/mvc/dao/entity/SavingGoal.java create mode 100644 mvc/src/main/java/cn/bunny/mvc/mapper/BillMapper.java create mode 100644 mvc/src/main/java/cn/bunny/mvc/service/ThymeleafService.java create mode 100644 mvc/src/main/java/cn/bunny/mvc/service/impl/ThymeleafServiceImpl.java create mode 100644 mvc/src/main/resources/application-dev.yml create mode 100644 mvc/src/main/resources/application-prod.yml rename mvc/src/main/resources/templates/{page => test}/test.html (100%) rename mvc/src/main/resources/templates/{page => test}/test2.html (100%) rename mvc/src/main/resources/templates/{page => test}/test3.html (100%) create mode 100644 mvc/src/main/resources/templates/thymeleaf/bill.html diff --git a/mvc/SpringMVC笔记.md b/mvc/SpringMVC笔记.md index 8b85f90..7a1926d 100644 --- a/mvc/SpringMVC笔记.md +++ b/mvc/SpringMVC笔记.md @@ -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 getJson() { } ``` +#### 将视图和模型拆开 + +```java +// 将视图和模型拆开 +@GetMapping("page/test3") +public String test3(Model model) { + model.addAttribute("test3", "测试3"); + return "page/test3"; +} +``` + ### 使用`@RestController` #### 使用方式1 @@ -143,4 +158,276 @@ public ModelAndView test2(ModelAndView modelAndView) { modelAndView.setViewName("page/test2"); return modelAndView; } -``` \ No newline at end of file +``` + +## Thymeleaf快速入门 + +Thymeleaf 是一种现代化的 Java 模板引擎,广泛用于生成 HTML、XML、JavaScript 等内容。它有许多内置的指令和功能,用于渲染动态内容、条件渲染、循环、处理表达式等。以下是 Thymeleaf 中常见的指令和属性的详细介绍: + +### 1. **`th:text`** + +用于替换元素的文本内容。 + +```html + +``` + +- `${message}` 的值会替换 `span` 元素的文本。 + +> 如果需要格式化日期,需要注意,使用`temporals`进行操作 +> +> ```html +> +> ``` + +### 2. **`th:utext`** + +用于替换元素的文本内容,并允许处理 HTML 标签(不会转义 HTML)。 + +```html + +``` + +- `${htmlContent}` 的内容直接插入,并解析其中的 HTML。 + +### 3. **`th:value`** + +设置表单元素的 `value` 属性,通常用于输入框或选择框。 + +```html + +``` + +- 将 `${user.name}` 的值赋给该输入框的 `value` 属性。 + +### 4. **`th:each`** + +用于循环遍历集合或数组。 + +```html + +``` + +- 遍历 `people` 集合,输出每个 `person.name`。 + +### 5. **`th:if`** + +用于条件渲染,只有满足条件时才渲染元素。 + +```html +
+

Welcome, admin!

+
+``` + +- 如果 `user.isAdmin` 为 `true`,渲染该 `div`。 + +### 6. **`th:unless`** + +与 `th:if` 相反,只有条件为 `false` 时才渲染元素。 + +```html +
+

You are not an admin!

+
+``` + +- 如果 `user.isAdmin` 为 `false`,渲染该 `div`。 + +### 7. **`th:attr`** + +用于设置元素的多个属性。 + +```html + +``` + +- 设置 `img` 元素的 `src` 和 `alt` 属性。 + +### 8. **`th:src` / `th:href`** + +用于动态设置 `src` 或 `href` 属性。 + +```html +Image +Click Here +``` + +- `th:src` 用于设置图片的 `src` 属性,`th:href` 用于设置链接的 `href` 属性。 + +### 9. **`th:class`** + +动态设置 `class` 属性,支持条件表达式。 + +```html +
...
+``` + +- 如果 `isActive` 为 `true`,设置 `class="active"`,否则为 `inactive`。 + +### 10. **`th:classappend` / `th:classprepend`** + +分别在现有的 `class` 属性上追加或前置新类。 + +```html +
...
+
...
+``` + +- `th:classappend` 会将新的类追加到现有类的后面。 +- `th:classprepend` 会将新的类添加到现有类的前面。 + +### 11. **`th:id`** + +设置元素的 `id` 属性。 + +```html + +``` + +- 设置 `input` 元素的 `id` 为 `${elementId}` 的值。 + +### 12. **`th:action`** + +设置表单的 `action` 属性。 + +```html +
+ +
+``` + +- 设置表单的 `action` 为 `/submitForm`。 + +### 13. **`th:style`** + +设置元素的 `style` 属性。 + +```html +
+``` + +- 动态设置 `style` 属性,`${color}` 的值会成为 `color` 样式的值。 + +### 14. **`th:fragment`** + +定义一个可重用的片段,通常在模板中调用。 + +```html +
+

Welcome,

+
+``` + +- 定义一个 `userFragment` 片段,可以在其他模板中引用。 + +### 15. **`th:replace`** + +替换当前元素,并将一个片段或其他模板插入其中。 + +```html +
+``` + +- `th:replace` 会将 `userFragment` 片段的内容插入到当前 `div` 中。 + +### 16. **`th:include`** + +将另一个模板的内容插入当前模板中,但不会替换当前元素。 + +```html +
+``` + +- 插入 `userFragment` 的内容,但保留当前 `div` 元素。 + +### 17. **`th:with`** + +局部变量声明,用于在模板中定义临时变量。 + +```html +
+

+
+``` + +- `th:with` 用于在当前元素的上下文中定义变量,类似于局部变量。 + +### 18. **`th:block`** + +在模板中定义一个不会渲染任何 HTML 标签的块元素。用于组合多个元素。 + +```html + +

+
+``` + +- `th:block` 不会渲染任何标签,但可以用来包装多个元素进行条件判断或循环。 + +### 19. **`th:switch` / `th:case`** + +类似于 Java 中的 `switch` 语句,用于条件选择。 + +```html +
+ Active + Inactive + Unknown +
+``` + +- 根据 `${status}` 的值,渲染对应的 `span` 元素。 + +### 20. **`th:object`** + +用来为表单元素绑定一个对象。 + +```html +
+ + + +
+``` + +- `th:object` 绑定整个表单到 `user` 对象。 +- `th:field` 用于绑定每个表单字段到对象的属性。 + +### 21. **`th:href` / `th:src`** + +用于动态设置 URL 值。 + +```html +Profile + +``` + +- 动态生成 URL,支持路径变量的替换。 + +### 22. **`th:placeholder`** + +设置表单输入框的 `placeholder` 属性。 + +```html + +``` + +- 设置 `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` 的条件语句。 \ No newline at end of file diff --git a/mvc/pom.xml b/mvc/pom.xml index 8ff8f16..1358965 100644 --- a/mvc/pom.xml +++ b/mvc/pom.xml @@ -13,22 +13,14 @@ 0.0.1-SNAPSHOT mvc mvc - - - - - - - - - - - - - + 17 + 3.5.6 + 8.0.30 + 5.1.0 + org.springframework.boot @@ -51,6 +43,7 @@ runtime true + org.projectlombok @@ -63,6 +56,24 @@ knife4j-openapi3-jakarta-spring-boot-starter 4.5.0 + + + com.baomidou + mybatis-plus-spring-boot3-starter + ${mybatis-plus.version} + + + + mysql + mysql-connector-java + ${mysql.version} + + + + com.zaxxer + HikariCP + ${HikariCP.version} + diff --git a/mvc/src/main/java/cn/bunny/mvc/configuration/MybatisPlusConfig.java b/mvc/src/main/java/cn/bunny/mvc/configuration/MybatisPlusConfig.java new file mode 100644 index 0000000..e63ba53 --- /dev/null +++ b/mvc/src/main/java/cn/bunny/mvc/configuration/MybatisPlusConfig.java @@ -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; + } +} diff --git a/mvc/src/main/java/cn/bunny/mvc/controller/ThymeleafController.java b/mvc/src/main/java/cn/bunny/mvc/controller/ThymeleafController.java new file mode 100644 index 0000000..cac1caa --- /dev/null +++ b/mvc/src/main/java/cn/bunny/mvc/controller/ThymeleafController.java @@ -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 billList = thymeleafService.bill(); + model.addAttribute("billList", billList); + + return "thymeleaf/bill"; + } +} diff --git a/mvc/src/main/java/cn/bunny/mvc/controller/UseController.java b/mvc/src/main/java/cn/bunny/mvc/controller/UseController.java index 36cd655..ccca714 100644 --- a/mvc/src/main/java/cn/bunny/mvc/controller/UseController.java +++ b/mvc/src/main/java/cn/bunny/mvc/controller/UseController.java @@ -51,6 +51,6 @@ public class UseController { @GetMapping("test3") public String test3(Model model) { model.addAttribute("test3", "测试3"); - return "page/test3"; + return "test/test3"; } } diff --git a/mvc/src/main/java/cn/bunny/mvc/controller/UseRestController.java b/mvc/src/main/java/cn/bunny/mvc/controller/UseRestController.java index f4aa7a5..eb47fe8 100644 --- a/mvc/src/main/java/cn/bunny/mvc/controller/UseRestController.java +++ b/mvc/src/main/java/cn/bunny/mvc/controller/UseRestController.java @@ -12,7 +12,7 @@ public class UseRestController { @GetMapping("page/test") public ModelAndView test() { ModelAndView modelAndView = new ModelAndView(); - modelAndView.setViewName("page/test"); + modelAndView.setViewName("test/test"); modelAndView.addObject("message", "这是消息内容"); return modelAndView; } @@ -20,7 +20,7 @@ public class UseRestController { @GetMapping("page/test2") public ModelAndView test2(ModelAndView modelAndView) { modelAndView.addObject("hello", "你好"); - modelAndView.setViewName("page/test2"); + modelAndView.setViewName("test/test2"); return modelAndView; } } diff --git a/mvc/src/main/java/cn/bunny/mvc/dao/BaseEntity.java b/mvc/src/main/java/cn/bunny/mvc/dao/BaseEntity.java new file mode 100644 index 0000000..0d72b0f --- /dev/null +++ b/mvc/src/main/java/cn/bunny/mvc/dao/BaseEntity.java @@ -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; + +} + diff --git a/mvc/src/main/java/cn/bunny/mvc/dao/BaseUserEntity.java b/mvc/src/main/java/cn/bunny/mvc/dao/BaseUserEntity.java new file mode 100644 index 0000000..477867a --- /dev/null +++ b/mvc/src/main/java/cn/bunny/mvc/dao/BaseUserEntity.java @@ -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; + +} diff --git a/mvc/src/main/java/cn/bunny/mvc/dao/entity/Bill.java b/mvc/src/main/java/cn/bunny/mvc/dao/entity/Bill.java new file mode 100644 index 0000000..f444968 --- /dev/null +++ b/mvc/src/main/java/cn/bunny/mvc/dao/entity/Bill.java @@ -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; + +/** + *

+ * 账单信息 + *

+ * + * @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; + +} + + + diff --git a/mvc/src/main/java/cn/bunny/mvc/dao/entity/BudgetCategory.java b/mvc/src/main/java/cn/bunny/mvc/dao/entity/BudgetCategory.java new file mode 100644 index 0000000..7be6d5d --- /dev/null +++ b/mvc/src/main/java/cn/bunny/mvc/dao/entity/BudgetCategory.java @@ -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; + +/** + *

+ * 预算分类表 + *

+ * + * @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; + +} diff --git a/mvc/src/main/java/cn/bunny/mvc/dao/entity/Category.java b/mvc/src/main/java/cn/bunny/mvc/dao/entity/Category.java new file mode 100644 index 0000000..59e6927 --- /dev/null +++ b/mvc/src/main/java/cn/bunny/mvc/dao/entity/Category.java @@ -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; + +/** + *

+ * 分类信息 + *

+ * + * @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; + +} + diff --git a/mvc/src/main/java/cn/bunny/mvc/dao/entity/DebtRepaymentPlan.java b/mvc/src/main/java/cn/bunny/mvc/dao/entity/DebtRepaymentPlan.java new file mode 100644 index 0000000..cbccc79 --- /dev/null +++ b/mvc/src/main/java/cn/bunny/mvc/dao/entity/DebtRepaymentPlan.java @@ -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; + +/** + *

+ * 债务还款计划表 + *

+ * + * @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; + +} + + + diff --git a/mvc/src/main/java/cn/bunny/mvc/dao/entity/DebtTracking.java b/mvc/src/main/java/cn/bunny/mvc/dao/entity/DebtTracking.java new file mode 100644 index 0000000..1368057 --- /dev/null +++ b/mvc/src/main/java/cn/bunny/mvc/dao/entity/DebtTracking.java @@ -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; + +/** + *

+ * 债务追踪表 + *

+ * + * @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; + +} + + + + + diff --git a/mvc/src/main/java/cn/bunny/mvc/dao/entity/SavingGoal.java b/mvc/src/main/java/cn/bunny/mvc/dao/entity/SavingGoal.java new file mode 100644 index 0000000..070ff93 --- /dev/null +++ b/mvc/src/main/java/cn/bunny/mvc/dao/entity/SavingGoal.java @@ -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; + +/** + *

+ * 用户储值 + *

+ * + * @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; + +} + + diff --git a/mvc/src/main/java/cn/bunny/mvc/mapper/BillMapper.java b/mvc/src/main/java/cn/bunny/mvc/mapper/BillMapper.java new file mode 100644 index 0000000..eae681f --- /dev/null +++ b/mvc/src/main/java/cn/bunny/mvc/mapper/BillMapper.java @@ -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 { +} diff --git a/mvc/src/main/java/cn/bunny/mvc/service/ThymeleafService.java b/mvc/src/main/java/cn/bunny/mvc/service/ThymeleafService.java new file mode 100644 index 0000000..31b43dd --- /dev/null +++ b/mvc/src/main/java/cn/bunny/mvc/service/ThymeleafService.java @@ -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 { + + /** + * 查看账单信息 + * + * @return 账单列表 + */ + List bill(); +} diff --git a/mvc/src/main/java/cn/bunny/mvc/service/impl/ThymeleafServiceImpl.java b/mvc/src/main/java/cn/bunny/mvc/service/impl/ThymeleafServiceImpl.java new file mode 100644 index 0000000..9dfa376 --- /dev/null +++ b/mvc/src/main/java/cn/bunny/mvc/service/impl/ThymeleafServiceImpl.java @@ -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 implements ThymeleafService { + /** + * 查看账单信息 + * + * @return 账单列表 + */ + @Override + public List bill() { + IPage billIPage = new Page<>(1, 30); + return list(billIPage); + } +} diff --git a/mvc/src/main/resources/application-dev.yml b/mvc/src/main/resources/application-dev.yml new file mode 100644 index 0000000..01dfae4 --- /dev/null +++ b/mvc/src/main/resources/application-dev.yml @@ -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 + diff --git a/mvc/src/main/resources/application-prod.yml b/mvc/src/main/resources/application-prod.yml new file mode 100644 index 0000000..c91f339 --- /dev/null +++ b/mvc/src/main/resources/application-prod.yml @@ -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 + diff --git a/mvc/src/main/resources/application.yaml b/mvc/src/main/resources/application.yaml index cd9fdcd..ca19afe 100644 --- a/mvc/src/main/resources/application.yaml +++ b/mvc/src/main/resources/application.yaml @@ -1,3 +1,19 @@ spring: application: - name: mvc \ No newline at end of file + 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 \ No newline at end of file diff --git a/mvc/src/main/resources/templates/page/test.html b/mvc/src/main/resources/templates/test/test.html similarity index 100% rename from mvc/src/main/resources/templates/page/test.html rename to mvc/src/main/resources/templates/test/test.html diff --git a/mvc/src/main/resources/templates/page/test2.html b/mvc/src/main/resources/templates/test/test2.html similarity index 100% rename from mvc/src/main/resources/templates/page/test2.html rename to mvc/src/main/resources/templates/test/test2.html diff --git a/mvc/src/main/resources/templates/page/test3.html b/mvc/src/main/resources/templates/test/test3.html similarity index 100% rename from mvc/src/main/resources/templates/page/test3.html rename to mvc/src/main/resources/templates/test/test3.html diff --git a/mvc/src/main/resources/templates/thymeleaf/bill.html b/mvc/src/main/resources/templates/thymeleaf/bill.html new file mode 100644 index 0000000..06cd522 --- /dev/null +++ b/mvc/src/main/resources/templates/thymeleaf/bill.html @@ -0,0 +1,42 @@ + + + + + + + + 账单信息 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
序号支出类型交易金额交易详情交易时间
数据为空
1
+ + \ No newline at end of file