package com.demo.service.impl; import com.demo.dao.CustomerMapper; import com.demo.dao.ProductMapper; import com.demo.dao.ReviewMapper; import com.demo.pojo.Customer; import com.demo.pojo.Product; import com.demo.pojo.Review; import com.demo.pojo.ReviewExample; import com.demo.service.ReviewService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service public class ReviewServiceImpl implements ReviewService { @Autowired private ReviewMapper reviewMapper; @Autowired private CustomerMapper customerMapper; @Autowired private ProductMapper productMapper; @Override public List list() { List reviews = reviewMapper.selectByExample(null); for (Review review:reviews){ Customer customer = customerMapper.selectByPrimaryKey(review.getCstid()); Product product = productMapper.selectByPrimaryKey(review.getPid()); review.setCustomer(customer); review.setProduct(product); } return reviews; } @Override public List getReviewListByPid(int id) { ReviewExample example = new ReviewExample(); example.createCriteria().andPidEqualTo(id); List reviews = reviewMapper.selectByExample(example); for (Review review:reviews){ Customer customer = customerMapper.selectByPrimaryKey(review.getCstid()); review.setCustomer(customer); } return reviews; } @Override public void del(int id) { reviewMapper.deleteByPrimaryKey(id); } @Override public Review get(int id) { return reviewMapper.selectByPrimaryKey(id); } @Override public void save(Review review) { reviewMapper.insert(review); } }