feat: thymeleaf查询
This commit is contained in:
parent
e808411049
commit
5fb5f7c524
|
@ -3,7 +3,7 @@ target/
|
|||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
logs/**
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
|
|
|
@ -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<Bill> billList = thymeleafService.bill();
|
||||
@RequestMapping("bill/{page}/{limit}")
|
||||
public String bill(Model model,
|
||||
@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);
|
||||
|
||||
return "thymeleaf/bill";
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -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<Bill> {
|
|||
*
|
||||
* @return 账单列表
|
||||
*/
|
||||
List<Bill> bill();
|
||||
List<Bill> bill(IPage<Bill> billIPage, BillDto dto);
|
||||
}
|
||||
|
|
|
@ -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<BillMapper, Bill> implemen
|
|||
* @return 账单列表
|
||||
*/
|
||||
@Override
|
||||
public List<Bill> bill() {
|
||||
IPage<Bill> billIPage = new Page<>(1, 30);
|
||||
public List<Bill> bill(IPage<Bill> billIPage, BillDto dto) {
|
||||
if (dto != null) {
|
||||
Bill bill = new Bill();
|
||||
BeanUtils.copyProperties(dto, bill);
|
||||
LambdaQueryWrapper<Bill> wrapper = new LambdaQueryWrapper<>(bill);
|
||||
return list(billIPage, wrapper);
|
||||
}
|
||||
|
||||
return list(billIPage);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,21 @@
|
|||
</head>
|
||||
|
||||
<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">
|
||||
<!-- 表头 -->
|
||||
<thead>
|
||||
|
@ -39,4 +54,7 @@
|
|||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
<script>
|
||||
|
||||
</script>
|
||||
</html>
|
Loading…
Reference in New Issue