根据您提供的代码,您只对MarketCoupon对象的属性进行了获取操作,并没有进行返回给前端的操作。返回给前端的数据是由您的代码逻辑中的其他部分决定的。

如果您希望返回给前端的数据只包含指定的属性,可以创建一个新的DTO(数据传输对象)类,将需要的属性作为该类的成员变量,并在遍历MarketCoupon对象时,将需要的属性值赋给DTO对象,最后将DTO对象返回给前端。

例如,您可以创建一个CouponDTO类:

public class CouponDTO {
    private Integer id;
    private String name;
    private String desc;
    private BigDecimal min;
    private Short days;
    private BigDecimal discount;
    private String tag;
    
    // 省略getter和setter方法
}

然后,您可以修改您的代码如下:

MarketCouponExample couponExample = new MarketCouponExample();
List<MarketCoupon> coupons = couponMapper.selectByExample(couponExample);
List<CouponDTO> couponDTOs = new ArrayList<>();
coupons.forEach(marketCoupon -> {
    CouponDTO couponDTO = new CouponDTO();
    couponDTO.setId(marketCoupon.getId());
    couponDTO.setName(marketCoupon.getName());
    couponDTO.setDesc(marketCoupon.getDesc());
    couponDTO.setMin(marketCoupon.getMin());
    couponDTO.setDays(marketCoupon.getDays());
    couponDTO.setDiscount(marketCoupon.getDiscount());
    couponDTO.setTag(marketCoupon.getTag());
    couponDTOs.add(couponDTO);
});
return couponDTOs;

这样,返回给前端的数据就只包含指定的属性了。

MarketCouponExample couponExample = new MarketCouponExample; ListMarketCoupon coupons = couponMapperselectByExamplecouponExample; couponsstreamforEachnew ConsumerMarketCoupon

原文地址: https://www.cveoy.top/t/topic/jaeK 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录