业务层
com.qfedu.fmmall.service.CategoryService
package com.qfedu.fmmall.service;
import com.qfedu.fmmall.vo.ResultVO;
/**
* @author beyondx
* @date Created in 2022/08/14/ 18:27
*/
public interface CategoryService {
/**
* 查询所有, 不登录页可以查询, 不需要参数
* 也没有 分页查询
* @return
*/
public ResultVO listCategories();
}
com.qfedu.fmmall.service.impl.CategoryServiceImpl
package com.qfedu.fmmall.service.impl;
import com.qfedu.fmmall.dao.CategoryMapper;
import com.qfedu.fmmall.entity.CategoryVO;
import com.qfedu.fmmall.service.CategoryService;
import com.qfedu.fmmall.vo.ResStatus;
import com.qfedu.fmmall.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author beyondx
* @date Created in 2022/08/14/ 18:29
*/
@Service
public class CategoryServiceImpl implements CategoryService {
@Autowired
private CategoryMapper categoryMapper;
@Override
public ResultVO listCategories() {
List<CategoryVO> categoryVOS = categoryMapper.selectAllCategories();
ResultVO resultVO = new ResultVO(ResStatus.OK, "success", categoryVOS);
return resultVO;
}
}
控制层
com.qfedu.fmmall.controller.IndexController
package com.qfedu.fmmall.controller;
import com.qfedu.fmmall.service.CategoryService;
import com.qfedu.fmmall.service.IndexImgService;
import com.qfedu.fmmall.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author beyondx
* @date Created in 2022/08/14/ 7:15
*/
//@Api(value = "提供首页数据显示所需的接口", tags = "首页管理")
@RestController
@CrossOrigin
@RequestMapping("/index")
// service可以分开写; 接口可以统一提供, 这里应该说的是 前端对后端暴露的 controller(这里也叫做接口了)
public class IndexController {
@Autowired
private IndexImgService indexImgService;
@Autowired
private CategoryService categoryService;
/**
* 响应 轮播图 数据
* @return
*/
// @ApiOperation("首页轮播图接口")
@GetMapping("/indeximg") // 查询用 GetMapping
public ResultVO listIndexImgs() {
return indexImgService.listIndexImgs();
}
/**
* @return
*/
@GetMapping("/category-list")
@ApiOperation("商品分类的查询接口")
public ResultVO listCategory() {
return categoryService.listCategories();
}
}
对 fmmall, clean, install
启动项目, 而不是 单元测试