记录删除功能已完成*非真正意义上删除

记录增加未完成

Signed-off-by: Chenx221 <chenx221@yandex.com>
This commit is contained in:
Chenx221 2023-06-09 13:07:45 +08:00
parent 7d14a0bf06
commit 91fea883f8
13 changed files with 78 additions and 35 deletions

View File

@ -4,9 +4,16 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" > "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cyou.chenx221.mapper.StudentDao"> <mapper namespace="cyou.chenx221.mapper.StudentDao">
<select id="getAllStudents" resultType="cyou.chenx221.pojo.Student"> <select id="getAllStudents" resultType="cyou.chenx221.pojo.Student">
SELECT * FROM student WHERE removed = 0 SELECT *
FROM student
WHERE removed = 0
</select>
<select id="getStudentById" resultType="cyou.chenx221.pojo.Student">
SELECT *
FROM student
WHERE id = #{id}
AND removed = 0
</select> </select>
<select id="getQueryStudents" parameterType="cyou.chenx221.pojo.Student" resultType="cyou.chenx221.pojo.Student"> <select id="getQueryStudents" parameterType="cyou.chenx221.pojo.Student" resultType="cyou.chenx221.pojo.Student">
SELECT * FROM student SELECT * FROM student
WHERE 1=1 WHERE 1=1
@ -26,6 +33,7 @@
AND id = #{id} AND id = #{id}
</if> </if>
</select> </select>
<select id="getQueryStudents2" parameterType="cyou.chenx221.pojo.Student" resultType="cyou.chenx221.pojo.Student"> <select id="getQueryStudents2" parameterType="cyou.chenx221.pojo.Student" resultType="cyou.chenx221.pojo.Student">
SELECT * FROM student SELECT * FROM student
WHERE 1=1 WHERE 1=1
@ -36,6 +44,7 @@
</foreach> </foreach>
</if> </if>
</select> </select>
<update id="updateStudent" parameterType="cyou.chenx221.pojo.Student"> <update id="updateStudent" parameterType="cyou.chenx221.pojo.Student">
UPDATE student UPDATE student
SET SET
@ -49,4 +58,11 @@
WHERE id = #{id} WHERE id = #{id}
</update> </update>
<update id="deleteStudent" parameterType="int">
UPDATE student
SET removed = 1
WHERE id = #{id}
</update>
</mapper> </mapper>

View File

@ -179,7 +179,7 @@
</li> </li>
</ul> </ul>
<!-- Tabs navs --> <!-- Tabs navs -->
<hr class="hr" style="margin: 1px" />
<!-- Tabs content --> <!-- Tabs content -->
<div class="tab-content" id="ex1-content"> <div class="tab-content" id="ex1-content">
<div class="tab-pane fade show active" id="ex1-tabs-1" role="tabpanel" <div class="tab-pane fade show active" id="ex1-tabs-1" role="tabpanel"
@ -256,7 +256,7 @@
</div> </div>
<div class="tab-pane fade" id="ex1-tabs-2" role="tabpanel" aria-labelledby="ex1-tab-2"> <div class="tab-pane fade" id="ex1-tabs-2" role="tabpanel" aria-labelledby="ex1-tab-2">
<div class="card-body" style="min-width: 175px"> <div class="card-body" style="min-width: 175px">
<form action="modinfo" method="post"> <form action="delinfo" method="post">
<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">

View File

@ -114,15 +114,38 @@ public class StudentController {
return "studentinfomodv2"; return "studentinfomodv2";
} }
@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", defaultValue = "-1", required = false) int id, public String UpdateModInfo(@RequestParam(value = "id", defaultValue = "-1", required = false) int id,
Model model) { Model model) {
Student student; Student temp = studentService.getStudentById(id);
if (id <= -1) { if (id <= 0 || temp == null) {
model.addAttribute("errorMessage", "ID异常学生信息修改失败"); model.addAttribute("errorMessage", "学生信息删除失败,可能是ID非法或者学生已删除");
} else { } else {
student = new Student(id); // Student student = new Student(id);
studentService.deleteStudent(student); studentService.deleteStudent(id);
model.addAttribute("successMessage", "学生信息删除成功");
}
return "redirect:/student/infomodv2";
}
@PostMapping(value = "/addinfo", produces = "application/x-www-form-urlencoded;charset=UTF-8")
public String InsertStudentInfo(@RequestParam(value = "name", defaultValue = "null", required = false) String name,
@RequestParam(value = "birthday", defaultValue = "#{null}", required = false) Date birthday,
@RequestParam(value = "sex", defaultValue = "null", required = false) String sex,
@RequestParam(value = "phone", defaultValue = "null", required = false) String phone,
@RequestParam(value = "classes", defaultValue = "", required = false) String classes,
Model model) {
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", "学生信息修改成功"); model.addAttribute("successMessage", "学生信息修改成功");
} }
return "redirect:/student/modstep1"; return "redirect:/student/modstep1";

View File

@ -3,13 +3,12 @@ package cyou.chenx221.mapper;
import cyou.chenx221.pojo.Student; import cyou.chenx221.pojo.Student;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.Date;
import java.util.List; import java.util.List;
@Repository @Repository
public interface StudentDao { public interface StudentDao {
void insertStudent(Student student); void insertStudent(Student student);
void deleteStudent(Student student); void deleteStudent(int id);
Student getStudentById(int studentId); Student getStudentById(int studentId);
List<Student> getAllStudents(); List<Student> getAllStudents();

View File

@ -32,8 +32,8 @@ public class StudentDaoImpl implements StudentDao {
} }
@Override @Override
public void deleteStudent(Student student) { public void deleteStudent(int id) {
sqlSession.delete("deleteStudent", student); sqlSession.update("deleteStudent", id);
} }
@Override @Override

View File

@ -2,8 +2,6 @@ package cyou.chenx221.pojo;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -17,17 +15,17 @@ public class Student {
private String classes; private String classes;
private List<String> classess; private List<String> classess;
private Integer removed; private int removed;
public Student(Integer id) { public Student(int id) {
this.id = id; this.id = id;
} }
public Integer getRemoved() { public int getRemoved() {
return removed; return removed;
} }
public void setRemoved(Integer removed) { public void setRemoved(int removed) {
this.removed = removed; this.removed = removed;
} }

View File

@ -19,8 +19,8 @@ public class StudentService {
studentDao.insertStudent(student); studentDao.insertStudent(student);
} }
public void deleteStudent(Student student) { public void deleteStudent(int id) {
studentDao.deleteStudent(student); studentDao.deleteStudent(id);
} }
public Student getStudentById(int studentId) { public Student getStudentById(int studentId) {

View File

@ -4,9 +4,16 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" > "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cyou.chenx221.mapper.StudentDao"> <mapper namespace="cyou.chenx221.mapper.StudentDao">
<select id="getAllStudents" resultType="cyou.chenx221.pojo.Student"> <select id="getAllStudents" resultType="cyou.chenx221.pojo.Student">
SELECT * FROM student WHERE removed = 0 SELECT *
FROM student
WHERE removed = 0
</select>
<select id="getStudentById" resultType="cyou.chenx221.pojo.Student">
SELECT *
FROM student
WHERE id = #{id}
AND removed = 0
</select> </select>
<select id="getQueryStudents" parameterType="cyou.chenx221.pojo.Student" resultType="cyou.chenx221.pojo.Student"> <select id="getQueryStudents" parameterType="cyou.chenx221.pojo.Student" resultType="cyou.chenx221.pojo.Student">
SELECT * FROM student SELECT * FROM student
WHERE 1=1 WHERE 1=1
@ -26,6 +33,7 @@
AND id = #{id} AND id = #{id}
</if> </if>
</select> </select>
<select id="getQueryStudents2" parameterType="cyou.chenx221.pojo.Student" resultType="cyou.chenx221.pojo.Student"> <select id="getQueryStudents2" parameterType="cyou.chenx221.pojo.Student" resultType="cyou.chenx221.pojo.Student">
SELECT * FROM student SELECT * FROM student
WHERE 1=1 WHERE 1=1
@ -36,6 +44,7 @@
</foreach> </foreach>
</if> </if>
</select> </select>
<update id="updateStudent" parameterType="cyou.chenx221.pojo.Student"> <update id="updateStudent" parameterType="cyou.chenx221.pojo.Student">
UPDATE student UPDATE student
SET SET
@ -49,4 +58,11 @@
WHERE id = #{id} WHERE id = #{id}
</update> </update>
<update id="deleteStudent" parameterType="int">
UPDATE student
SET removed = 1
WHERE id = #{id}
</update>
</mapper> </mapper>

View File

@ -179,22 +179,13 @@
</li> </li>
</ul> </ul>
<!-- Tabs navs --> <!-- Tabs navs -->
<hr class="hr" style="margin: 1px" />
<!-- Tabs content --> <!-- Tabs content -->
<div class="tab-content" id="ex1-content"> <div class="tab-content" id="ex1-content">
<div class="tab-pane fade show active" id="ex1-tabs-1" role="tabpanel" <div class="tab-pane fade show active" id="ex1-tabs-1" role="tabpanel"
aria-labelledby="ex1-tab-1"> aria-labelledby="ex1-tab-1">
<div class="card-body" style="min-width: 175px"> <div class="card-body" style="min-width: 175px">
<form action="modinfo" method="post"> <form action="modinfo" method="post">
<div class="row mb-2">
<div class="col-12">
<div class="form-outline">
<input type="number" id="typeText1" class="form-control"
required name="id"/>
<label class="form-label" for="typeText1">ID (必填)</label>
</div>
</div>
</div>
<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">
@ -256,7 +247,7 @@
</div> </div>
<div class="tab-pane fade" id="ex1-tabs-2" role="tabpanel" aria-labelledby="ex1-tab-2"> <div class="tab-pane fade" id="ex1-tabs-2" role="tabpanel" aria-labelledby="ex1-tab-2">
<div class="card-body" style="min-width: 175px"> <div class="card-body" style="min-width: 175px">
<form action="modinfo" method="post"> <form action="delinfo" method="post">
<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">