图片.png图片.png图片.png

一、新建banner微服务

1、在service模块下创建子模块service-cms图片.png

2、使用代码生成器生成banner代码

(1)创建crm_banner表

图片.png

(2)生成代码

图片.png**

3、配置application.properties

  1. # 服务端口
  2. server.port=8004
  3. # 服务名
  4. spring.application.name=service-cms
  5. # mysql数据库连接
  6. spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
  7. spring.datasource.url=jdbc:mysql://localhost:3306/guli?serverTimezone=GMT%2B8
  8. spring.datasource.username=root
  9. spring.datasource.password=root
  10. #返回json的全局时间格式
  11. spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
  12. spring.jackson.time-zone=GMT+8
  13. #配置mapper xml文件的路径
  14. mybatis-plus.mapper-locations=classpath:com/atguigu/cmsservice/mapper/xml/*.xml
  15. #mybatis日志
  16. mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl

4、创建启动类

创建CmsApplication.java

  1. @SpringBootApplication
  2. @ComponentScan({"com.atguigu"}) //指定扫描位置
  3. @MapperScan("com.atguigu.cmsservice.mapper")
  4. public class CmsApplication {
  5. public static void main(String[] args) {
  6. SpringApplication.run(CmsApplication.class, args);
  7. }
  8. }

二、创建banner服务接口

1、创建banner后台管理接口

banner后台分页查询、添加、修改、删除接口

  1. @RestController
  2. @RequestMapping("/eduservice/banner")
  3. @CrossOrigin
  4. public class CrmBannerController {
  5. @Autowired
  6. private CrmBannerService bannerService;
  7. @ApiOperation(value = "获取Banner分页列表")
  8. @GetMapping("{page}/{limit}")
  9. public R index(
  10. @ApiParam(name = "page", value = "当前页码", required = true)
  11. @PathVariable Long page,
  12. @ApiParam(name = "limit", value = "每页记录数", required = true)
  13. @PathVariable Long limit) {
  14. Page<CrmBanner> pageParam = new Page<>(page, limit);
  15. bannerService.pageBanner(pageParam,null);
  16. return R.ok().data("items", pageParam.getRecords()).data("total", pageParam.getTotal());
  17. }
  18. @ApiOperation(value = "获取Banner")
  19. @GetMapping("get/{id}")
  20. public R get(@PathVariable String id) {
  21. CrmBanner banner = bannerService.getBannerById(id);
  22. return R.ok().data("item", banner);
  23. }
  24. @ApiOperation(value = "新增Banner")
  25. @PostMapping("save")
  26. public R save(@RequestBody CrmBanner banner) {
  27. bannerService.saveBanner(banner);
  28. return R.ok();
  29. }
  30. @ApiOperation(value = "修改Banner")
  31. @PutMapping("update")
  32. public R updateById(@RequestBody CrmBanner banner) {
  33. bannerService.updateBannerById(banner);
  34. return R.ok();
  35. }
  36. @ApiOperation(value = "删除Banner")
  37. @DeleteMapping("remove/{id}")
  38. public R remove(@PathVariable String id) {
  39. bannerService.removeBannerById(id);
  40. return R.ok();
  41. }
  42. }

2、创建banner前台查询接口

首页获取banner数据接口

  1. @RestController
  2. @RequestMapping("/educms/banner")
  3. @Api(description = "网站首页Banner列表")
  4. @CrossOrigin //跨域
  5. public class BannerApiController {
  6. @Autowired
  7. private CrmBannerService bannerService;
  8. @ApiOperation(value = "获取首页banner")
  9. @GetMapping("getAllBanner")
  10. public R index() {
  11. List<CrmBanner> list = bannerService.selectIndexList();
  12. return R.ok().data("bannerList", list);
  13. }
  14. }

三、实现banner后台管理前端

实现banner后台的添加修改删除和分页查询操作,和其他后台管理模块类似

四、新建前端查询课程名师接口

1、在service-edu模块创建controller

(1)查询最新前4条讲师数据
(2)查询最新前8条课程数据

  1. @RestController
  2. @RequestMapping("/eduservice/index")
  3. @CrossOrigin
  4. public class IndexController {
  5. @Autowired
  6. private EduCourseService courseService;
  7. @Autowired
  8. private EduTeacherService teacherService;
  9. //查询前8条热门课程,查询前4条名师
  10. @GetMapping("index")
  11. public R index() {
  12. //查询前8条热门课程
  13. QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
  14. wrapper.orderByDesc("id");
  15. wrapper.last("limit 8");
  16. List<EduCourse> eduList = courseService.list(wrapper);
  17. //查询前4条名师
  18. QueryWrapper<EduTeacher> wrapperTeacher = new QueryWrapper<>();
  19. wrapperTeacher.orderByDesc("id");
  20. wrapperTeacher.last("limit 4");
  21. List<EduTeacher> teacherList = teacherService.list(wrapperTeacher);
  22. return R.ok().data("eduList",eduList).data("teacherList",teacherList);
  23. }
  24. }