Xuecheng Online - day 15 - handout - media management system integration IV

3. Online learning interface
3.1 demand analysis
According to the business process below, this chapter completes the front-end learning page to request the learning service to obtain the course video address, and automatically plays the video.
 
3.2 build development environment

3.2.1 create database
Create XC ﹣ learning database, which will record students' course selection information and learning information.  
Import: data / xc_learning.sql
3.2.2 create learning service project
Refer to the course management service engineering structure to create learning service engineering:
 
 

<dependencies>
<!‐‐ Import Eureka Service dependency ‐‐>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring‐cloud‐starter‐netflix‐eureka‐client</artifactId>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring‐cloud‐starter‐openfeign</artifactId>
</dependency>
<dependency>
<groupId>com.netflix.feign</groupId>
<artifactId>feign‐okhttp</artifactId>
<version>8.18.0</version>
</dependency>
<dependency>
<groupId>com.xuecheng</groupId>
<artifactId>xc‐service‐api</artifactId>
<version>1.0‐SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.xuecheng</groupId>
<artifactId>xc‐framework‐model</artifactId>
<version>1.0‐SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.xuecheng</groupId>
<artifactId>xc‐framework‐utils</artifactId>
<version>1.0‐SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.xuecheng</groupId>
<artifactId>xc‐framework‐common</artifactId>
<version>1.0‐SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring‐boot‐starter‐web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql‐connector‐java</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid‐spring‐boot‐starter</artifactId>
<version>1.1.10</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis‐spring‐boot‐starter</artifactId>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper‐spring‐boot‐starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring‐orm</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring‐boot‐starter‐data‐jpa</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<dependency>
<groupId>commons‐io</groupId>
<artifactId>commons‐io</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons‐lang3</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring‐boot‐starter‐test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring‐boot‐starter‐amqp</artifactId>
</dependency>
</dependencies>
server:
port: ${PORT:40600}
spring:
application:
name: xc‐service‐learning
datasource:
druid:
url: ${MYSQL_URL:jdbc:mysql://localhost:3306/xc_learning?characterEncoding=utf‐8}
username: root
password: mysql
driverClassName: com.mysql.jdbc.Driver
initialSize: 5 #Number of initially established connections
minIdle: 5 #Minimum number of connections
maxActive: 20 #Maximum number of connections
maxWait: 10000 #Get the maximum waiting time of the connection, MS
testOnBorrow: true #Check whether the connection is valid when applying for connection
testOnReturn: false #Check whether the connection is valid when returning the connection
timeBetweenEvictionRunsMillis: 60000 #Time (in milliseconds) for configuration interval to detect whether the connection is valid
minEvictableIdleTimeMillis: 300000 #Minimum lifetime of connection in connection pool (MS)
eureka:
client:
registerWithEureka: true #Service registration switch
fetchRegistry: true #Service discovery switch
serviceUrl: #Address where Eureka client interacts with Eureka server, separated by commas
defaultZone: ${EUREKA_SERVER:http://localhost:50101/eureka/}
instance:
prefer‐ip‐address: true #Register your ip address with Eureka service
ip‐address: ${IP_ADDRESS:127.0.0.1}
instance‐id: ${spring.application.name}:${server.port} #Specify instance id
ribbon:
MaxAutoRetries: 2 #The maximum number of retries. When the service can be found in Eureka, but the service cannot be connected, it will be retried. If the service cannot be found in Eureka, it will be retried
//Go straight to the service circuit breaker
MaxAutoRetriesNextServer: 3 #Number of retries to switch instances
OkToRetryOnAllOperations: false #Retry all operation requests. If it's get, it's OK. If it's post, put, etc
//It's dangerous without idempotent, so set it to false
ConnectTimeout: 5000 #Timeout for connection request
ReadTimeout: 6000 #Timeout for request processing

Startup class:

@EnableDiscoveryClient
@EnableFeignClients
@SpringBootApplication
@EntityScan("com.xuecheng.framework.domain.learning")//Scan entity class
@ComponentScan(basePackages={"com.xuecheng.api"})//Scan interface
@ComponentScan(basePackages={"com.xuecheng.learning"})//Scan interface
@ComponentScan(basePackages={"com.xuecheng.framework"})//Scan all classes under common
public class LearningApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(LearningApplication.class, args);
}
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate(new OkHttp3ClientHttpRequestFactory());
}
}

3.3 Api interface
This api interface is the course learning page to request the learning service to obtain the course learning address.
Define return value type:

@Data
@ToString
@NoArgsConstructor
public class GetMediaResult extends ResponseResult {
public GetMediaResult(ResultCode resultCode, String fileUrl) {
super(resultCode);
this.fileUrl = fileUrl;
}
//Media file broadcast address
private String fileUrl;
}

Define the interface, and the learning service takes the learning address according to the incoming course ID and chapter ID (course plan ID).

@Api(value = "Learning management of recording and broadcasting courses",description = "Learning management of recording and broadcasting courses")
public interface CourseLearningControllerApi {
@ApiOperation("Get course learning address")
public GetMediaResult getmedia(String courseId,String teachplanId);
}

 

Published 820 original articles, won praise for 150 and received 130 thousand visits+
His message board follow

Tags: Spring MySQL snapshot Druid

Posted on Fri, 07 Feb 2020 07:37:38 -0800 by if