课程删除、增加基本完成
Signed-off-by: Chenx221 <chenx221@yandex.com>
This commit is contained in:
parent
d4e571936e
commit
cc471c1478
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -35,4 +35,19 @@
|
|||||||
</trim>
|
</trim>
|
||||||
WHERE CourseID = #{courseID}
|
WHERE CourseID = #{courseID}
|
||||||
</update>
|
</update>
|
||||||
|
<select id="getCourseById" parameterType="int" resultType="cyou.chenx221.pojo.Course">
|
||||||
|
SELECT *
|
||||||
|
FROM course
|
||||||
|
WHERE CourseID = #{id}
|
||||||
|
AND removed = 0
|
||||||
|
</select>
|
||||||
|
<update id="deleteCourse" parameterType="int">
|
||||||
|
UPDATE course
|
||||||
|
SET removed = 1
|
||||||
|
WHERE CourseID = #{id}
|
||||||
|
</update>
|
||||||
|
<insert id="insertCourse" parameterType="cyou.chenx221.pojo.Course">
|
||||||
|
INSERT INTO course (CourseName, Description)
|
||||||
|
VALUES (#{courseName}, #{description})
|
||||||
|
</insert>
|
||||||
</mapper>
|
</mapper>
|
@ -10,7 +10,6 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
import java.sql.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@ -42,43 +41,39 @@ public class CourseController {
|
|||||||
return "courseopv2";
|
return "courseopv2";
|
||||||
}
|
}
|
||||||
|
|
||||||
// @PostMapping(value = "/delinfo", produces = "application/x-www-form-urlencoded;charset=UTF-8")
|
@PostMapping(value = "/delinfo", produces = "application/x-www-form-urlencoded;charset=UTF-8")
|
||||||
// public String UpdateModInfo(@RequestParam(value = "id") int id,
|
public String UpdateModInfo(@RequestParam(value = "id") int id,
|
||||||
// Model model) {
|
Model model) {
|
||||||
// Student temp = studentService.getStudentById(id);
|
Course temp = courseService.getCourseById(id);
|
||||||
// if (id <= 0 || temp == null) {
|
if (id <= 0 || temp == null) {
|
||||||
// model.addAttribute("errorMessage", "学生信息删除失败,可能是ID非法或者学生已删除");
|
model.addAttribute("errorMessage", "学生信息删除失败,可能是ID非法或者学生已删除");
|
||||||
// } else {
|
} else {
|
||||||
//// Student student = new Student(id);
|
int status_code = courseService.deleteCourse(id);
|
||||||
// studentService.deleteStudent(id);
|
if (status_code == 1) {
|
||||||
// model.addAttribute("successMessage", "学生信息删除成功");
|
model.addAttribute("successMessage", "学生信息删除成功");
|
||||||
// }
|
} else if (status_code == 0) {
|
||||||
// return "redirect:/student/infomodv2";
|
model.addAttribute("errorMessage", "学生信息删除失败,可能是ID非法或者学生已删除");
|
||||||
// }
|
} else {
|
||||||
//
|
model.addAttribute("errorMessage", "学生信息删除异常");
|
||||||
// @PostMapping(value = "/addinfo", produces = "application/x-www-form-urlencoded;charset=UTF-8")
|
System.out.println("DEBUG:异常删除,多条记录被删除");
|
||||||
// public String InsertStudentInfo(@RequestParam(value = "name") String name,
|
}
|
||||||
// @RequestParam(value = "birthday") Date birthday,
|
}
|
||||||
// @RequestParam(value = "sex") String sex,
|
return "redirect:/course/infomodv2";
|
||||||
// @RequestParam(value = "phone") String phone,
|
}
|
||||||
// @RequestParam(value = "classes") String classes,
|
|
||||||
// Model model) {
|
//
|
||||||
// Student student;
|
@PostMapping(value = "/addinfo", produces = "application/x-www-form-urlencoded;charset=UTF-8")
|
||||||
// String classesPattern = "[1-5]班";// 使用正则表达式验证班级格式
|
public String InsertCourseInfo(@RequestParam(value = "name", defaultValue = "null", required = false) String name,
|
||||||
//
|
@RequestParam(value = "description", defaultValue = "null", required = false) String description,
|
||||||
// //格式合法性检查
|
Model model) {
|
||||||
// if (!sex.equals("男") && !sex.equals("女")) {
|
Course course;
|
||||||
// model.addAttribute("errorMessage", "性别格式不正确,仅允许'男'或'女'");
|
course = new Course(name, description);
|
||||||
// } else if (!classes.matches(classesPattern)) {
|
courseService.insertCourse(course);
|
||||||
// model.addAttribute("errorMessage", "班级格式不正确,格式应为?班(?为1~5之间的数字)");
|
model.addAttribute("successMessage", "学生信息添加成功");
|
||||||
// } else {
|
return "redirect:/course/infomodv2";
|
||||||
// student = new Student(name, sex, birthday, phone, classes);
|
}
|
||||||
// studentService.insertStudent(student);
|
|
||||||
// model.addAttribute("successMessage", "学生信息添加成功");
|
//
|
||||||
// }
|
|
||||||
// return "redirect:/student/infomodv2";
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
@PostMapping(value = "/modinfo", produces = "application/x-www-form-urlencoded;charset=UTF-8")
|
@PostMapping(value = "/modinfo", produces = "application/x-www-form-urlencoded;charset=UTF-8")
|
||||||
public String UpdateModInfo(@RequestParam(value = "name", defaultValue = "null", required = false) String name,
|
public String UpdateModInfo(@RequestParam(value = "name", defaultValue = "null", required = false) String name,
|
||||||
@RequestParam(value = "description", defaultValue = "null", required = false) String description,
|
@RequestParam(value = "description", defaultValue = "null", required = false) String description,
|
||||||
@ -93,11 +88,11 @@ public class CourseController {
|
|||||||
} else {
|
} else {
|
||||||
course = new Course(id, name, description);
|
course = new Course(id, name, description);
|
||||||
int status_code = courseService.updateCourse(course);
|
int status_code = courseService.updateCourse(course);
|
||||||
if(status_code==1){
|
if (status_code == 1) {
|
||||||
model.addAttribute("successMessage", "课程信息修改成功");
|
model.addAttribute("successMessage", "课程信息修改成功");
|
||||||
}else if(status_code==0) {
|
} else if (status_code == 0) {
|
||||||
model.addAttribute("errorMessage", "课程信息修改失败,可能是ID非法或者课程不存在");
|
model.addAttribute("errorMessage", "课程信息修改失败,可能是ID非法或者课程不存在");
|
||||||
}else{
|
} else {
|
||||||
model.addAttribute("errorMessage", "课程信息修改异常");
|
model.addAttribute("errorMessage", "课程信息修改异常");
|
||||||
System.out.println("DEBUG:课程信息修改异常,存在多条记录被修改的情况");
|
System.out.println("DEBUG:课程信息修改异常,存在多条记录被修改的情况");
|
||||||
}
|
}
|
||||||
|
@ -12,4 +12,10 @@ public interface CourseDao {
|
|||||||
List<Course> getQueryCourses(Course course);
|
List<Course> getQueryCourses(Course course);
|
||||||
|
|
||||||
int updateCourse(Course course);
|
int updateCourse(Course course);
|
||||||
|
|
||||||
|
Course getCourseById(int id);
|
||||||
|
|
||||||
|
int deleteCourse(int id);
|
||||||
|
|
||||||
|
void insertCourse(Course course);
|
||||||
}
|
}
|
||||||
|
@ -30,4 +30,19 @@ public class CourseDaoImpl implements CourseDao {
|
|||||||
public int updateCourse(Course course) {
|
public int updateCourse(Course course) {
|
||||||
return sqlSession.update("updateCourse", course);
|
return sqlSession.update("updateCourse", course);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Course getCourseById(int id) {
|
||||||
|
return sqlSession.selectOne("getCourseById", id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int deleteCourse(int id) {
|
||||||
|
return sqlSession.delete("deleteCourse", id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void insertCourse(Course course) {
|
||||||
|
sqlSession.insert("insertCourse", course);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,4 +27,16 @@ public class CourseService {
|
|||||||
public int updateCourse(Course course) {
|
public int updateCourse(Course course) {
|
||||||
return courseDao.updateCourse(course);
|
return courseDao.updateCourse(course);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Course getCourseById(int id) {
|
||||||
|
return courseDao.getCourseById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int deleteCourse(int id) {
|
||||||
|
return courseDao.deleteCourse(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void insertCourse(Course course) {
|
||||||
|
courseDao.insertCourse(course);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,4 +35,19 @@
|
|||||||
</trim>
|
</trim>
|
||||||
WHERE CourseID = #{courseID}
|
WHERE CourseID = #{courseID}
|
||||||
</update>
|
</update>
|
||||||
|
<select id="getCourseById" parameterType="int" resultType="cyou.chenx221.pojo.Course">
|
||||||
|
SELECT *
|
||||||
|
FROM course
|
||||||
|
WHERE CourseID = #{id}
|
||||||
|
AND removed = 0
|
||||||
|
</select>
|
||||||
|
<update id="deleteCourse" parameterType="int">
|
||||||
|
UPDATE course
|
||||||
|
SET removed = 1
|
||||||
|
WHERE CourseID = #{id}
|
||||||
|
</update>
|
||||||
|
<insert id="insertCourse" parameterType="cyou.chenx221.pojo.Course">
|
||||||
|
INSERT INTO course (CourseName, Description)
|
||||||
|
VALUES (#{courseName}, #{description})
|
||||||
|
</insert>
|
||||||
</mapper>
|
</mapper>
|
@ -298,7 +298,7 @@
|
|||||||
<div class="row mb-2">
|
<div class="row mb-2">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<div class="form-outline">
|
<div class="form-outline">
|
||||||
<input type="text" id="typeText14" class="form-control"
|
<input type="text" id="typeText14" class="form-control" required
|
||||||
name="name"/>
|
name="name"/>
|
||||||
<label class="form-label" for="typeText14">课程名 (必填)</label>
|
<label class="form-label" for="typeText14">课程名 (必填)</label>
|
||||||
</div>
|
</div>
|
||||||
@ -307,7 +307,7 @@
|
|||||||
<div class="row mb-2">
|
<div class="row mb-2">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<div class="form-outline">
|
<div class="form-outline">
|
||||||
<input type="text" id="typeText15" class="form-control"
|
<input type="text" id="typeText15" class="form-control" required
|
||||||
name="description"/>
|
name="description"/>
|
||||||
<label class="form-label" for="typeText15">课程描述 (必填)</label>
|
<label class="form-label" for="typeText15">课程描述 (必填)</label>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user