From 5fb5f7c5243d7eecea3850983fe9a19c48088e3a Mon Sep 17 00:00:00 2001 From: Bunny <1319900154@qq.com> Date: Wed, 22 Jan 2025 22:31:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20thymeleaf=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- .../mvc/controller/ThymeleafController.java | 19 ++++++-- .../java/cn/bunny/mvc/dao/dto/BillDto.java | 44 +++++++++++++++++++ .../bunny/mvc/service/ThymeleafService.java | 4 +- .../service/impl/ThymeleafServiceImpl.java | 14 ++++-- .../resources/templates/thymeleaf/bill.html | 18 ++++++++ 6 files changed, 92 insertions(+), 9 deletions(-) create mode 100644 mvc/src/main/java/cn/bunny/mvc/dao/dto/BillDto.java diff --git a/.gitignore b/.gitignore index 549e00a..de60279 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ target/ !.mvn/wrapper/maven-wrapper.jar !**/src/main/**/target/ !**/src/test/**/target/ - +logs/** ### STS ### .apt_generated .classpath diff --git a/mvc/src/main/java/cn/bunny/mvc/controller/ThymeleafController.java b/mvc/src/main/java/cn/bunny/mvc/controller/ThymeleafController.java index cac1caa..817742c 100644 --- a/mvc/src/main/java/cn/bunny/mvc/controller/ThymeleafController.java +++ b/mvc/src/main/java/cn/bunny/mvc/controller/ThymeleafController.java @@ -1,11 +1,15 @@ package cn.bunny.mvc.controller; +import cn.bunny.mvc.dao.dto.BillDto; import cn.bunny.mvc.dao.entity.Bill; import cn.bunny.mvc.service.ThymeleafService; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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.util.StringUtils; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import java.util.List; @@ -21,9 +25,16 @@ public class ThymeleafController { } @Operation(summary = "查看账单信息") - @GetMapping("bill") - public String bill(Model model) { - List billList = thymeleafService.bill(); + @RequestMapping("bill/{page}/{limit}") + public String bill(Model model, + @PathVariable Long page, + @PathVariable Long limit, + BillDto dto) { + IPage billIPage = new Page<>(page, limit); + if (!StringUtils.hasText(dto.getDescription())) { + dto.setDescription(null); + } + List billList = thymeleafService.bill(billIPage, dto); model.addAttribute("billList", billList); return "thymeleaf/bill"; diff --git a/mvc/src/main/java/cn/bunny/mvc/dao/dto/BillDto.java b/mvc/src/main/java/cn/bunny/mvc/dao/dto/BillDto.java new file mode 100644 index 0000000..ce88656 --- /dev/null +++ b/mvc/src/main/java/cn/bunny/mvc/dao/dto/BillDto.java @@ -0,0 +1,44 @@ +package cn.bunny.mvc.dao.dto; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.time.LocalDate; +import java.util.List; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +@Schema(name = "BillDto对象", title = "账单信息查询内容", description = "账单信息查询内容") +public class BillDto { + + @Schema(name = "userId", title = "绑定的用户id") + private Long userId; + + @Schema(name = "amount", title = "金额") + private BigDecimal amount; + + @Schema(name = "categoryIds", title = "类别分类") + private List categoryIds; + + @Schema(name = "username", title = "类型:1 - 收入,-1 - 支出") + private Byte type; + + @Schema(name = "description", title = "描述") + private String description; + + @Schema(name = "startDate", title = "开始交易日期") + @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd") + private LocalDate startDate; + + @Schema(name = "endDate", title = "结束交易日期") + @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd") + private LocalDate endDate; + +} \ No newline at end of file diff --git a/mvc/src/main/java/cn/bunny/mvc/service/ThymeleafService.java b/mvc/src/main/java/cn/bunny/mvc/service/ThymeleafService.java index 31b43dd..3a6b2ae 100644 --- a/mvc/src/main/java/cn/bunny/mvc/service/ThymeleafService.java +++ b/mvc/src/main/java/cn/bunny/mvc/service/ThymeleafService.java @@ -1,7 +1,9 @@ package cn.bunny.mvc.service; +import cn.bunny.mvc.dao.dto.BillDto; import cn.bunny.mvc.dao.entity.Bill; +import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; import java.util.List; @@ -13,5 +15,5 @@ public interface ThymeleafService extends IService { * * @return 账单列表 */ - List bill(); + List bill(IPage billIPage, BillDto dto); } 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 index 9dfa376..9485e66 100644 --- a/mvc/src/main/java/cn/bunny/mvc/service/impl/ThymeleafServiceImpl.java +++ b/mvc/src/main/java/cn/bunny/mvc/service/impl/ThymeleafServiceImpl.java @@ -1,11 +1,13 @@ package cn.bunny.mvc.service.impl; +import cn.bunny.mvc.dao.dto.BillDto; import cn.bunny.mvc.dao.entity.Bill; import cn.bunny.mvc.mapper.BillMapper; import cn.bunny.mvc.service.ThymeleafService; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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.beans.BeanUtils; import org.springframework.stereotype.Service; import java.util.List; @@ -18,8 +20,14 @@ public class ThymeleafServiceImpl extends ServiceImpl implemen * @return 账单列表 */ @Override - public List bill() { - IPage billIPage = new Page<>(1, 30); + public List bill(IPage billIPage, BillDto dto) { + if (dto != null) { + Bill bill = new Bill(); + BeanUtils.copyProperties(dto, bill); + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(bill); + return list(billIPage, wrapper); + } + return list(billIPage); } } diff --git a/mvc/src/main/resources/templates/thymeleaf/bill.html b/mvc/src/main/resources/templates/thymeleaf/bill.html index 06cd522..d39957a 100644 --- a/mvc/src/main/resources/templates/thymeleaf/bill.html +++ b/mvc/src/main/resources/templates/thymeleaf/bill.html @@ -11,6 +11,21 @@ +
+
+ +
+
+ +
+ + + +
+ +
+
+ @@ -39,4 +54,7 @@
+ \ No newline at end of file