Signed-off-by: Chenx221 <chenx221@yandex.com>
This commit is contained in:
Chenx221 2023-06-09 12:09:44 +08:00
parent 21ebfdf358
commit 3e54759b15
14 changed files with 62 additions and 63 deletions

View File

@ -3,6 +3,7 @@
<component name="WebContextManager">
<option name="state">
<map>
<entry key="file://$PROJECT_DIR$/web/WEB-INF/views/studentInfoAdd.jsp" value="file://$PROJECT_DIR$/web/WEB-INF/views" />
<entry key="file://$PROJECT_DIR$/web/WEB-INF/views/studentList.jsp" value="file://$PROJECT_DIR$/web/WEB-INF/views" />
</map>
</option>

View File

@ -4,7 +4,7 @@
"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
SELECT * FROM student WHERE removed = 0
</select>
<select id="getQueryStudents" parameterType="cyou.chenx221.pojo.Student" resultType="cyou.chenx221.pojo.Student">

View File

@ -43,9 +43,9 @@
<li><a class="dropdown-item" href="student/all">学生信息显示</a></li>
<li><a class="dropdown-item" href="student/queryinfo">学生信息查询</a></li>
<li><a class="dropdown-item" href="student/modstep1">学生信息修改</a></li>
<li><a class="dropdown-item" href="#">学生信息添加</a></li>
<li><a class="dropdown-item" href="student/infomodv2">学生信息添加</a></li>
<li><a class="dropdown-item" href="#">学生信息删除</a></li>
<li><a class="dropdown-item disabled">自己输入sql语句查(没做)</a></li>
<li><a class="dropdown-item disabled"><del>自己输入sql语句查</del>(划掉,没做)</a></li>
<li>
<hr class="dropdown-divider" />
</li>

View File

@ -232,6 +232,7 @@
<div class="mt-4">
<input class="btn btn-warning btn-lg" type="submit" value="提交"/>
<button type="reset" class="btn btn-secondary">重置</button>
</div>
</div>
</div>

View File

@ -28,19 +28,20 @@ public class StudentController {
this.studentService = studentService;
}
@GetMapping("/all")
@GetMapping("/all")//学生信息查询不带条件(排除removed的学生
public String getAllStudents(Model model) {
List<Student> students = studentService.getAllStudents();
model.addAttribute("students", students);
return "studentList"; // 重定向到 dashboard 页面
}
@GetMapping("/queryinfo")
@GetMapping("/queryinfo")//处理访问学生信息查询
public String getQueryInfo(Model model) {
return "studentListQuery"; // 重定向到 dashboard 页面
return "studentListQuery";
}
@PostMapping(value = "/query", produces = "application/x-www-form-urlencoded;charset=UTF-8")
@PostMapping(value = "/query", produces = "application/x-www-form-urlencoded;charset=UTF-8")//学生信息查询带条件
public String getQueryStudents(@RequestParam(value = "name", defaultValue = "null", required = false) String name,
@RequestParam(value = "birthday", defaultValue = "#{null}", required = false) Date birthday,
@RequestParam(value = "inlineRadioOptions", defaultValue = "null", required = false) String option,
@ -48,13 +49,6 @@ public class StudentController {
@RequestParam(value = "phone", defaultValue = "null", required = false) String phone,
@RequestParam(value = "classes", defaultValue = "", required = false) List<String> classes,
Model model) {
// System.out.println("name: " + name);
// System.out.println("birthday: " + birthday);
// System.out.println("option: " + option);
// System.out.println("id: " + id);
// System.out.println("phone: " + phone);
// System.out.println("classes: " + classes);
List<Student> students;
Student student;
if (classes.size() == 0) {
@ -68,17 +62,15 @@ public class StudentController {
student = new Student(classes);
students = studentService.getQueryStudents2(student);
}
model.addAttribute("students", students);
return "studentQueryResult";
}
@GetMapping("/modstep1")
public String getModStep1(@RequestParam(value = "successMessage", required = false , defaultValue = "null") String successMessage,
@RequestParam(value = "errorMessage" ,required = false , defaultValue = "null") String errorMessage,
@GetMapping("/modstep1")//处理学生信息修改页
public String getModStep1(@RequestParam(value = "successMessage", required = false, defaultValue = "null") String successMessage,
@RequestParam(value = "errorMessage", required = false, defaultValue = "null") String errorMessage,
Model model) {
List<Student> students = studentService.getAllStudents();
List<Student> students = studentService.getAllStudents();//和前面显示全部学生一样页面需要学生信息的显示
model.addAttribute("students", students);
// 将消息添加到Model中
model.addAttribute("successMessage", successMessage);
@ -86,7 +78,7 @@ public class StudentController {
return "studentMod";
}
@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,
@RequestParam(value = "birthday", defaultValue = "#{null}", required = false) Date birthday,
@RequestParam(value = "sex", defaultValue = "null", required = false) String sex,
@ -94,14 +86,6 @@ public class StudentController {
@RequestParam(value = "phone", defaultValue = "null", required = false) String phone,
@RequestParam(value = "classes", defaultValue = "", required = false) String classes,
Model model) {
System.out.println("name: " + name);
System.out.println("birthday: " + birthday);
System.out.println("sex: " + sex);
System.out.println("id: " + id);
System.out.println("phone: " + phone);
System.out.println("classes: " + classes);
//
List<Student> students;
Student student;
if (name.equals("null")) name = null;
if (sex.equals("null")) sex = null;
@ -117,32 +101,30 @@ public class StudentController {
}
return "redirect:/student/modstep1";
}
// students = studentService.getQueryStudents(student);
@GetMapping("/infomodv2")//处理学生信息修改页
public String getInfoModv2(@RequestParam(value = "successMessage", required = false, defaultValue = "null") String successMessage,
@RequestParam(value = "errorMessage", required = false, defaultValue = "null") String errorMessage,
Model model) {
List<Student> students = studentService.getAllStudents();//和前面显示全部学生一样页面需要学生信息的显示
model.addAttribute("students", students);
// 将消息添加到Model中
model.addAttribute("successMessage", successMessage);
model.addAttribute("errorMessage", errorMessage);
return "studentinfomodv2";
}
// // 示例处理查询学生信息的请求
// @GetMapping("/{studentId}")
// public String getStudentById(@PathVariable int studentId) {
// // ...
// }
//
// // 示例处理添加学生信息的请求
// @PostMapping("/")
// public String addStudent(@RequestBody Student student) {
// // ...
// }
//
// // 示例处理更新学生信息的请求
// @PutMapping("/{studentId}")
// public String updateStudent(@PathVariable int studentId, @RequestBody Student student) {
// // ...
// }
//
// // 示例处理删除学生信息的请求
// @DeleteMapping("/{studentId}")
// public String deleteStudent(@PathVariable int studentId) {
// // ...
// }
// ...
@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异常学生信息修改失败");
} else {
student = new Student(id);
studentService.deleteStudent(student);
model.addAttribute("successMessage", "学生信息修改成功");
}
return "redirect:/student/modstep1";
}
}

View File

@ -9,7 +9,7 @@ import java.util.List;
@Repository
public interface StudentDao {
void insertStudent(Student student);
void deleteStudent(int studentId);
void deleteStudent(Student student);
Student getStudentById(int studentId);
List<Student> getAllStudents();

View File

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

View File

@ -17,6 +17,20 @@ public class Student {
private String classes;
private List<String> classess;
private Integer removed;
public Student(Integer id) {
this.id = id;
}
public Integer getRemoved() {
return removed;
}
public void setRemoved(Integer removed) {
this.removed = removed;
}
public List<String> getClassess() {
return classess;
}

View File

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

View File

@ -4,7 +4,7 @@
"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
SELECT * FROM student WHERE removed = 0
</select>
<select id="getQueryStudents" parameterType="cyou.chenx221.pojo.Student" resultType="cyou.chenx221.pojo.Student">

View File

@ -43,9 +43,9 @@
<li><a class="dropdown-item" href="student/all">学生信息显示</a></li>
<li><a class="dropdown-item" href="student/queryinfo">学生信息查询</a></li>
<li><a class="dropdown-item" href="student/modstep1">学生信息修改</a></li>
<li><a class="dropdown-item" href="#">学生信息添加</a></li>
<li><a class="dropdown-item" href="student/infomodv2">学生信息添加</a></li>
<li><a class="dropdown-item" href="#">学生信息删除</a></li>
<li><a class="dropdown-item disabled">自己输入sql语句查(没做)</a></li>
<li><a class="dropdown-item disabled"><del>自己输入sql语句查</del>(划掉,没做)</a></li>
<li>
<hr class="dropdown-divider" />
</li>

View File

@ -232,6 +232,7 @@
<div class="mt-4">
<input class="btn btn-warning btn-lg" type="submit" value="提交"/>
<button type="reset" class="btn btn-secondary">重置</button>
</div>
</div>
</div>