Initial commit

This commit is contained in:
Yo Vinchen 2022-08-28 17:57:54 +08:00
commit 1279a85007
32 changed files with 1137 additions and 0 deletions

33
.gitignore vendored Normal file
View File

@ -0,0 +1,33 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/

BIN
.mvn/wrapper/maven-wrapper.jar vendored Normal file

Binary file not shown.

2
.mvn/wrapper/maven-wrapper.properties vendored Normal file
View File

@ -0,0 +1,2 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.5/apache-maven-3.8.5-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar

71
pom.xml Normal file
View File

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.offcn.edu</groupId>
<artifactId>uxue-edu001</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>uxue-edu001</name>
<description>uxue-edu001</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--mybatis-plus-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.0.5</version>
</dependency>
<!--mysql-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!--lombok用来简化实体类-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!--swagger-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,15 @@
package com.offcn.edu;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@MapperScan("com.offcn.edu.dao")
public class UxueEdu001Application {
public static void main(String[] args) {
SpringApplication.run(UxueEdu001Application.class, args);
}
}

View File

@ -0,0 +1,35 @@
package com.offcn.edu.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.offcn.edu.controller"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("优学网后台端接口文档")
.description("优学网")
.termsOfServiceUrl("http://www.ujiuye.com/")
.contact("Vinchen")
.version("1.0")
.build();
}
}

View File

@ -0,0 +1,103 @@
package com.offcn.edu.controller;
import com.offcn.edu.pojo.Course;
import com.offcn.edu.pojo.CourseUser;
import com.offcn.edu.pojo.User;
import com.offcn.edu.service.CourseService;
import com.offcn.edu.service.CourseUserService;
import com.offcn.edu.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* <p>
* 课程表 前端控制器
* </p>
*
* @author Vinchen
* @since 2022-06-22
*/
@Api(tags = "课程操作接口")
@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/edu/course")
public class CourseController {
@Autowired
private CourseService courseService;
@Autowired
private UserService userService;
@Autowired
private CourseUserService courseUserService;
//测试读取全部课程
@GetMapping("/")
public List<Course> findAll() {
return courseService.list(null);
}
//正式接口1据题目分类编号获取对应题目前八条集合
@ApiOperation(value = "据题目分类编号获取给首页显示用的前8条对应题目集合")
@ApiImplicitParam(name = "typeId", value = "分类编号", required = true, paramType = "path")
@GetMapping("/items/{typeId}")
public List<Course> findCourseType(@PathVariable("typeId") Long typeId) {
return courseService.findCourseTypeTop8(typeId);
}
//正式接口2搜索方法
@ApiOperation(value = "题目搜索接口")
@ApiImplicitParam(name = "keyword", value = "搜索关键字", paramType = "path", required = true)
@GetMapping("/search/{keyword}")
public List<Course> search(@PathVariable("keyword") String keyword) {
return courseService.searchCourseName(keyword);
}
//正式接口3根据课程编号获取对应课程信息+课程详情集合
@ApiOperation(value = "根据课程编号,获取对应课程信息+课程详情集合")
@ApiImplicitParam(name = "id", value = "课程编号", paramType = "path", required = true)
@GetMapping("/{id}")
public Map<String, Object> findCourseInfo(@PathVariable("id") Long id) {
return courseService.findCourseInfo(id);
}
//正式接口4据题目分类编号获取对应题目全部集合
@ApiOperation(value = "据题目分类编号,获取给首页显示用的全部对应题目集合")
@ApiImplicitParam(name = "typeId", value = "分类编号", required = true, paramType = "path")
@GetMapping("/itemsall/{typeId}")
public List<Course> findCourseAll(@PathVariable("typeId") Long typeId) {
return courseService.findCourseTypeAll(typeId);
}
//根据指定用户名获取当前用户购买课程
@ApiOperation(value = "根据指定用户名,获取当前用户购买课程")
@ApiImplicitParam(name = "username", value = "用户名", required = true, paramType = "path")
@GetMapping("/user/{username}")
public List<Course> findCouseByUserName(@PathVariable("username") String username) {
List<Course> courseList = new ArrayList<>();
//调用用户服务根据用户名获取用户对象
User user = userService.findUserByUserName(username);
if (user != null) {
Integer uid = user.getUid();
List<CourseUser> courseUserList = courseUserService.findCourseUserByUid(uid);
//循环遍历集合
for (CourseUser courseUser : courseUserList) {
//根据课程编号获取对应课程信息
Course course = courseService.getById(courseUser.getCid());
courseList.add(course);
}
}
return courseList;
}
}

View File

@ -0,0 +1,82 @@
package com.offcn.edu.controller;
import com.offcn.edu.pojo.Course;
import com.offcn.edu.pojo.CourseUser;
import com.offcn.edu.pojo.User;
import com.offcn.edu.service.CourseService;
import com.offcn.edu.service.CourseUserService;
import com.offcn.edu.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
* 前端控制器
* </p>
*
* @author Vinchen
* @since 2022-06-22
*/
@Api(tags = "课程购买接口")
@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/edu/course-user")
public class CourseUserController {
@Autowired
private UserService userService;
@Autowired
private CourseService courseService;
@Autowired
private CourseUserService courseUserService;
//课程购买接口
@ApiOperation(value = "课程购买接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "cid",value = "课程编号",required = true),
@ApiImplicitParam(name = "username",value = "用户名",required = true)
})
@PostMapping("/")
public String courseSale(Integer cid, String username) {
//根据课程编号查询课程信息
Course course = courseService.getById(cid);
if (course == null) {
return "null:";
}
//根据用户名获取用户信息
User user = userService.findUserByUserName(username);
if (user == null) {
return "null";
}
//获取用户编号
Integer uid = user.getUid();
//调用用户课程服务新增用户购物记录
//先验证该用户是否购买过该课程
CourseUser courseUser1 = courseUserService.findEqualByCidUid(cid, uid);
if (courseUser1!=null){
return "error";
}
CourseUser courseUser = new CourseUser();
courseUser.setCid(cid.intValue());
courseUser.setUid(uid);
courseUserService.save(courseUser);
return "success";
}
}

View File

@ -0,0 +1,22 @@
package com.offcn.edu.controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
* 前端控制器
* </p>
*
* @author Vinchen
* @since 2022-06-22
*/
@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/edu/coursedetail")
public class CoursedetailController {
}

View File

@ -0,0 +1,77 @@
package com.offcn.edu.controller;
import com.offcn.edu.pojo.User;
import com.offcn.edu.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
/**
* <p>
* 用户表 前端控制器
* </p>
*
* @author Vinchen
* @since 2022-06-22
*/
@Api(tags = "用户操作接口")
@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/edu/user")
public class UserController {
@Autowired
private UserService userService;
//正式接口用户注册
@ApiOperation(value = "用户注册接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "phone", value = "手机号", required = true),
@ApiImplicitParam(name = "password", value = "密码", required = true),
@ApiImplicitParam(name = "repassword", value = "重复密码", required = true)
})
@PostMapping("/")
public String register(String phone, String password, String repassword) {
//判断二次输入密码是否相同
if (password != null && repassword != null && password.equals(repassword)) {
//发起注册创建用户对象
User user = new User();
user.setPhone(phone);
user.setUsername(phone);
user.setName(phone);
user.setPassword(password);
user.setCreatetime(new Date());
//调用用户服务,保存
userService.save(user);
return "成功";
} else {
return "失败";
}
}
//正式接口2用户登录接口
@ApiOperation(value = "用户登录接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "phone", value = "手机号", required = true),
@ApiImplicitParam(name = "password", value = "密码", required = true)
})
@PostMapping("/login")
public User login(String phone, String password) {
User user = userService.login(phone, password);
if (user != null) {
return user;
} else {
return null;
}
}
}

View File

@ -0,0 +1,28 @@
package com.offcn.edu.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.offcn.edu.pojo.Course;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* <p>
* 课程表 Mapper 接口
* </p>
*
* @author Vinchen
* @since 2022-06-22
*/
public interface CourseMapper extends BaseMapper<Course> {
//定义一个方法根据指定课程类型获取课程列表
List<Course> findCourseTypeTop8(@Param("typeId") Long typeId);
//定义搜索方法根据课程名称:搜索关键字
List<Course> searchCourseName(@Param("keyword") String keyword);
//定义一个方法根据指定课程类型全部课程列表
List<Course> findCourseTypeAll(@Param("typeId") Long typeId);
}

View File

@ -0,0 +1,25 @@
package com.offcn.edu.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.offcn.edu.pojo.CourseUser;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* <p>
* Mapper 接口
* </p>
*
* @author Vinchen
* @since 2022-06-22
*/
public interface CourseUserMapper extends BaseMapper<CourseUser> {
//查询用户是否购买过课程
CourseUser findEqualByCidUid(@Param("cid") Integer cid, @Param("uid") Integer uid);
//根据uid获取对应购买课程集合
List<CourseUser> findCourseUserByUid(@Param("uid") Integer uid);
}

View File

@ -0,0 +1,20 @@
package com.offcn.edu.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.offcn.edu.pojo.Coursedetail;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* <p>
* Mapper 接口
* </p>
*
* @author Vinchen
* @since 2022-06-22
*/
public interface CoursedetailMapper extends BaseMapper<Coursedetail> {
//根据课程编号 cid获取对应课程详情集合
List<Coursedetail> findAllByCidCoursedetails(@Param("cid") Long cid);
}

View File

@ -0,0 +1,23 @@
package com.offcn.edu.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.offcn.edu.pojo.User;
import org.apache.ibatis.annotations.Param;
/**
* <p>
* 用户表 Mapper 接口
* </p>
*
* @author Vinchen
* @since 2022-06-22
*/
public interface UserMapper extends BaseMapper<User> {
//用户登录方法
User login(@Param("phone") String phone, @Param("password") String password);
//根据登录用户名获取用户信息
User getUserByUsername(@Param("username") String username);
}

View File

@ -0,0 +1,67 @@
package com.offcn.edu.pojo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
* <p>
* 课程表
* </p>
*
* @author Vinchen
* @since 2022-06-22
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="Course对象", description="课程表")
public class Course implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "课程编号")
@TableId(value = "cid", type = IdType.AUTO)
private Integer cid;
@ApiModelProperty(value = "课程名称")
@TableField("courseName")
private String courseName;
@ApiModelProperty(value = "课程简介")
private String descs;
@ApiModelProperty(value = "课程类型")
@TableField("courseType")
private Integer courseType;
@ApiModelProperty(value = "课程图片地址")
@TableField("courseImage")
private String courseImage;
@ApiModelProperty(value = "课程视频地址")
@TableField("courseVideo")
private String courseVideo;
@ApiModelProperty(value = "价格")
@TableField("coursePrice")
private BigDecimal coursePrice;
@ApiModelProperty(value = "状态")
private Integer status;
@ApiModelProperty(value = "上传时间")
@TableField("createTime")
private Date createTime;
}

View File

@ -0,0 +1,36 @@
package com.offcn.edu.pojo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* <p>
*
* </p>
*
* @author Vinchen
* @since 2022-06-22
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="CourseUser对象", description="")
public class CourseUser implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
private Integer cid;
private Integer uid;
}

View File

@ -0,0 +1,42 @@
package com.offcn.edu.pojo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* <p>
*
* </p>
*
* @author Vinchen
* @since 2022-06-22
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="Coursedetail对象", description="")
public class Coursedetail implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
private String name;
private String type;
private String url;
private String startData;
private Integer cid;
}

View File

@ -0,0 +1,65 @@
package com.offcn.edu.pojo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
* 用户表
* </p>
*
* @author Vinchen
* @since 2022-06-22
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="User对象", description="用户表")
public class User implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "学员编号")
@TableId(value = "uid", type = IdType.AUTO)
private Integer uid;
@ApiModelProperty(value = "真实姓名")
private String name;
@ApiModelProperty(value = "手机号")
private String phone;
@ApiModelProperty(value = "年龄")
private Integer age;
@ApiModelProperty(value = "性别")
private Integer sex;
@ApiModelProperty(value = "账号")
private String username;
@ApiModelProperty(value = "密码")
private String password;
@ApiModelProperty(value = "状态")
private Integer status;
@ApiModelProperty(value = "注册时间")
private Date createtime;
@ApiModelProperty(value = "角色")
private Integer role;
@ApiModelProperty(value = "头像")
private String picture;
}

View File

@ -0,0 +1,31 @@
package com.offcn.edu.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.offcn.edu.pojo.Course;
import java.util.List;
import java.util.Map;
/**
* <p>
* 课程表 服务类
* </p>
*
* @author Vinchen
* @since 2022-06-22
*/
public interface CourseService extends IService<Course> {
//根据题目分类编号获取对应题目前8条集合
List<Course> findCourseTypeTop8(Long typeId);
//根据课程名称:搜索关键字
List<Course> searchCourseName(String keyword);
//根据课程编号获取课程信息和对应课程详情集合
Map<String, Object> findCourseInfo(Long id);
//根据题目分类编号获取对应题目全部集合
List<Course> findCourseTypeAll(Long typeId);
}

View File

@ -0,0 +1,24 @@
package com.offcn.edu.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.offcn.edu.pojo.CourseUser;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* <p>
* 服务类
* </p>
*
* @author Vinchen
* @since 2022-06-22
*/
public interface CourseUserService extends IService<CourseUser> {
//根据用户编号和课程编号验证是否购买过该课程
CourseUser findEqualByCidUid(Integer cid,Integer uid);
List<CourseUser> findCourseUserByUid(Integer uid);
}

View File

@ -0,0 +1,16 @@
package com.offcn.edu.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.offcn.edu.pojo.Coursedetail;
/**
* <p>
* 服务类
* </p>
*
* @author Vinchen
* @since 2022-06-22
*/
public interface CoursedetailService extends IService<Coursedetail> {
}

View File

@ -0,0 +1,20 @@
package com.offcn.edu.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.offcn.edu.pojo.User;
/**
* <p>
* 用户表 服务类
* </p>
*
* @author Vinchen
* @since 2022-06-22
*/
public interface UserService extends IService<User> {
//调用登录
User login(String phone,String password);
//根据username获取用户信息
User findUserByUserName(String username);
}

View File

@ -0,0 +1,60 @@
package com.offcn.edu.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.offcn.edu.dao.CourseMapper;
import com.offcn.edu.dao.CoursedetailMapper;
import com.offcn.edu.pojo.Course;
import com.offcn.edu.pojo.Coursedetail;
import com.offcn.edu.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* <p>
* 课程表 服务实现类
* </p>
*
* @author Vinchen
* @since 2022-06-22
*/
@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements CourseService {
@Autowired
private CoursedetailMapper coursedetailMapper;
@Override
public List<Course> findCourseTypeTop8(Long typeId) {
return this.baseMapper.findCourseTypeTop8(typeId);
}
@Override
public List<Course> searchCourseName(String keyword) {
return this.baseMapper.searchCourseName(keyword);
}
@Override
public Map<String, Object> findCourseInfo(Long id) {
Map<String, Object> map=new HashMap<>();
//调用课程数据访问接口根据课程id获取课程信息
Course course = this.baseMapper.selectById(id);
//根据课程编号去查询对应课程详情集合数据
List<Coursedetail> coursedetailList = coursedetailMapper.findAllByCidCoursedetails(id);
//把获取到数据封装到map
map.put("course",course);
map.put("coursedetailList",coursedetailList);
return map;
}
@Override
public List<Course> findCourseTypeAll(Long typeId){
return this.baseMapper.findCourseTypeAll(typeId);
}
}

View File

@ -0,0 +1,31 @@
package com.offcn.edu.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.offcn.edu.dao.CourseUserMapper;
import com.offcn.edu.pojo.CourseUser;
import com.offcn.edu.service.CourseUserService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 服务实现类
* </p>
*
* @author Vinchen
* @since 2022-06-22
*/
@Service
public class CourseUserServiceImpl extends ServiceImpl<CourseUserMapper, CourseUser> implements CourseUserService {
@Override
public CourseUser findEqualByCidUid(Integer cid,Integer uid){
return this.baseMapper.findEqualByCidUid(cid,uid);
}
@Override
public List<CourseUser> findCourseUserByUid(Integer cid) {
return this.baseMapper.findCourseUserByUid(cid);
}
}

View File

@ -0,0 +1,20 @@
package com.offcn.edu.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.offcn.edu.dao.CoursedetailMapper;
import com.offcn.edu.pojo.Coursedetail;
import com.offcn.edu.service.CoursedetailService;
import org.springframework.stereotype.Service;
/**
* <p>
* 服务实现类
* </p>
*
* @author Vinchen
* @since 2022-06-22
*/
@Service
public class CoursedetailServiceImpl extends ServiceImpl<CoursedetailMapper, Coursedetail> implements CoursedetailService {
}

View File

@ -0,0 +1,31 @@
package com.offcn.edu.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.offcn.edu.dao.UserMapper;
import com.offcn.edu.pojo.User;
import com.offcn.edu.service.UserService;
import org.springframework.stereotype.Service;
/**
* <p>
* 用户表 服务实现类
* </p>
*
* @author Vinchen
* @since 2022-06-22
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
@Override
public User login(String phone, String password) {
return this.baseMapper.login(phone, password);
}
@Override
public User findUserByUserName(String username) {
return this.baseMapper.getUserByUsername(username);
}
}

View File

@ -0,0 +1,20 @@
server:
port: 8001
spring:
application:
name: uxue-edu
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/cangzhou001?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8
username: root
password: 8520
jackson:
time-zone: GMT%2B
date-format: yyyy-MM-dd HH:mm:ss
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
mapper-locations: classpath:mapper/*.xml #??mybatis????????
type-aliases-package: com.offcn.edu.pojo #????????

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.offcn.edu.dao.CourseMapper">
<select id="findCourseTypeTop8" resultType="com.offcn.edu.pojo.Course">
select *
from course
where courseType = #{typeId}
and status = 1 limit 0,8
</select>
<select id="searchCourseName" resultType="com.offcn.edu.pojo.Course">
select *
from course
where courseName like '%${keyword}%'
</select>
<select id="findCourseTypeAll" resultType="com.offcn.edu.pojo.Course">
select *
from course
where courseType = #{typeId}
and status = 1
</select>
</mapper>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.offcn.edu.dao.CourseUserMapper">
<select id="findEqualByCidUid" resultType="com.offcn.edu.pojo.CourseUser">
select *
from course_user
where cid = #{cid}
and uid = #{uid} limit 0,1
</select>
<select id="findCourseUserByUid" resultType="com.offcn.edu.pojo.CourseUser">
select *
from course_user
where uid = #{uid}
</select>
</mapper>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.offcn.edu.dao.CoursedetailMapper">
<select id="findAllByCidCoursedetails" resultType="com.offcn.edu.pojo.Coursedetail">
select *
from coursedetail
where cid = #{cid}
</select>
</mapper>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.offcn.edu.dao.UserMapper">
<select id="login" resultType="com.offcn.edu.pojo.User">
select *
from user
where phone = #{phone}
and password = #{password} limit 0,1
</select>
<select id="getUserByUsername" resultType="com.offcn.edu.pojo.User">
select *
from user
where username = #{username} limit 0,1
</select>
</mapper>

View File

@ -0,0 +1,71 @@
package com.offcn.edu;
import com.offcn.edu.dao.CourseMapper;
import com.offcn.edu.dao.CoursedetailMapper;
import com.offcn.edu.dao.UserMapper;
import com.offcn.edu.pojo.Course;
import com.offcn.edu.pojo.Coursedetail;
import com.offcn.edu.pojo.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.List;
@SpringBootTest
class UxueEdu001ApplicationTests {
@Autowired
private CourseMapper courseMapper;
@Autowired
private CoursedetailMapper coursedetailMapper;
@Autowired
private UserMapper userMapper;
//测试首页展示方法
@Test
void testfindCourseType() {
List<Course> courseList = courseMapper.findCourseTypeTop8(2L);
for (Course course : courseList) {
System.out.println(course);
}
}
//测试课程搜索方法
@Test
public void testSearch(){
String keyword="Java";
List<Course> courseList = courseMapper.searchCourseName(keyword);
for (Course course : courseList) {
System.out.println(course);
}
}
//测试根据课程id获取课程信息
@Test
public void testGetCourseByID(){
Course course = courseMapper.selectById(1);
System.out.println(course);
}
//测试根据cid获取对应课程详情集合
@Test
public void testfindAllByCidCoursedetails(){
List<Coursedetail> coursedetailList = coursedetailMapper.findAllByCidCoursedetails(3L);
for (Coursedetail coursedetail : coursedetailList) {
System.out.println(coursedetail);
}
}
//测试登录
@Test
public void testLogin(){
User login = userMapper.login("13515823698", "123");
System.out.println(login);
}
}