完善代码

This commit is contained in:
2026-05-22 21:37:51 +08:00
parent fdcc187384
commit ca38ec4f60
13 changed files with 225 additions and 72 deletions

View File

@@ -1,7 +1,6 @@
package com.org.flashsalesystem.controller;
import com.org.flashsalesystem.dto.FlashSaleDTO;
import com.org.flashsalesystem.dto.ProductDTO;
import com.org.flashsalesystem.entity.Product;
import com.org.flashsalesystem.repository.ProductRepository;
import com.org.flashsalesystem.service.FlashSaleService;
@@ -18,7 +17,10 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* API控制器 - 为Vue前端提供REST接口
@@ -47,7 +49,7 @@ public class ApiController {
try {
// 获取前N个商品作为热门商品
Pageable pageable = PageRequest.of(0, limit, Sort.by(Sort.Direction.DESC, "id"));
Page<Product> productPage = productRepository.findAll(pageable);
Page<Product> productPage = productRepository.findByStatus(1, pageable);
List<Map<String, Object>> products = new ArrayList<>();
for (Product product : productPage.getContent()) {
@@ -175,7 +177,7 @@ public class ApiController {
try {
Pageable pageable = PageRequest.of(page, size, Sort.by(Sort.Direction.DESC, "id"));
Page<Product> productPage = productRepository.findAll(pageable);
Page<Product> productPage = productRepository.findByStatus(1, pageable);
List<Map<String, Object>> products = new ArrayList<>();
for (Product product : productPage.getContent()) {
@@ -227,4 +229,4 @@ public class ApiController {
return ResponseEntity.ok(response);
}
}
}