Java的新项目学成在线笔记-day9(十一)

4.2 课程数据模型查询接口 

静态化操作需要模型数据方可进行静态化,课程数据模型由课程管理服务提供,仅供课程静态化程序调用使用。 4.2.1 接口定义 
1、响应结果类型

[AppleScript] 纯文本查看 复制代码

?

1

2

3

4

5

6

7

@Data

 @ToString @NoArgsConstructor public class CourseView  implements Serializable  {

    CourseBase courseBase;//基础信息  

  CourseMarket courseMarket;//课程营销  

  CoursePic coursePic;//课程图片  

  TeachplanNode TeachplanNode;//教学计划

  }


2、请求类型

String:课程id  
3、接口定义如下
 

[AppleScript] 纯文本查看 复制代码

?

1

2

@ApiOperation("课程视图查询")  

  public CourseView courseview(String id);


4.2.2 Dao 
需要对course_base、course_market、course_pic、teachplan等信息进行查询, 新建课程营销的dao,其它dao已经存在不用再建。
 

[AppleScript] 纯文本查看 复制代码

?

1

public interface CourseMarketRepository extends JpaRepository<CourseMarket,String> { }


4.2.3 Service 

[AppleScript] 纯文本查看 复制代码

?

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

//课程视图查询   

 public CourseView getCoruseView(String id) {      

  CourseView courseView = new CourseView()

       //查询课程基本信息  

      Optional<CourseBase> optional = courseBaseRepository.findById(id)

       if(optional.isPresent()){       

     CourseBase courseBase = optional.get();     

       courseView.setCourseBase(courseBase);  

      }      

  //查询课程营销信息  

      Optional<CourseMarket> courseMarketOptional = courseMarketRepository.findById(id);  

      if(courseMarketOptional.isPresent()){        

    CourseMarket courseMarket = courseMarketOptional.get();    

        courseView.setCourseMarket(courseMarket);  

      }      

  //查询课程图片信息  

      Optional<CoursePic> picOptional = coursePicRepository.findById(id);   

     if(picOptional.isPresent()){      

      CoursePic coursePic = picOptional.get();   

         courseView.setCoursePic(picOptional.get());  

      }   

    //查询课程计划信息    

    TeachplanNode teachplanNode = teachplanMapper.selectList(id);

        courseView.setTeachplanNode(teachplanNode);  

      return courseView;  

    }


4.2.4 Controller 

[AppleScript] 纯文本查看 复制代码

?

1

2

3

4

@Override

 @GetMapping("/courseview/{id}")

 public CourseView courseview(@PathVariable("id") String id) { 

   return courseService.getCoruseView(id); }

猜你喜欢

转载自blog.csdn.net/czbkzmj/article/details/89632509
今日推荐