|
|
|
@ -8,6 +8,7 @@ import cn.ppdxzz.service.DormService;
|
|
|
|
|
import cn.ppdxzz.service.StudentService;
|
|
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
@ -20,9 +21,11 @@ import java.io.InputStream;
|
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/dorm")
|
|
|
|
|
@Controller
|
|
|
|
|
public class DormController {
|
|
|
|
|
public class DormController
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// 定义宿舍服务、学生服务和管理员服务的私有成员变量
|
|
|
|
|
private DormService dormService;
|
|
|
|
@ -31,19 +34,22 @@ public class DormController {
|
|
|
|
|
|
|
|
|
|
// 使用@Autowired注解自动注入DormService实例
|
|
|
|
|
@Autowired
|
|
|
|
|
public void setStudentService(StudentService studentService) {
|
|
|
|
|
public void setStudentService(StudentService studentService)
|
|
|
|
|
{
|
|
|
|
|
this.studentService = studentService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 使用@Autowired注解自动注入StudentService实例
|
|
|
|
|
@Autowired
|
|
|
|
|
public void setDormService(DormService dormService) {
|
|
|
|
|
public void setDormService(DormService dormService)
|
|
|
|
|
{
|
|
|
|
|
this.dormService = dormService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 使用@Autowired注解自动注入AdminService实例
|
|
|
|
|
@Autowired
|
|
|
|
|
public void setAdminService(AdminService adminService) {
|
|
|
|
|
public void setAdminService(AdminService adminService)
|
|
|
|
|
{
|
|
|
|
|
this.adminService = adminService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -58,7 +64,10 @@ public class DormController {
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/findAll")
|
|
|
|
|
public ModelAndView findAll(@RequestParam(name = "page", required = true, defaultValue = "1")int page, @RequestParam(name = "size", required = true, defaultValue = "5") int size, HttpServletRequest request, HttpServletResponse response) throws Exception {
|
|
|
|
|
public ModelAndView findAll(@RequestParam(name = "page", required = true, defaultValue = "1"
|
|
|
|
|
)int page, @RequestParam(name = "size", required = true, defaultValue = "5") int size,
|
|
|
|
|
HttpServletRequest request, HttpServletResponse response) throws Exception
|
|
|
|
|
{
|
|
|
|
|
// 设置请求和响应的字符编码为UTF-8
|
|
|
|
|
request.setCharacterEncoding("utf-8");
|
|
|
|
|
response.setCharacterEncoding("utf-8");
|
|
|
|
@ -71,10 +80,13 @@ public class DormController {
|
|
|
|
|
|
|
|
|
|
// 获取搜索关键字
|
|
|
|
|
String keyword = request.getParameter("keyword");
|
|
|
|
|
if (keyword == null || "".trim().equals(keyword)) {
|
|
|
|
|
if (keyword == null || "".trim().equals(keyword))
|
|
|
|
|
{
|
|
|
|
|
// 根据分页参数查询所有宿舍信息
|
|
|
|
|
dorms = dormService.findAll(page,size);
|
|
|
|
|
}else {
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// 根据关键字进行搜索
|
|
|
|
|
dorms = dormService.search(page,size,keyword);
|
|
|
|
|
}
|
|
|
|
@ -97,7 +109,8 @@ public class DormController {
|
|
|
|
|
* @throws Exception 可能抛出的异常
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/toAdd")
|
|
|
|
|
public String addDorm() throws Exception {
|
|
|
|
|
public String addDorm() throws Exception
|
|
|
|
|
{
|
|
|
|
|
// 返回宿舍添加页面的视图名称
|
|
|
|
|
return "dorm-add";
|
|
|
|
|
}
|
|
|
|
@ -108,7 +121,8 @@ public class DormController {
|
|
|
|
|
* @throws Exception 可能抛出的异常
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/add")
|
|
|
|
|
public void add(Dorm dorm,HttpServletResponse response) throws Exception {
|
|
|
|
|
public void add(Dorm dorm,HttpServletResponse response) throws Exception
|
|
|
|
|
{
|
|
|
|
|
response.setCharacterEncoding("utf-8");
|
|
|
|
|
|
|
|
|
|
// 获取PrintWriter对象,用于向客户端输出内容
|
|
|
|
@ -116,14 +130,16 @@ public class DormController {
|
|
|
|
|
|
|
|
|
|
// 检查宿舍对象及其必要属性是否为空
|
|
|
|
|
if (dorm == null || dorm.getDorm_id() == null || dorm.getDorm_intro() == null || dorm.getDorm_rps() == null
|
|
|
|
|
|| dorm.getDorm_leader() == null || dorm.getTeacher() == null) {
|
|
|
|
|
|| dorm.getDorm_leader() == null || dorm.getTeacher() == null)
|
|
|
|
|
{
|
|
|
|
|
writer.write("false");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 根据宿舍ID查询是否存在相同ID的宿舍
|
|
|
|
|
Dorm isNull = dormService.findByDormId(dorm.getDorm_id());
|
|
|
|
|
if (isNull != null) {
|
|
|
|
|
if (isNull != null)
|
|
|
|
|
{
|
|
|
|
|
writer.write("false");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -140,7 +156,8 @@ public class DormController {
|
|
|
|
|
* @throws Exception 可能抛出的异常
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/isExist")
|
|
|
|
|
public void isExist(HttpServletRequest request,HttpServletResponse response) throws Exception {
|
|
|
|
|
public void isExist(HttpServletRequest request,HttpServletResponse response) throws Exception
|
|
|
|
|
{
|
|
|
|
|
request.setCharacterEncoding("utf-8");
|
|
|
|
|
response.setCharacterEncoding("utf-8");
|
|
|
|
|
PrintWriter writer = response.getWriter();
|
|
|
|
@ -148,7 +165,8 @@ public class DormController {
|
|
|
|
|
// 获取请求中的宿舍ID参数
|
|
|
|
|
String dorm_id = request.getParameter("dorm_id");
|
|
|
|
|
Dorm isNull = dormService.findByDormId(dorm_id);
|
|
|
|
|
if (isNull != null) {
|
|
|
|
|
if (isNull != null)
|
|
|
|
|
{
|
|
|
|
|
// 如果存在相同ID的宿舍,则返回"true"
|
|
|
|
|
writer.write("true");
|
|
|
|
|
return;
|
|
|
|
@ -162,11 +180,13 @@ public class DormController {
|
|
|
|
|
* @throws Exception 可能抛出的异常
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/toUpdate")
|
|
|
|
|
public ModelAndView toUpdate(HttpServletRequest request) throws Exception {
|
|
|
|
|
public ModelAndView toUpdate(HttpServletRequest request) throws Exception
|
|
|
|
|
{
|
|
|
|
|
request.setCharacterEncoding("utf-8");
|
|
|
|
|
ModelAndView mv = new ModelAndView();
|
|
|
|
|
String id = request.getParameter("id");
|
|
|
|
|
if (id == null) {
|
|
|
|
|
if (id == null)
|
|
|
|
|
{
|
|
|
|
|
return mv;
|
|
|
|
|
}
|
|
|
|
|
Dorm dorm = dormService.findById(id);
|
|
|
|
@ -187,11 +207,14 @@ public class DormController {
|
|
|
|
|
* @throws Exception 可能抛出的异常
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/update")
|
|
|
|
|
public void update(Dorm dorm,HttpServletResponse response) throws Exception {
|
|
|
|
|
public void update(Dorm dorm,HttpServletResponse response) throws Exception
|
|
|
|
|
{
|
|
|
|
|
response.setCharacterEncoding("utf-8");
|
|
|
|
|
PrintWriter writer = response.getWriter();
|
|
|
|
|
if (dorm == null ||dorm.getId() == null || dorm.getDorm_id() == null || dorm.getDorm_intro() == null || dorm.getDorm_rps() == null
|
|
|
|
|
|| dorm.getDorm_leader() == null || dorm.getTeacher() == null) {
|
|
|
|
|
if (dorm == null ||dorm.getId() == null || dorm.getDorm_id() == null
|
|
|
|
|
|| dorm.getDorm_intro() == null || dorm.getDorm_rps() == null
|
|
|
|
|
|| dorm.getDorm_leader() == null || dorm.getTeacher() == null)
|
|
|
|
|
{
|
|
|
|
|
writer.write("false");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -207,7 +230,8 @@ public class DormController {
|
|
|
|
|
* @throws Exception 可能抛出的异常
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/export")
|
|
|
|
|
public void export(HttpServletResponse response) throws Exception {
|
|
|
|
|
public void export(HttpServletResponse response) throws Exception
|
|
|
|
|
{
|
|
|
|
|
// 获取宿舍信息的输入流
|
|
|
|
|
InputStream is = dormService.getInputStream();
|
|
|
|
|
|
|
|
|
@ -232,20 +256,26 @@ public class DormController {
|
|
|
|
|
* @throws Exception 可能抛出的异常
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/look")
|
|
|
|
|
public ModelAndView look(HttpServletRequest request) throws Exception {
|
|
|
|
|
public ModelAndView look(HttpServletRequest request) throws Exception
|
|
|
|
|
{
|
|
|
|
|
ModelAndView mv = new ModelAndView();
|
|
|
|
|
Dorm dorm = null;
|
|
|
|
|
String id = request.getParameter("id");
|
|
|
|
|
String uid = request.getParameter("uid");
|
|
|
|
|
|
|
|
|
|
// 根据不同的参数情况查询宿舍信息
|
|
|
|
|
if (id == null && uid != null) {
|
|
|
|
|
if (id == null && uid != null)
|
|
|
|
|
{
|
|
|
|
|
// 根据学生ID查询学生信息,再根据学生的宿舍ID查询宿舍信息
|
|
|
|
|
Student stu = studentService.findBySno(uid);
|
|
|
|
|
dorm = dormService.findByDormId(stu.getDorm_id());
|
|
|
|
|
}else if (id != null) {
|
|
|
|
|
}
|
|
|
|
|
else if (id != null)
|
|
|
|
|
{
|
|
|
|
|
dorm = dormService.findById(id);
|
|
|
|
|
}else {
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return mv;
|
|
|
|
|
}
|
|
|
|
|
mv.addObject("dorm",dorm);
|
|
|
|
@ -265,7 +295,8 @@ public class DormController {
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/byDorm_leader")
|
|
|
|
|
//根据宿舍ID或学生ID查询宿舍学生信息
|
|
|
|
|
public ModelAndView find(HttpServletRequest request) throws Exception {
|
|
|
|
|
public ModelAndView find(HttpServletRequest request) throws Exception
|
|
|
|
|
{
|
|
|
|
|
request.setCharacterEncoding("utf-8");
|
|
|
|
|
|
|
|
|
|
// 创建ModelAndView对象,用于返回视图和数据
|
|
|
|
@ -274,7 +305,8 @@ public class DormController {
|
|
|
|
|
// 从请求中获取参数uid
|
|
|
|
|
String uid = request.getParameter("uid");
|
|
|
|
|
String dorm_id = request.getParameter("dorm_id");
|
|
|
|
|
if (dorm_id != null) {
|
|
|
|
|
if (dorm_id != null)
|
|
|
|
|
{
|
|
|
|
|
// 根据dorm_id查询学生信息
|
|
|
|
|
List<Student> studentsInfo = studentService.findByDormId(dorm_id, 1);
|
|
|
|
|
|
|
|
|
@ -299,7 +331,8 @@ public class DormController {
|
|
|
|
|
|
|
|
|
|
//根据教师ID查询该教师管理的宿舍信息
|
|
|
|
|
@RequestMapping("/byTeacher")
|
|
|
|
|
public ModelAndView find1(HttpServletRequest request) throws Exception {
|
|
|
|
|
public ModelAndView find1(HttpServletRequest request) throws Exception
|
|
|
|
|
{
|
|
|
|
|
ModelAndView mv = new ModelAndView();
|
|
|
|
|
String uid = request.getParameter("uid");
|
|
|
|
|
|
|
|
|
@ -309,7 +342,7 @@ public class DormController {
|
|
|
|
|
// 根据管理员姓名查询宿舍信息
|
|
|
|
|
List<Dorm> dorms = dormService.findByTeacher(admin.getName());
|
|
|
|
|
|
|
|
|
|
/ 将宿舍信息添加到ModelAndView对象中
|
|
|
|
|
// 将宿舍信息添加到ModelAndView对象中
|
|
|
|
|
mv.addObject("dorms",dorms);
|
|
|
|
|
mv.setViewName("dormsTeacherInfo");
|
|
|
|
|
return mv;
|
|
|
|
@ -325,7 +358,10 @@ public class DormController {
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/findStudent")
|
|
|
|
|
//根据教师姓名和关键词分页查询学生集合
|
|
|
|
|
public ModelAndView findStudents(@RequestParam(name = "page", required = true, defaultValue = "1")int page, @RequestParam(name = "size", required = true, defaultValue = "5") int size,HttpServletRequest request) throws Exception {
|
|
|
|
|
public ModelAndView findStudents(@RequestParam(name = "page", required = true, defaultValue = "1")int page,
|
|
|
|
|
@RequestParam(name = "size", required = true, defaultValue = "5") int size,
|
|
|
|
|
HttpServletRequest request) throws Exception
|
|
|
|
|
{
|
|
|
|
|
request.setCharacterEncoding("utf-8");
|
|
|
|
|
ModelAndView mv = new ModelAndView();
|
|
|
|
|
|
|
|
|
@ -339,11 +375,14 @@ public class DormController {
|
|
|
|
|
// 打印关键词到控制台
|
|
|
|
|
System.out.println(keyword);
|
|
|
|
|
|
|
|
|
|
if (keyword == null || "".trim().equals(keyword) || keyword.length() == 0) {
|
|
|
|
|
if (keyword == null || "".trim().equals(keyword) || keyword.length() == 0)
|
|
|
|
|
{
|
|
|
|
|
// 根据教师姓名分页查询学生信息
|
|
|
|
|
students = studentService.findByTeacher(page,size,teacher);
|
|
|
|
|
}
|
|
|
|
|
if (keyword != null){
|
|
|
|
|
|
|
|
|
|
if (keyword != null)
|
|
|
|
|
{
|
|
|
|
|
students = studentService.searchStudent(page,size,teacher,keyword);
|
|
|
|
|
}
|
|
|
|
|
PageInfo pageInfo = new PageInfo(students);
|
|
|
|
|