增加删除,返回用户信息接口
This commit is contained in:
@@ -2,11 +2,11 @@ package com.backend.webbackend.Controller;
|
||||
|
||||
import com.backend.webbackend.Service.courseService;
|
||||
import com.backend.webbackend.Vo.ResultVo;
|
||||
import com.backend.webbackend.domain.Course;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("course")
|
||||
@@ -14,6 +14,9 @@ public class CourseController {
|
||||
@Autowired
|
||||
private courseService courseService;
|
||||
|
||||
@Value("${app.courseLoadPath}")
|
||||
private String courseLoadPath;
|
||||
|
||||
// 返回课程信息
|
||||
@GetMapping("getAll")
|
||||
public ResultVo getAllCourses() {
|
||||
@@ -26,21 +29,29 @@ public class CourseController {
|
||||
return ResultVo.Success("", courseService.getCourseResources());
|
||||
}
|
||||
|
||||
//返回课程类型信息
|
||||
@GetMapping("getCourseTypes")
|
||||
public ResultVo getAllCourseTypes() {
|
||||
return ResultVo.Success("", courseService.getAllCourseTypes());
|
||||
}
|
||||
|
||||
//新增课程信息
|
||||
@PostMapping("addCourse")
|
||||
public ResultVo addCourse() {
|
||||
return ResultVo.Success("", "新增课程成功");
|
||||
@PostMapping(value = "addCourse", consumes = "multipart/form-data")
|
||||
public ResultVo addCourse(@ModelAttribute Course course, @RequestPart(name = "icoFile",required = false)MultipartFile icoFile) {
|
||||
try {
|
||||
if(courseService.addCourse(course,icoFile)>0)
|
||||
return ResultVo.Success("", "新增课程信息成功");
|
||||
else
|
||||
return ResultVo.Error("", "新增课程信息失败");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("新增课程信息失败!!!!!!");
|
||||
}
|
||||
}
|
||||
|
||||
//新增课程资源
|
||||
@PostMapping("addCourseResource")
|
||||
public ResultVo addCourseResource() {
|
||||
|
||||
return ResultVo.Success("", "新增课程资源成功");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,13 @@ public class userController {
|
||||
return ResultVo.Success("",userService.getAlldept());
|
||||
}
|
||||
|
||||
//返回全部用户信息
|
||||
@GetMapping("allUsers")
|
||||
public ResultVo getAllUsers(){
|
||||
return ResultVo.Success("",userService.getAllUsers());
|
||||
}
|
||||
|
||||
|
||||
//用户注册
|
||||
@PostMapping("register")
|
||||
public ResultVo register(@RequestBody User user){
|
||||
@@ -35,8 +42,8 @@ public class userController {
|
||||
}
|
||||
|
||||
//用户登录
|
||||
@PostMapping("login")
|
||||
public ResultVo login(@RequestBody User user) {
|
||||
@PostMapping(value = "login")
|
||||
public ResultVo login(@ModelAttribute User user) {
|
||||
if(!userService.login(user.getUsername(),user.getPassword())){
|
||||
return ResultVo.Error("","用户名或密码错误");
|
||||
}
|
||||
@@ -54,8 +61,18 @@ public class userController {
|
||||
return ResultVo.Success("","用户信息修改成功");
|
||||
}
|
||||
catch (Exception e){
|
||||
System.out.println(e.getMessage());
|
||||
throw new RuntimeException("用户信息修改失败!!!!!!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("deleteUser")
|
||||
public ResultVo deleteTest(@Param("id") Long id) {
|
||||
if(userService.deleteUserById(id) == 1){
|
||||
return ResultVo.Success("", "用户删除成功");
|
||||
}else {
|
||||
return ResultVo.Error("", "用户删除失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.backend.webbackend.mapper.CourseTypeMapper;
|
||||
import com.backend.webbackend.mapper.TrainingResourceMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -32,6 +33,7 @@ public class courseServiceImpl implements com.backend.webbackend.Service.courseS
|
||||
return trainingResourceMapper.getAllTraningResources();
|
||||
}
|
||||
|
||||
//返回课程类型信息
|
||||
@Override
|
||||
public List<CourseType> getAllCourseTypes() {
|
||||
return courseTypeMapper.selectAllCourseTypes();
|
||||
@@ -39,11 +41,8 @@ public class courseServiceImpl implements com.backend.webbackend.Service.courseS
|
||||
|
||||
//新增课程信息
|
||||
@Override
|
||||
public int addCourse(Course course) {
|
||||
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
public int addCourse(Course course, MultipartFile icoFile) {
|
||||
//如果有上传文件,先保存文件至服务器磁盘
|
||||
return courseMapper.insertCourse(course);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,4 +83,16 @@ public class userServiceImpl implements userService {
|
||||
public int updateUserInfo(User user){
|
||||
return userMapper.updateByName(user);
|
||||
}
|
||||
|
||||
//返回全部用户信息
|
||||
@Override
|
||||
public List<User> getAllUsers() {
|
||||
return userMapper.getAllUsers();
|
||||
}
|
||||
|
||||
//删除用户
|
||||
@Override
|
||||
public int deleteUserById(Long id) {
|
||||
return userMapper.deleteByPrimaryKey(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.backend.webbackend.domain.Course;
|
||||
import com.backend.webbackend.domain.CourseType;
|
||||
import com.backend.webbackend.domain.TrainingResource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -12,5 +13,5 @@ public interface courseService {
|
||||
List<Course> getAllCourseInfo();
|
||||
List<TrainingResource> getCourseResources();
|
||||
List<CourseType>getAllCourseTypes();
|
||||
int addCourse(Course course);
|
||||
int addCourse(Course course, MultipartFile icoFile);
|
||||
}
|
||||
|
||||
@@ -14,4 +14,8 @@ public interface userService {
|
||||
boolean login(String username, String password);
|
||||
List<Dept> getAlldept();
|
||||
int updateUserInfo(User user);
|
||||
|
||||
List<User> getAllUsers();
|
||||
|
||||
int deleteUserById(Long id);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import com.backend.webbackend.mapper.UserMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -49,4 +50,10 @@ public class Tools {
|
||||
}
|
||||
return PASSWORD_ENCODER.matches(rawPassword, encodedPassword);
|
||||
}
|
||||
|
||||
//文件保存
|
||||
public String saveIcoFile(MultipartFile icoFile){
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,12 +10,16 @@ import lombok.Data;
|
||||
public class Course {
|
||||
private Long id;
|
||||
|
||||
@JsonProperty("course_name")
|
||||
private String courseName;
|
||||
|
||||
@JsonProperty("course_code")
|
||||
private String courseCode;
|
||||
|
||||
@JsonProperty("course_desc")
|
||||
private String courseDesc;
|
||||
|
||||
@JsonProperty("course_category")
|
||||
private String courseCategory;
|
||||
|
||||
@JsonProperty("course_ico")
|
||||
|
||||
@@ -26,4 +26,5 @@ public interface CourseMapper {
|
||||
|
||||
int updateByPrimaryKey(Course record);
|
||||
|
||||
int insertCourse(Course course);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.backend.webbackend.mapper;
|
||||
import com.backend.webbackend.domain.User;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Quella
|
||||
* @description 针对表【user(用户表)】的数据库操作Mapper
|
||||
@@ -30,4 +32,6 @@ public interface UserMapper {
|
||||
int updateById(User user);
|
||||
|
||||
int updateByName(User user);
|
||||
|
||||
List<User> getAllUsers();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user