Merge pull request 'Dorm' (#5) from branch_li into develop

develop
pxrztuq3h 3 months ago
commit d2f8f08b4b

@ -8,12 +8,12 @@ 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;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -21,110 +21,153 @@ import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
/**
* Description:
*
* @Date: 2020/2/19 21:01
* @Author: PeiChen
*/
@RequestMapping("/dorm")
@Controller
public class DormController {
public class DormController
{
// 定义宿舍服务、学生服务和管理员服务的私有成员变量
private DormService dormService;
private StudentService studentService;
private AdminService adminService;
// 使用@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;
}
/**
* 宿
* @param page
* @param size
* @param request
* @param response
* @return
* @throws Exception
* @param page
* @param size
* @param request HTTP
* @param response HTTP
* @return ModelAndView
* @throws Exception
*/
@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");
// 创建ModelAndView对象
ModelAndView mv = new ModelAndView();
// 初始化宿舍列表
List<Dorm> dorms = null;
// 获取搜索关键字
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);
}
// 创建PageInfo对象封装分页信息
PageInfo pageInfo = new PageInfo(dorms);
// 将分页信息添加到ModelAndView对象中
mv.addObject("pageInfo",pageInfo);
// 设置视图名称为"dorm-list"
mv.setViewName("dorm-list");
//返回ModelAndView对象
return mv;
}
/**
* 宿
* @return
* @throws Exception
* @return
* @throws Exception
*/
@RequestMapping("/toAdd")
public String addDorm() throws Exception {
public String addDorm() throws Exception
{
// 返回宿舍添加页面的视图名称
return "dorm-add";
}
/**
* 宿
* @param dorm
* @param response
* @throws Exception
* 宿
* @param dorm 宿宿
* @param response HTTP
* @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对象用于向客户端输出内容
PrintWriter writer = response.getWriter();
// 检查宿舍对象及其必要属性是否为空
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;
}
// 调用服务层方法添加宿舍信息
dormService.add(dorm);
writer.write("true");
}
/**
* 宿宿,true
* @param request
* @param response
* @throws Exception
* 宿宿true
* @param request HTTP
* @param response HTTP
* @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();
// 获取请求中的宿舍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;
}
@ -132,20 +175,26 @@ public class DormController {
/**
* id宿宿
* @param request
* @return
* @throws Exception
* @param request HTTP
* @return ModelAndView宿
* @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);
// 将宿舍信息添加到ModelAndView对象中
mv.addObject("dorm",dorm);
// 设置视图名称为"dorm-edit"
mv.setViewName("dorm-edit");
return mv;
@ -153,59 +202,85 @@ public class DormController {
/**
* 宿
* @param dorm
* @param response
* @throws Exception
* @param dorm 宿宿
* @param response HTTP
* @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;
}
// 调用服务层方法更新宿舍信息
dormService.update(dorm);
writer.write("true");
}
/**
* 宿
* @param response
* @throws Exception
* @param response HTTP
* @throws Exception
*/
@RequestMapping("/export")
public void export(HttpServletResponse response) throws Exception {
public void export(HttpServletResponse response) throws Exception
{
// 获取宿舍信息的输入流
InputStream is = dormService.getInputStream();
// 设置响应的内容类型为Excel文件格式
response.setContentType("application/vnd.ms-excel");
// 设置响应头,指定下载的文件名
response.setHeader("contentDisposition","attachment;filename=dormInfo.xls");
// 获取ServletOutputStream对象用于向客户端输出二进制数据
ServletOutputStream outputStream = response.getOutputStream();
// 将输入流的数据复制到输出流中,实现文件下载
IOUtils.copy(is,outputStream);
}
/**
*
* @param request
* @return
* @throws Exception
* @param request HTTP
* @return ModelAndView宿
* @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);
// 设置视图名称为"look-dorm"
mv.setViewName("look-dorm");
return mv;
@ -217,18 +292,33 @@ public class DormController {
* @return
* @throws Exception
*/
@RequestMapping("/byDorm_leader")
public ModelAndView find(HttpServletRequest request) throws Exception {
//根据宿舍ID或学生ID查询宿舍学生信息
public ModelAndView find(HttpServletRequest request) throws Exception
{
request.setCharacterEncoding("utf-8");
// 创建ModelAndView对象用于返回视图和数据
ModelAndView mv = new ModelAndView();
// 从请求中获取参数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);
// 将学生信息添加到ModelAndView对象中
mv.addObject("studentsInfo",studentsInfo);
// 设置视图名称为"dormStudentsInfo"
mv.setViewName("dormStudentsInfo");
return mv;
}
// 根据uid查询学生信息
Student stu = studentService.findBySno(uid);
// Dorm dormInfo = dormService.findByDormId(stu.getDorm_id());
List<Student> studentsInfo = studentService.findByDormId(stu.getDorm_id(), 1);
@ -239,12 +329,20 @@ public class DormController {
return mv;
}
//根据教师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");
// 根据uid查询管理员信息
Admin admin = adminService.checkUid(uid);
// 根据管理员姓名查询宿舍信息
List<Dorm> dorms = dormService.findByTeacher(admin.getName());
// 将宿舍信息添加到ModelAndView对象中
mv.addObject("dorms",dorms);
mv.setViewName("dormsTeacherInfo");
return mv;
@ -252,33 +350,47 @@ public class DormController {
/**
* teacher
* @param page
* @param size
* @param request
* @return
* @throws Exception
*/
@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();
// 初始化学生列表
List<Student> students = null;
// 从请求中获取参数name教师姓名、keyword搜索关键词
String teacher = request.getParameter("name");
String keyword = request.getParameter("keyword");
// 打印关键词到控制台
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);
mv.addObject("pageInfo",pageInfo);
// 设置视图名称为"studentsTeacher"
mv.setViewName("studentsTeacher");
return mv;
}
}

@ -3,49 +3,50 @@ package cn.ppdxzz.dao;
import cn.ppdxzz.domain.Dorm;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* Description:
*
* @Date: 2020/2/19 18:28
* @Author: PeiChen
*/
@Repository
public interface DormDao {
public interface DormDao //DormDao 的接口,用于操作宿舍信息
{
/**
* 宿
* @return
* @throws Exception
*/
@Select("select * from dorms")
List<Dorm> findAll() throws Exception;
@Select("select * from dorms")//使用 @Select 注解指定 SQL 查询语句
List<Dorm> findAll() throws Exception;//返回包含所有宿舍信息的一个列表
/**
* 宿
* 宿
* @param keyword
* @return
* @throws Exception
*/
@Select("select * from dorms where dorm_id like '%${keyword}%' or dorm_intro like '%${keyword}%' or dorm_rps like '%${keyword}%' or dorm_leader like '%${keyword}%' or teacher like '%${keyword}%' ")
List<Dorm> search(@Param(value = "keyword") String keyword) throws Exception;
@Select("select * from dorms where dorm_id like '%${keyword}%' or dorm_intro " +
"like '%${keyword}%' or dorm_rps like '%${keyword}%' or dorm_leader " +
"like '%${keyword}%' or teacher like '%${keyword}%' ")
//返回一个包含匹配条件的宿舍信息的列表
List<Dorm> search(@Param(value = "keyword") String keyword) throws Exception;//将方法参数 keyword 绑定到 SQL 语句中的占位符
/**
* 宿
* 宿
* @param dorm
* @throws Exception
*/
@Insert("insert into dorms(dorm_id,dorm_intro,dorm_rps,dorm_leader,teacher) values(#{dorm_id},#{dorm_intro},#{dorm_rps},#{dorm_leader},#{teacher})")
//注解指定 SQL 插入语句,占位符#{dorm_id}、#{dorm_intro}、#{dorm_rps}、#{dorm_leader} 和 #{teacher}表示 Dorm 对象的属性值
@Insert("insert into dorms(dorm_id,dorm_intro,dorm_rps,dorm_leader,teacher) " +
"values(#{dorm_id},#{dorm_intro},#{dorm_rps},#{dorm_leader},#{teacher})")
void add(Dorm dorm) throws Exception;
/**
* 宿
* 宿
* @param dorm
* @throws Exception
*/
@Update("update dorms set dorm_id = #{dorm_id},dorm_intro = #{dorm_intro},dorm_rps = #{dorm_rps},dorm_leader = #{dorm_leader},teacher = #{teacher} where id = #{id}")
//注解指定了SQL 更新语句,
@Update("update dorms set dorm_id = #{dorm_id},dorm_intro = #{dorm_intro}," +
"dorm_rps = #{dorm_rps},dorm_leader = #{dorm_leader},teacher = #{teacher} where id = #{id}")
void update(Dorm dorm) throws Exception;
/**
@ -53,16 +54,19 @@ public interface DormDao {
* @param id
* @throws Exception
*/
@Delete("delete from dorms where id = #{id}")
@Delete("delete from dorms where id = #{id}")//占位符#{id} 表示要删除的宿舍记录的ID。
void delete(String id) throws Exception;
//根据宿舍ID查询宿舍信息
@Select("select * from dorms where dorm_id = #{dorm_id}")
Dorm findByDormId(String dorm_id) throws Exception;
Dorm findByDormId(String dorm_id) throws Exception;//返回一个 Dorm 对象
//根据记录ID查询宿舍信息
@Select("select * from dorms where id = #{id}")
Dorm findById(String id) throws Exception;
Dorm findById(String id) throws Exception;//返回一个 Dorm 对象
//根据教师姓名查询宿舍信息
@Select("select * from dorms where teacher = #{teacher}")
List<Dorm> findByTeacher(String teacher) throws Exception;
List<Dorm> findByTeacher(String teacher) throws Exception;//返回一个包含匹配条件的宿舍信息的列表
}

@ -2,13 +2,8 @@ package cn.ppdxzz.domain;
import java.io.Serializable;
/**
* Description:宿
*
* @Date: 2020/2/19 17:51
* @Author: PeiChen
*/
public class Dorm implements Serializable {
public class Dorm implements Serializable //该类的实例可以被序列化,可以将其转换为字节流以便存储、传输
{
private Integer id;//ID
private String dorm_id;//宿舍号
private String dorm_intro;//宿舍简介
@ -16,68 +11,88 @@ public class Dorm implements Serializable {
private String dorm_leader;//宿舍长
private String teacher;//管辖育人导师
public Dorm() {
//构造方法
public Dorm()
{
}
public Dorm(Integer id, String dorm_id, String dorm_intro, String dorm_rps, String dorm_leader, String teacher) {
public Dorm(Integer id, String dorm_id, String dorm_intro, String dorm_rps,
String dorm_leader, String teacher) {
this.id = id;
this.dorm_id = dorm_id;
this.dorm_intro = dorm_intro;
this.dorm_rps = dorm_rps;
this.dorm_leader = dorm_leader;
this.teacher = teacher;
}
public Integer getId() {
//Getter 和 Setter 方法
public Integer getId()
{
return id;
}
public void setId(Integer id) {
public void setId(Integer id)
{
this.id = id;
}
public String getDorm_id() {
public String getDorm_id()
{
return dorm_id;
}
public void setDorm_id(String dorm_id) {
public void setDorm_id(String dorm_id)
{
this.dorm_id = dorm_id;
}
public String getDorm_intro() {
public String getDorm_intro()
{
return dorm_intro;
}
public void setDorm_intro(String dorm_intro) {
public void setDorm_intro(String dorm_intro)
{
this.dorm_intro = dorm_intro;
}
public String getDorm_rps() {
public String getDorm_rps()
{
return dorm_rps;
}
public void setDorm_rps(String dorm_rps) {
public void setDorm_rps(String dorm_rps)
{
this.dorm_rps = dorm_rps;
}
public String getDorm_leader() {
public String getDorm_leader()
{
return dorm_leader;
}
public void setDorm_leader(String dorm_leader) {
public void setDorm_leader(String dorm_leader)
{
this.dorm_leader = dorm_leader;
}
public String getTeacher() {
public String getTeacher()
{
return teacher;
}
public void setTeacher(String teacher) {
public void setTeacher(String teacher)
{
this.teacher = teacher;
}
//重写toString() 方法,返回一个描述 Dorm 对象的字符串
@Override
public String toString() {
public String toString()
{
return "Dorm{" +
"id=" + id +
", dorm_id='" + dorm_id + '\'' +

@ -1,31 +1,33 @@
package cn.ppdxzz.service;
import cn.ppdxzz.domain.Dorm;
import java.io.InputStream;
import java.util.List;
/**
* Description:
*
* @Date: 2020/2/19 19:52
* @Author: PeiChen
*/
public interface DormService {
public interface DormService
{
List<Dorm> findAll(int page,int size) throws Exception;
//分页查询所有宿舍信息参数page 当前页码参数size (每页显示的记录数)
List<Dorm> findAll(int page,int size) throws Exception;//返回一个包含宿舍信息的列表List<Dorm>
List<Dorm> search(int page,int size,String keyword) throws Exception;
//根据关键字进行分页模糊查询宿舍信息参数keyword (查询的关键字)
List<Dorm> search(int page,int size,String keyword) throws Exception;//返回一个包含匹配关键字的宿舍信息的列表List<Dorm>
//添加新的宿舍信息参数dorm包含宿舍信息的对象
void add(Dorm dorm) throws Exception;
//更新已有的宿舍信息参数dorm包含更新后宿舍信息的对象
void update(Dorm dorm) throws Exception;
InputStream getInputStream() throws Exception;
//导出宿舍信息为Excel文件
InputStream getInputStream() throws Exception;//返回一个输入流InputStream用于读取生成的Excel文件
//根据宿舍号查找宿舍信息,参数 dorm_id (宿舍号)
Dorm findByDormId(String dorm_id) throws Exception;
//根据ID查找宿舍信息参数 id宿舍的唯一标识符
Dorm findById(String id) throws Exception;
List<Dorm> findByTeacher(String teacher) throws Exception;
//根据导师查找宿舍信息,参数 teacher导师的名字或标识
List<Dorm> findByTeacher(String teacher) throws Exception;//返回一个包含匹配导师的宿舍信息的列表List<Dorm>
}

@ -8,25 +8,22 @@ import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
/**
* Description:
*
* @Date: 2020/2/19 20:22
* @Author: PeiChen
*/
@Transactional
@Service("dormService")
public class DormServiceImpl implements DormService {
//基于Spring框架的Java服务类用于管理宿舍信息
@Transactional//该类中的所有方法都支持事务管理,这些方法在执行过程中如果出现异常,将进行回滚操作
@Service("dormService")//将这个类标记为一个Spring的服务组件并指定其名称为"dormService",可以通过依赖注入的方式在其他类中使用它
public class DormServiceImpl implements DormService
{
//用于访问数据层DAO
private DormDao dormDao;
@Autowired
public void setDormDao(DormDao dormDao) {
@Autowired//通过自动装配机制将DormDao类型的Bean注入到dormDao变量中
public void setDormDao(DormDao dormDao)
{
this.dormDao = dormDao;
}
@ -38,8 +35,11 @@ public class DormServiceImpl implements DormService {
* @throws Exception
*/
@Override
public List<Dorm> findAll(int page, int size) throws Exception {
public List<Dorm> findAll(int page, int size) throws Exception
{
//使用MyBatis的分页插件进行分页设置
PageHelper.startPage(page,size);
//调用DAO层的findAll方法获取数据
return dormDao.findAll();
}
@ -52,8 +52,11 @@ public class DormServiceImpl implements DormService {
* @throws Exception
*/
@Override
public List<Dorm> search(int page, int size, String keyword) throws Exception {
public List<Dorm> search(int page, int size, String keyword) throws Exception
{
//设置分页参数
PageHelper.startPage(page,size);
//调用DAO层的search方法进行模糊查询
return dormDao.search(keyword);
}
@ -63,7 +66,9 @@ public class DormServiceImpl implements DormService {
* @throws Exception
*/
@Override
public void add(Dorm dorm) throws Exception {
public void add(Dorm dorm) throws Exception
{
//调用DAO层的add方法保存数据
dormDao.add(dorm);
}
@ -73,7 +78,9 @@ public class DormServiceImpl implements DormService {
* @throws Exception
*/
@Override
public void update(Dorm dorm) throws Exception {
public void update(Dorm dorm) throws Exception
{
//调用DAO层的update方法更新数据
dormDao.update(dorm);
}
@ -83,12 +90,18 @@ public class DormServiceImpl implements DormService {
* @throws Exception
*/
@Override
public InputStream getInputStream() throws Exception {
public InputStream getInputStream() throws Exception
{
//Excel中的每列列名依次对应数据库的字段
String[] title = new String[]{"ID","宿舍号","宿舍简介","宿舍荣誉","宿舍长","育人导师"};
//获取所有宿舍信息
List<Dorm> dorms = dormDao.findAll();
// 创建一个列表存储数据
List<Object[]> datalist = new ArrayList<>();
for (int i = 0; i < dorms.size(); i++) {
//循环遍历宿舍信息将每个宿舍的信息存入datalist中
for (int i = 0; i < dorms.size(); i++)
{
Object[] obj = new Object[6];
obj[0] = dorms.get(i).getId();
obj[1] = dorms.get(i).getDorm_id();
@ -98,22 +111,27 @@ public class DormServiceImpl implements DormService {
obj[5] = dorms.get(i).getTeacher();
datalist.add(obj);
}
//创建Excel对象
WriteExcel excel = new WriteExcel(title,datalist);
//返回生成的Excel文件流
return excel.export();
}
@Override
public Dorm findByDormId(String dorm_id) throws Exception {
@Override//根据宿舍号查找宿舍信息
public Dorm findByDormId(String dorm_id) throws Exception
{
return dormDao.findByDormId(dorm_id);
}
@Override
public Dorm findById(String id) throws Exception {
@Override//根据ID查找宿舍信息
public Dorm findById(String id) throws Exception
{
return dormDao.findById(id);
}
@Override
public List<Dorm> findByTeacher(String teacher) throws Exception {
@Override//根据导师查找宿舍信息
public List<Dorm> findByTeacher(String teacher) throws Exception
{
return dormDao.findByTeacher(teacher);
}
}

@ -1,10 +1,3 @@
<%--
Created by IntelliJ IDEA.
User: user
Date: 2020/2/19
Time: 21:16
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
@ -22,6 +15,7 @@
<tr>
<td><label for="dorm3">宿舍号</label></td>
<td>
<!-- 下拉选择框,用于选择宿舍楼 -->
<select class="form-control" name="dorm1" id="dorm1">
<option value="西六" selected>西六</option>
<option value="西七">西七</option>
@ -29,12 +23,17 @@
<option value="西十三">西十三</option>
</select>
</td>
<td><select class="form-control" name="dorm2" id="dorm2">
<td>
<!-- 下拉选择框,用于选择宿舍层 -->
<select class="form-control" name="dorm2" id="dorm2">
<option value="A" selected>A</option>
<option value="B">B</option>
</select></td>
</select>
</td>
<td>
<!-- 输入框,用于直接输入宿舍号 -->
<input type="text" name="dorm3" placeholder="请直接输入宿舍号" class="form-control" id="dorm3" list="did" required>
<!-- 数据列表,提供预定义的宿舍号选项 -->
<datalist id="did">
<option value="101" />
<option value="102" />
@ -66,9 +65,15 @@
</td>
</tr>
<tr>
<td><label for="dorm_intro">宿舍简介</label></td>
<td>
<label for="dorm_intro">宿舍简介</label>
</td>
<td colspan="3">
<textarea class="form-control" id="dorm_intro" name="dorm_intro" cols="2" maxlength="80" placeholder="请输入宿舍简介" required="required"></textarea>
<!-- 文本区域,用于输入宿舍简介 -->
<textarea class="form-control" id="dorm_intro" name="dorm_intro" cols="2"
maxlength="80" placeholder="请输入宿舍简介" required="required">
</textarea>
</td>
</tr>
<tr>
@ -76,7 +81,10 @@
<label for="dorm_rps">宿舍奖惩</label>
</td>
<td colspan="3">
<input type="text" name="dorm_rps" class="form-control" id="dorm_rps" value="无" placeholder="" list="rpsList" required>
<!-- 输入框,用于输入宿舍奖惩信息 -->
<input type="text" name="dorm_rps" class="form-control" id="dorm_rps" value="无"
placeholder="" list="rpsList" required>
<!-- 数据列表,提供预定义的宿舍奖惩选项 -->
<datalist id="rpsList">
<option value="年度最佳宿舍" />
<option value="年度活跃宿舍" />
@ -92,12 +100,14 @@
<label for="dorm_leader">宿舍长</label>
</td>
<td colspan="3">
<!-- 输入框,用于输入宿舍长姓名 -->
<input type="text" name="dorm_leader" class="form-control" id="dorm_leader" required>
</td>
</tr>
<tr>
<td><label for="teacher">育人导师</label></td>
<td colspan="3">
<!-- 下拉选择框,用于选择导师 -->
<select class="form-control" name="teacher" id="teacher">
<option value="小李" selected>小李</option>
<option value="小王">小王</option>
@ -109,7 +119,9 @@
</tr>
<tr>
<td colspan="4">
<!-- 确认添加按钮 -->
<button type="button" id="add-dorm" class="btn btn-primary">确认添加</button>
<!-- 返回列表按钮 -->
<a href="javascript:window.history.back(-1)" target="_self" class="btn btn-default">返回列表</a>
</td>
</tr>
@ -117,75 +129,133 @@
</table>
</form>
<script>
$("#dorm3").change(function () {
// 当宿舍号输入框的值发生变化时触发
$("#dorm3").change(function ()
{
// 获取楼栋选择框的值
var d1 = $("#dorm1").val();
// 获取楼层选择框的值
var d2 = $("#dorm2").val();
// 获取宿舍号输入框的值并去除两端空格
var dorm3 = $("#dorm3").val().trim();
// 拼接成完整的宿舍ID
var dorm_id = d1+""+d2+""+dorm3;
$.ajax({
url: "${pageContext.request.contextPath}/dorm/isExist",//要请求的服务器url
//这是一个对象表示请求的参数两个参数method=ajax&val=xxx服务器可以通过request.getParameter()来获取
//data:{method:"ajaxTest",val:value},
data: {
// 发送的数据
dorm_id:dorm_id
},
type: "POST", //请求方式为POST
//请求方式为POST
type: "POST",
// 期望服务器返回JSON格式的数据
dataType: "json",
success:function(result){ //这个方法会在服务器执行成功时被调用 参数data就是服务器返回的值(现在是json类型)
success:function(result)//这个方法会在服务器执行成功时被调用 参数data就是服务器返回的值(现在是json类型)
{
//alert(result);
if(result){
if(result)
{// 如果返回结果为真,表示宿舍已存在
// 弹出提示信息
layer.msg('该宿舍已存在,请重新注册!');
}
}
});
});
$("#add-dorm").click(function () {
// 当点击“确认添加”按钮时触发
$("#add-dorm").click(function ()
{
// 获取宿舍号输入框的值并去除两端空格
var dorm3 = $("#dorm3").val().trim();
// 获取宿舍简介输入框的值并去除两端空格
var dorm_intro = $("#dorm_intro").val().trim();
// 获取宿舍奖惩输入框的值并去除两端空格
var dorm_rps = $("#dorm_rps").val().trim();
// 获取宿舍长输入框的值并去除两端空格
var dorm_leader = $("#dorm_leader").val().trim();
// 获取导师选择框的值并去除两端空格
var teacher = $("#teacher").val().trim();
if (dorm3.length == 0 || dorm_intro.length == 0 || dorm_rps.length == 0 || dorm_leader == 0 || teacher.length == 0) {
// 检查所有字段是否为空
if (dorm3.length == 0 || dorm_intro.length == 0 || dorm_rps.length == 0
|| dorm_leader == 0 || teacher.length == 0)
{
// 如果有任意一个字段为空,弹出提示信息
layer.msg('字段不能为空');
// 终止函数执行
return false;
}
if (${sessionScope.adminInfo.power < 2}) {
// 检查用户权限是否足够
if (${sessionScope.adminInfo.power < 2})
{
// 如果权限不足,弹出提示信息
layer.msg('权限不足');
return false;
}
// 获取楼栋选择框的值
var d1 = $("#dorm1").val();
// 获取楼层选择框的值
var d2 = $("#dorm2").val();
// 拼接成完整的宿舍ID
var dorm_id = d1+""+d2+""+dorm3;
//alert(dorm_id);
$.ajax({
$.ajax({// 发送AJAX请求到服务器进行添加操作
url: "${pageContext.request.contextPath}/dorm/add",//要请求的服务器url
//这是一个对象表示请求的参数两个参数method=ajax&val=xxx服务器可以通过request.getParameter()来获取
//data:{method:"ajaxTest",val:value},
data: {
// 发送的宿舍ID
dorm_id:dorm_id,
// 发送的宿舍简介
dorm_intro:dorm_intro,
// 发送的宿舍奖惩
dorm_rps: dorm_rps,
// 发送的宿舍长
dorm_leader:dorm_leader,
// 发送的导师
teacher: teacher,
},
type: "POST", //请求方式为POST
dataType: "json",
success:function(result){ //这个方法会在服务器执行成功时被调用 参数data就是服务器返回的值(现在是json类型)
success:function(result)//这个方法会在服务器执行成功时被调用 参数data就是服务器返回的值(现在是json类型)
{
//alert(result);
if(result){
if(result)
{
// 弹出提示信息
layer.msg('添加成功');
if (${sessionScope.adminInfo.power == 2}) {
setTimeout(function () {window.location.href='${pageContext.request.contextPath}/dorm/byTeacher?uid=${sessionScope.adminInfo.uid}';},2000);
// 如果用户权限为2跳转到教师管理的页面
if (${sessionScope.adminInfo.power == 2})
{
setTimeout(function () {window.location.href='${pageContext.request.contextPath
}/dorm/byTeacher?uid=${sessionScope.adminInfo.uid}';},2000);
// 终止函数执行
return flase;
}
setTimeout(function () {window.location.href='${pageContext.request.contextPath}/dorm/findAll';},2000);
}else {
// 否则跳转到宿舍列表页面
setTimeout(function () {window.location.href='${pageContext.request.contextPath
}/dorm/findAll';},2000);
}
else
{// 如果返回结果为假,表示添加失败
layer.msg('添加失败,请重新添加');
if (${sessionScope.adminInfo.power == 2}) {
setTimeout(function () {window.location.href='${pageContext.request.contextPath}/dorm/byTeacher?uid=${sessionScope.adminInfo.uid}';},2000);
// 如果用户权限为2跳转到教师管理的页面
if (${sessionScope.adminInfo.power == 2})
{
setTimeout(function () {window.location.href='${pageContext.request.contextPath
}/dorm/byTeacher?uid=${sessionScope.adminInfo.uid}';},2000);
return flase;
}
// 否则跳转到宿舍列表页面
setTimeout(function () {window.location.href='${pageContext.request.contextPath}/dorm/findAll';},2000);
}
}

@ -1,16 +1,16 @@
<!-- 生成一个宿舍信息管理页面-->
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
Created by IntelliJ IDEA.
User: user
Date: 2020/2/19
Time: 21:16
To change this template use File | Settings | File Templates.
--%>
<!-- 引入JSTL标签库并定义前缀c-->
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!-- 设置页面内容类型为HTML字符编码为UTF-8使用的编程语言为Java-->
<html>
<!-- 定义HTML文档的根元素-->
<head>
<!-- 包含文档的头部信息-->
<title>Title</title>
<!-- 设置网页标题为“Title”-->
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.css">
<!-- 引入Bootstrap样式表路径是相对于当前请求上下文的CSS文件夹下的bootstrap.css-->
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.1.1.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/bootstrap.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/layer/layer.js"></script>
@ -18,31 +18,45 @@
<body>
<br />
<form>
<!-- 表格用于显示和编辑宿舍信息 -->
<table class="table" style="width: 100%;text-align: center;">
<tbody>
<!-- 宿舍号输入框 -->
<tr>
<td><label for="dorm_id">宿舍号</label></td>
<td>
<label for="dorm_id">宿舍号</label>
</td>
<td>
<!-- 隐藏的输入框用于存储宿舍ID -->
<input type="hidden" id="id" name="id" value="${dorm.id}">
<!-- 根据管理员权限判断是否可编辑宿舍号 -->
<c:if test="${sessionScope.adminInfo.power > 3}">
<input type="text" name="dorm_id" placeholder="例:西七B209" value="${dorm.dorm_id}" class="form-control" id="dorm_id" required>
<input type="text" name="dorm_id" placeholder="例:西七B209" value="${dorm.dorm_id}" class="form-control"
id="dorm_id" required>
</c:if>
<c:if test="${sessionScope.adminInfo.power <= 3}">
<input type="text" name="dorm_id" placeholder="" value="${dorm.dorm_id}" readonly class="form-control" id="dorm_id" required>
<input type="text" name="dorm_id" placeholder="" value="${dorm.dorm_id}" readonly class="form-control"
id="dorm_id" required>
</c:if>
</td>
</tr>
<!-- 宿舍简介输入框 -->
<tr>
<td><label for="dorm_intro">宿舍简介</label></td>
<td>
<label for="dorm_intro">宿舍简介</label>
</td>
<td colspan="3">
<input class="form-control" id="dorm_intro" value="${dorm.dorm_intro}" name="dorm_intro" cols="2" maxlength="80" placeholder="请输入宿舍简介" required="required">
<input class="form-control" id="dorm_intro" value="${dorm.dorm_intro}" name="dorm_intro" cols="2"
maxlength="80" placeholder="请输入宿舍简介" required="required">
</td>
</tr>
<!-- 宿舍奖惩选择框 -->
<tr>
<td>
<label for="dorm_rps">宿舍奖惩</label>
</td>
<td colspan="3">
<!-- 根据当前宿舍的奖惩类型,动态生成下拉菜单选项 -->
<c:if test="${dorm.dorm_rps == '年度最佳宿舍'}">
<select class="form-control" name="dorm_rps" id="dorm_rps">
<option value="无" selected>无</option>
@ -122,6 +136,7 @@
</c:if>
</td>
</tr>
<!-- 宿舍长输入框 -->
<tr>
<td>
<label for="dorm_leader">宿舍长</label>
@ -130,9 +145,13 @@
<input type="text" name="dorm_leader" value="${dorm.dorm_leader}" class="form-control" id="dorm_leader" required>
</td>
</tr>
<!-- 育人导师选择框 -->
<tr>
<td><label for="teacher">育人导师</label></td>
<td>
<label for="teacher">育人导师</label>
</td>
<td colspan="3">
<!-- 根据当前宿舍的育人导师,动态生成下拉菜单选项 -->
<c:if test="${dorm.teacher == '小李'}">
<select class="form-control" name="teacher" id="teacher">
<option value="小李" selected>小李</option>
@ -190,7 +209,10 @@
</table>
</form>
<script>
$("#update-dorm").click(function () {
// 当点击id为"update-dorm"的元素时,执行以下函数
$("#update-dorm").click(function ()
{
// 获取并去除输入框中id、dorm_id、dorm_intro、dorm_rps、dorm_leader和teacher的值的前后空格
var id = $("#id").val().trim();
var dorm_id = $("#dorm_id").val().trim();
var dorm_intro = $("#dorm_intro").val().trim();
@ -198,14 +220,22 @@
var dorm_leader = $("#dorm_leader").val().trim();
var teacher = $("#teacher").val().trim();
if (id.length == 0 || dorm_id.length == 0 || dorm_intro.length == 0 || dorm_rps.length == 0 || dorm_leader == 0 || teacher.length == 0) {
// 检查是否有任何一个字段为空如果有则弹出提示信息并返回false阻止后续代码执行
if (id.length == 0 || dorm_id.length == 0 || dorm_intro.length == 0 || dorm_rps.length == 0
|| dorm_leader == 0 || teacher.length == 0)
{
layer.msg('字段不能为空');
return false;
}
if (${sessionScope.adminInfo.power < 1}) {
// 检查当前用户的权限是否小于1如果是则弹出提示信息并返回false阻止后续代码执行
if (${sessionScope.adminInfo.power < 1})
{
layer.msg('权限不足');
return false;
}
// 使用AJAX发送POST请求到服务器进行数据更新操作
$.ajax({
url: "${pageContext.request.contextPath}/dorm/update",//要请求的服务器url
//这是一个对象表示请求的参数两个参数method=ajax&val=xxx服务器可以通过request.getParameter()来获取
@ -219,33 +249,52 @@
teacher: teacher,
},
type: "POST", // 请求方式为POST
dataType: "json",
success:function(result){ //这个方法会在服务器执行成功时被调用 参数data就是服务器返回的值(现在是json类型)
dataType: "json",// 预期服务器返回的数据类型为JSON
success:function(result)// 请求成功时的回调函数参数result是服务器返回的数据
{
//alert(result);
if(result){
if(result)
{
layer.msg('修改成功!');
if (${sessionScope.adminInfo.power == 1}) {
// 根据用户权限不同,跳转到不同的页面
if (${sessionScope.adminInfo.power == 1})
{
setTimeout(function () {window.location.href='${pageContext.request.contextPath}/dorm/look?uid=${sessionScope.adminInfo.uid}';},2000);
}
if (${sessionScope.adminInfo.power == 2}) {
if (${sessionScope.adminInfo.power == 2})
{
setTimeout(function () {window.location.href='${pageContext.request.contextPath}/dorm/byTeacher?uid=${sessionScope.adminInfo.uid}';},2000);
return flase;
}
if (${sessionScope.adminInfo.power > 2}) {
if (${sessionScope.adminInfo.power > 2})
{
setTimeout(function () {window.location.href='${pageContext.request.contextPath}/dorm/findAll';},2000);
}
}else {
}
else
{
// 如果服务器返回的结果为假(即修改失败)
layer.msg('修改失败,请联系管理员');
if (${sessionScope.adminInfo.power == 1}) {
if (${sessionScope.adminInfo.power == 1})
{
setTimeout(function () {window.location.href='${pageContext.request.contextPath}/dorm/look?uid=${sessionScope.adminInfo.uid}';},2000);
}
if (${sessionScope.adminInfo.power == 2}) {
if (${sessionScope.adminInfo.power == 2})
{
setTimeout(function () {window.location.href='${pageContext.request.contextPath}/dorm/byTeacher?uid=${sessionScope.adminInfo.uid}';},2000);
return flase;
}
if (${sessionScope.adminInfo.power > 2}) {
if (${sessionScope.adminInfo.power > 2})
{
setTimeout(function () {window.location.href='${pageContext.request.contextPath}/dorm/findAll';},2000);
}
}
}
});

@ -26,17 +26,22 @@
<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<script>
function changePageSize() {
function changePageSize()
{
//获取下拉框的值
var pageSize = $("#changePageSize").val();
//向服务器发送请求,改变每页显示条数
location.href = "${pageContext.request.contextPath}/dorm/findAll?page=1&size="+ pageSize;
}
$("#serarch_btn").click(function () {
$("#serarch_btn").click(function ()
{
var keyword = $("#keyword").val();
location.href="${pageContext.request.contextPath}/dorm/findAll?page=1&size=5&keyword="+keyword;
});
$("#refresh").click(function () {
$("#refresh").click(function ()
{
$("#myform").reset();
location.href="${pageContext.request.contextPath}/dorm/findAll?page=1&size=5";
});
@ -85,6 +90,7 @@
<th style="text-align: center">宿舍奖惩</th>
<th style="text-align: center">宿舍长</th>
<th style="text-align: center">育人导师</th>
<!--当前用户的权限大于2则显示“操作”列-->
<c:if test="${sessionScope.adminInfo.power > 2}">
<th style="text-align: center">操作</th>
</c:if>
@ -93,6 +99,8 @@
<%
int j = 1;
%>
<!--通过JSTL标签<c:forEach>循环遍历pageInfo.list中的每个宿舍对象dorm-->
<c:forEach items="${pageInfo.list}" var="dorm">
<tr id="light" style="text-align: center">
<td><%=j++%></td>
@ -118,6 +126,7 @@
</tr>
</tbody>
</table>
<!--关闭表格和外层容器的标签-->
</div>
<div class="pull-left">
<div class="form-group form-inline">
@ -186,7 +195,8 @@
<script>
//查看详情
function look(id) {
function look(id)
{
layer.open({
type: 2,
title:'宿舍详情',
@ -194,14 +204,20 @@
area: ['800px', '430px'], //宽高
content: '${pageContext.request.contextPath}/dorm/look?id='+id
});
}
//导出Excel操作
function exportInfo(power) {
if (power < 3) {
function exportInfo(power)
{
if (power < 3)
{
layer.msg('对不起,您没有权限导出宿舍信息');
return false;
}
layer.confirm('确定导出所有宿舍数据吗?',function (index) {
layer.confirm('确定导出所有宿舍数据吗?',function (index)
{
location.href="${pageContext.request.contextPath}/dorm/export";
layer.close(index);
});

@ -96,21 +96,25 @@
</table>
</form>
<script>
$(function () {
$(function ()
{
//ajax校验学号已被注册
$("#sno").change(function () {
$("#sno").change(function ()
{
//取sno的值
var sno = $(this).val();
//ajax异步请求
$.get("${pageContext.request.contextPath}/student/isExist",{"sno":sno},function (date) {
//$(".error").html(msg);
if (date) {
if (date)
{
layer.msg('学号已被注册,请重新输入!');
return false;
}
});
});
});
$("#add-student").click(function () {
var name = $("#name").val().trim();
var sex = $("#sex").val().trim();
@ -122,10 +126,12 @@
var teacher = $("#teacher").val().trim();
var status = $("#status").val().trim();
if (name == 0 || sex == 0 || sno == 0 || stu_class == 0 || phone == 0 || place == 0 || teacher == 0) {
if (name == 0 || sex == 0 || sno == 0 || stu_class == 0 || phone == 0 || place == 0 || teacher == 0)
{
layer.msg('字段不能为空');
return false;
}
$.ajax({
url: "${pageContext.request.contextPath}/student/add",//要请求的服务器url
//这是一个对象表示请求的参数两个参数method=ajax&val=xxx服务器可以通过request.getParameter()来获取
@ -141,14 +147,19 @@
teacher:teacher,
status:status
},
type: "POST", //请求方式为POST
dataType: "json",
success:function(result){ //这个方法会在服务器执行成功时被调用 参数data就是服务器返回的值(现在是json类型)
success:function(result)
{ //这个方法会在服务器执行成功时被调用 参数data就是服务器返回的值(现在是json类型)
//alert(result);
if(result){
if(result)
{
layer.msg('添加成功!');
setTimeout(function () {window.location.href='${pageContext.request.contextPath}/dorm/byDorm_leader?uid=${sessionScope.adminInfo.uid}';},2000);
}else {
}
else
{
layer.msg('添加失败,请联系管理员');
setTimeout(function () {window.location.href='${pageContext.request.contextPath}/dorm/byDorm_leader?uid=${sessionScope.adminInfo.uid}';},2000);
}

@ -26,17 +26,22 @@
<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<script>
function changePageSize() {
function changePageSize()
{
//获取下拉框的值
var pageSize = $("#changePageSize").val();
//向服务器发送请求,改变每页显示条数
location.href = "${pageContext.request.contextPath}/student/findAll?page=1&size="+ pageSize;
}
$("#serarch_btn").click(function () {
$("#serarch_btn").click(function ()
{
var keyword = $("#keyword").val();
location.href="${pageContext.request.contextPath}/student/findAll?page=1&size=5&keyword="+keyword;
});
$("#refresh").click(function () {
$("#refresh").click(function ()
{
$("#myform").reset();
location.href="${pageContext.request.contextPath}/student/findAll?page=1&size=5";
});

@ -26,20 +26,26 @@
<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<script>
function changePageSize() {
function changePageSize()
{
//获取下拉框的值
var pageSize = $("#changePageSize").val();
//向服务器发送请求,改变每页显示条数
location.href = "${pageContext.request.contextPath}/dorm/findAll?page=1&size="+ pageSize;
}
$("#serarch_btn").click(function () {
$("#serarch_btn").click(function ()
{
var keyword = $("#keyword").val();
location.href="${pageContext.request.contextPath}/dorm/findAll?page=1&size=5&keyword="+keyword;
});
$("#refresh").click(function () {
$("#refresh").click(function ()
{
$("#myform").reset();
location.href="${pageContext.request.contextPath}/dorm/findAll?page=1&size=5";
});
</script>
</head>
<body>
@ -107,8 +113,8 @@
</div>
<script>
//查看详情
function look(id) {
function look(id) //查看详情
{
layer.open({
type: 2,
title:'宿舍详情',

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save