作者主页:Java毕设网
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
一、项目介绍
后端技术包含springboot+mybatis+spring security+mysql+redis
前端技术包含 semanticUI + thymeleaf模板引擎
二、环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.是否Maven项目: 是;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
6.数据库:MySql 5.7版本;
三、技术栈
1. 后端:SpringBoot
2. 前端:Thymeleaf+html+layui+jQuery+bootstrap
四、使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 将项目中application.yml及activiti.cfg.xml配置文件中的数据库配置改为自己的配置;
3. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,配置tomcat,然后运行;
4. 运行项目,输入localhost:8085 登录
五、运行截图
六、相关代码
学生选课控制器
@RestController
@RequestMapping("usercourse")
@Api
public class UserCourseController{
@Autowired
UserCourseService userCourseService;
@Autowired
SelectableCourseDAO selectableCourseDAO;
/**
* 选课
* @param courseId
* @param username
* @return
*/
@PostMapping("choose")
@PreAuthorize("hasAuthority('student')")
public Object chooseCourse(@RequestParam("courseId") Integer courseId ,
@RequestParam("username") String username){
Map<String,Object> map = new HashMap<>();
try{
return userCourseService.chooseCourse(courseId , username);
}catch(Exception e){
if(e instanceof DataIntegrityViolationException){
map.put("msg","该课程已经被抢完啦。");
}else{
map.put("msg","出现其他异常,选课失败!");
}
map.put("flag",false);
return JSON.toJSON(map);
}
}
/**
* 退课
* @param courseId
* @param username
* @return
*/
@PostMapping("cancel")
@PreAuthorize("hasAuthority('student')")
public Object cancelCourse(@RequestParam("courseId") Integer courseId ,
@RequestParam("username") String username){
return userCourseService.cancelCourse(courseId,username);
}
/**
* 获取学生所选全部课程
* @param page
* @param limit
* @param username
* @return
*/
@PostMapping("studentInfo")
@PreAuthorize("hasAuthority('admin') or hasAuthority('student')")
public Object studentInfo(@RequestParam(value = "page", defaultValue = "1") int page ,
@RequestParam(value = "limit", defaultValue = "10") int limit ,
@RequestParam("username")String username){
try{
Map<String,Object> map = new HashMap<>();
PageHelper.startPage(page , limit);
List<SelectableCourse> list = selectableCourseDAO.selectByUser(username);
if(list == null){
return Msg.fail();
}
//System.out.println("=="+username+"==");
PageInfo<SelectableCourse> pageInfo = new PageInfo<>(list);
map.put("totalPage" , pageInfo.getPages()); //总页数
map.put("totalCount" , pageInfo.getTotal()); //总条数
map.put("currentPage" , page); //当前页数。
map.put("data" , pageInfo.getList()); //获得的数据量
map.put("tCase",username);
return JSON.toJSON(map);
}catch(Exception e){
e.printStackTrace();
return Msg.fail();
}
}
//测试。
@PostMapping("cc")
public Object cc(){
Map<String,Object> map = new HashMap<>();
try{
selectableCourseDAO.updateMinCourseStock(1);
return true;
}catch(Exception e){
if(e instanceof DataIntegrityViolationException){
map.put("msg","该课程已经被抢完啦。");
}else{
map.put("msg","出现其他异常,选课失败!");
}
map.put("flag",false);
return JSON.toJSON(map);
}
}
}
课程检索控制器
@RestController
@RequestMapping("/course")
@Api
public class SelectableCourseController{
@Autowired
SelectableCourseService selectableCourseService;
/**
* 获得全部课程
* @param page
* @param limit
* @param username
* @return
*/
@PostMapping("/getAll")
public Object getAll(@RequestParam(value = "page", defaultValue = "1") int page ,
@RequestParam(value = "limit", defaultValue = "10") int limit ,
@RequestParam(value = "username", required = false) String username){
return selectableCourseService.selectAll(page,limit,username);
}
/**
* 根据课程类别搜索课程
* @param page
* @param limit
* @param username
* @param type
* @return
*/
@PostMapping("/getCourseByType")
public Object getCourseByType(@RequestParam(value = "page", defaultValue = "1") int page ,
@RequestParam(value = "limit", defaultValue = "10") int limit ,
@RequestParam(value = "username", required = false) String username ,
@RequestParam("courseType") String type){
return selectableCourseService.selectCoursesByType(page,limit,type , username);
}
/**
* 根据课程所属学院名称搜索课程
* @param page
* @param limit
* @param username
* @param name
* @return
*/
@PostMapping("/getCourseByCollege")
public Object getCourseByCollege(@RequestParam(value = "page", defaultValue = "1") int page ,
@RequestParam(value = "limit", defaultValue = "10") int limit ,
@RequestParam(value = "username", required = false) String username ,
@RequestParam("college") String name){
return selectableCourseService.selectCoursesByCollege(page,limit,name , username);
}
/**
* 根据课程名称模糊搜索课程
* @param page
* @param limit
* @param username
* @param courseName
* @return
*/
@PostMapping("selectByCourseName")
public Object selectByCourseName(@RequestParam(value = "page", defaultValue = "1") int page ,
@RequestParam(value = "limit", defaultValue = "10") int limit ,
@RequestParam(value = "username", required = false) String username ,
@RequestParam("courseName") String courseName){
return selectableCourseService.selectByCourseName(page,limit,courseName , username);
}
/**
* 根据课程剩余人数查找课程
* @param page
* @param limit
* @param username
* @param count
* @return
*/
@PostMapping("selectCourseByMemberCount")
public Object selectByMemberCount(@RequestParam(value = "page", defaultValue = "1") int page ,
@RequestParam(value = "limit", defaultValue = "10") int limit ,
@RequestParam(value = "username", required = false) String username ,
@RequestParam("count") Integer count){
return selectableCourseService.selectCoursesByMemberCount(page,limit,count,username);
}
/**
* 隐藏课程
* @param courseId
* @return
*/
@PostMapping("hideBatch")
@PreAuthorize("hasAuthority('admin')")
public Object hideBatch(Integer courseId){
try{
return selectableCourseService.hideBatch(courseId);
}catch(Exception e){
return Msg.msg("操作异常!");
}
}
@PostMapping("/addCourseByAdmin")
@PreAuthorize("hasAuthority('admin')")
public Object addCourse(@RequestParam("courseName")String courseName,
@RequestParam("courseType")String courseType,
@RequestParam("collegeId")Integer collegeId,
@RequestParam("teacher")String teacher,
@RequestParam("score")Integer score,
@RequestParam("stock")Integer stock,
@RequestParam("address")String address,
@RequestParam(value = "description",defaultValue = "")String description){
try{
return selectableCourseService.addCourse(courseName,collegeId,courseType,teacher,score,stock,address,description);
}catch(Exception e){
e.printStackTrace();
return Msg.msg("出现异常,添加课程失败!");
}
}
}