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

记录增加未完成

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" >
<mapper namespace="cyou.chenx221.mapper.StudentDao">
<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 id="getQueryStudents" parameterType="cyou.chenx221.pojo.Student" resultType="cyou.chenx221.pojo.Student">
SELECT * FROM student
WHERE 1=1
@ -26,6 +33,7 @@
AND id = #{id}
</if>
</select>
<select id="getQueryStudents2" parameterType="cyou.chenx221.pojo.Student" resultType="cyou.chenx221.pojo.Student">
SELECT * FROM student
WHERE 1=1
@ -36,6 +44,7 @@
</foreach>
</if>
</select>
<update id="updateStudent" parameterType="cyou.chenx221.pojo.Student">
UPDATE student
SET
@ -49,4 +58,11 @@
WHERE id = #{id}
</update>
<update id="deleteStudent" parameterType="int">
UPDATE student
SET removed = 1
WHERE id = #{id}
</update>
</mapper>

View File

@ -179,7 +179,7 @@
</li>
</ul>
<!-- Tabs navs -->
<hr class="hr" style="margin: 1px" />
<!-- Tabs content -->
<div class="tab-content" id="ex1-content">
<div class="tab-pane fade show active" id="ex1-tabs-1" role="tabpanel"
@ -256,7 +256,7 @@
</div>
<div class="tab-pane fade" id="ex1-tabs-2" role="tabpanel" aria-labelledby="ex1-tab-2">
<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="col-12">
<div class="form-outline">

View File

@ -114,15 +114,38 @@ public class StudentController {
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,
Model model) {
Student student;
if (id <= -1) {
model.addAttribute("errorMessage", "ID异常学生信息修改失败");
Student temp = studentService.getStudentById(id);
if (id <= 0 || temp == null) {
model.addAttribute("errorMessage", "学生信息删除失败,可能是ID非法或者学生已删除");
} else {
student = new Student(id);
studentService.deleteStudent(student);
// Student student = new Student(id);
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", "学生信息修改成功");
}
return "redirect:/student/modstep1";

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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