feat: thymeleaf查询

This commit is contained in:
Bunny 2025-01-22 22:31:16 +08:00
parent e808411049
commit 5fb5f7c524
6 changed files with 92 additions and 9 deletions

2
.gitignore vendored
View File

@ -3,7 +3,7 @@ target/
!.mvn/wrapper/maven-wrapper.jar !.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/ !**/src/main/**/target/
!**/src/test/**/target/ !**/src/test/**/target/
logs/**
### STS ### ### STS ###
.apt_generated .apt_generated
.classpath .classpath

View File

@ -1,11 +1,15 @@
package cn.bunny.mvc.controller; package cn.bunny.mvc.controller;
import cn.bunny.mvc.dao.dto.BillDto;
import cn.bunny.mvc.dao.entity.Bill; import cn.bunny.mvc.dao.entity.Bill;
import cn.bunny.mvc.service.ThymeleafService; 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 io.swagger.v3.oas.annotations.Operation;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; 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 org.springframework.web.bind.annotation.RequestMapping;
import java.util.List; import java.util.List;
@ -21,9 +25,16 @@ public class ThymeleafController {
} }
@Operation(summary = "查看账单信息") @Operation(summary = "查看账单信息")
@GetMapping("bill") @RequestMapping("bill/{page}/{limit}")
public String bill(Model model) { public String bill(Model model,
List<Bill> billList = thymeleafService.bill(); @PathVariable Long page,
@PathVariable Long limit,
BillDto dto) {
IPage<Bill> billIPage = new Page<>(page, limit);
if (!StringUtils.hasText(dto.getDescription())) {
dto.setDescription(null);
}
List<Bill> billList = thymeleafService.bill(billIPage, dto);
model.addAttribute("billList", billList); model.addAttribute("billList", billList);
return "thymeleaf/bill"; return "thymeleaf/bill";

View File

@ -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<Long> 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;
}

View File

@ -1,7 +1,9 @@
package cn.bunny.mvc.service; package cn.bunny.mvc.service;
import cn.bunny.mvc.dao.dto.BillDto;
import cn.bunny.mvc.dao.entity.Bill; import cn.bunny.mvc.dao.entity.Bill;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List; import java.util.List;
@ -13,5 +15,5 @@ public interface ThymeleafService extends IService<Bill> {
* *
* @return 账单列表 * @return 账单列表
*/ */
List<Bill> bill(); List<Bill> bill(IPage<Bill> billIPage, BillDto dto);
} }

View File

@ -1,11 +1,13 @@
package cn.bunny.mvc.service.impl; package cn.bunny.mvc.service.impl;
import cn.bunny.mvc.dao.dto.BillDto;
import cn.bunny.mvc.dao.entity.Bill; import cn.bunny.mvc.dao.entity.Bill;
import cn.bunny.mvc.mapper.BillMapper; import cn.bunny.mvc.mapper.BillMapper;
import cn.bunny.mvc.service.ThymeleafService; 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.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
@ -18,8 +20,14 @@ public class ThymeleafServiceImpl extends ServiceImpl<BillMapper, Bill> implemen
* @return 账单列表 * @return 账单列表
*/ */
@Override @Override
public List<Bill> bill() { public List<Bill> bill(IPage<Bill> billIPage, BillDto dto) {
IPage<Bill> billIPage = new Page<>(1, 30); if (dto != null) {
Bill bill = new Bill();
BeanUtils.copyProperties(dto, bill);
LambdaQueryWrapper<Bill> wrapper = new LambdaQueryWrapper<>(bill);
return list(billIPage, wrapper);
}
return list(billIPage); return list(billIPage);
} }
} }

View File

@ -11,6 +11,21 @@
</head> </head>
<body> <body>
<form action="/thymeleaf/bill/1/30" class="row g-3" method="get">
<div class="col">
<input aria-label="收入/支出 输入 1或-1" class="form-control" name="type" placeholder="收入/支出 输入 1或-1" type="text">
</div>
<div class="col">
<input aria-label="记录详情" class="form-control" name="description" placeholder="记录详情" type="text">
</div>
<!-- <div class="col"> -->
<!-- <input aria-label="Last name" class="form-control" placeholder="Last name" type="text"> -->
<!-- </div> -->
<div class="col">
<button class="btn btn-primary" type="submit">查询</button>
</div>
</form>
<table class="table table-striped"> <table class="table table-striped">
<!-- 表头 --> <!-- 表头 -->
<thead> <thead>
@ -39,4 +54,7 @@
</tbody> </tbody>
</table> </table>
</body> </body>
<script>
</script>
</html> </html>