CourseInfo修改基本完成

Signed-off-by: Chenx221 <chenx221@yandex.com>
This commit is contained in:
Chenx221 2023-06-11 10:42:02 +08:00
parent 9c50926a51
commit d4e571936e
12 changed files with 68 additions and 44 deletions

View File

@ -22,5 +22,17 @@
AND Description LIKE CONCAT('%', #{description}, '%')
</if>
</select>
<update id="updateCourse" parameterType="cyou.chenx221.pojo.Course">
UPDATE course
SET
<trim suffixOverrides=",">
<if test="courseName != null">
CourseName = #{courseName},
</if>
<if test="description != null">
Description = #{description},
</if>
</trim>
WHERE CourseID = #{courseID}
</update>
</mapper>

View File

@ -197,7 +197,7 @@
<div class="form-outline">
<input type="text" id="typeText2" class="form-control"
name="name"/>
<label class="form-label" for="typeText2">课程名(支持部分关键词匹配)</label>
<label class="form-label" for="typeText2">课程名(支持部分)</label>
</div>
</div>
</div>
@ -206,7 +206,7 @@
<div class="form-outline">
<input type="text" id="typeText3" class="form-control"
name="description"/>
<label class="form-label" for="typeText3">描述(支持部分关键词匹配)</label>
<label class="form-label" for="typeText3">描述(支持部分)</label>
</div>
</div>
</div>

View File

@ -79,34 +79,31 @@ public class CourseController {
// return "redirect:/student/infomodv2";
// }
//
// @PostMapping(value = "/modinfo", produces = "application/x-www-form-urlencoded;charset=UTF-8")//处理学生信息修改请求
// public String UpdateModInfo(@RequestParam(value = "name", defaultValue = "null", required = false) String name,
// @RequestParam(value = "birthday", defaultValue = "null", required = false) String birthdayStr,
// @RequestParam(value = "sex", defaultValue = "null", required = false) String sex,
// @RequestParam(value = "id", defaultValue = "-1", required = false) int id,
// @RequestParam(value = "phone", defaultValue = "null", required = false) String phone,
// @RequestParam(value = "classes", defaultValue = "", required = false) String classes,
// Model model) {
// Date birthday = null;
// if (!"null".equals(birthdayStr)) {
// birthday = Date.valueOf(birthdayStr);
// }
// System.out.println(birthday);//debug
// Student student;
// if (name.equals("null")) name = null;
// if (sex.equals("null")) sex = null;
// if (phone.equals("null")) phone = null;
// if (classes.equals("")) classes = null;
//
// if (id <= -1) {
// model.addAttribute("errorMessage", "学生信息修改失败");
// } else {
// student = new Student(id, name, sex, birthday, phone, classes);
// studentService.updateStudent(student);
// model.addAttribute("successMessage", "学生信息修改成功");
// }
// return "redirect:/student/infomodv2";
// }
@PostMapping(value = "/modinfo", produces = "application/x-www-form-urlencoded;charset=UTF-8")
public String UpdateModInfo(@RequestParam(value = "name", defaultValue = "null", required = false) String name,
@RequestParam(value = "description", defaultValue = "null", required = false) String description,
@RequestParam(value = "id", defaultValue = "-1", required = false) int id,
Model model) {
Course course;
if (name.equals("null")) name = null;
if (description.equals("null")) description = null;
if (id <= -1) {
model.addAttribute("errorMessage", "ID非法课程信息修改失败");
} else {
course = new Course(id, name, description);
int status_code = courseService.updateCourse(course);
if(status_code==1){
model.addAttribute("successMessage", "课程信息修改成功");
}else if(status_code==0) {
model.addAttribute("errorMessage", "课程信息修改失败可能是ID非法或者课程不存在");
}else{
model.addAttribute("errorMessage", "课程信息修改异常");
System.out.println("DEBUG:课程信息修改异常,存在多条记录被修改的情况");
}
}
return "redirect:/course/infomodv2";
}
@PostMapping(value = "/query", produces = "application/x-www-form-urlencoded;charset=UTF-8")//学生信息查询带条件
public String getQueryCourses(@RequestParam(value = "name", defaultValue = "null", required = false) String name,
@ -122,16 +119,7 @@ public class CourseController {
List<Course> courses;
Course course;
course = new Course((id == -1 ? null : id), name, description);
System.out.println("id:" + id + " name:" + name + " description:" + description);
// if(course.getCourseID() == null){
// System.out.println("WARNNING : id is null");
// }
// if (course.getCourseName() == null) {
// System.out.println("WARNNING : courseName is null");
// }
// if (course.getDescription() == null) {
// System.out.println("WARNNING : description is null");
// }
// System.out.println("id:" + id + " name:" + name + " description:" + description);
courses = courseService.getQueryCourses(course);
model.addAttribute("courses", courses);
return "courseQueryResult";

View File

@ -10,4 +10,6 @@ public interface CourseDao {
List<Course> getAllCourses();
List<Course> getQueryCourses(Course course);
int updateCourse(Course course);
}

View File

@ -25,4 +25,9 @@ public class CourseDaoImpl implements CourseDao {
public List<Course> getQueryCourses(Course course) {
return sqlSession.selectList("getQueryCourses", course);
}
@Override
public int updateCourse(Course course) {
return sqlSession.update("updateCourse", course);
}
}

View File

@ -22,4 +22,9 @@ public class CourseService {
public List<Course> getQueryCourses(Course course) {
return courseDao.getQueryCourses(course);
}
public int updateCourse(Course course) {
return courseDao.updateCourse(course);
}
}

View File

@ -22,5 +22,17 @@
AND Description LIKE CONCAT('%', #{description}, '%')
</if>
</select>
<update id="updateCourse" parameterType="cyou.chenx221.pojo.Course">
UPDATE course
SET
<trim suffixOverrides=",">
<if test="courseName != null">
CourseName = #{courseName},
</if>
<if test="description != null">
Description = #{description},
</if>
</trim>
WHERE CourseID = #{courseID}
</update>
</mapper>

View File

@ -197,7 +197,7 @@
<div class="form-outline">
<input type="text" id="typeText2" class="form-control"
name="name"/>
<label class="form-label" for="typeText2">课程名(支持部分关键词匹配)</label>
<label class="form-label" for="typeText2">课程名(支持部分)</label>
</div>
</div>
</div>
@ -206,7 +206,7 @@
<div class="form-outline">
<input type="text" id="typeText3" class="form-control"
name="description"/>
<label class="form-label" for="typeText3">描述(支持部分关键词匹配)</label>
<label class="form-label" for="typeText3">描述(支持部分)</label>
</div>
</div>
</div>