目录:
(1)搜索员工
(2)查看会议室
(3)会议室详情
(4)添加会议室
(1)搜索员工
创建EmployeeController:
public static final Integer PAGE_SIZE = 10;//定义默认显示10条
/**
* 分页查询员工
* 获取员工的数量
*
* @param employee 员工
* @param page 页数
* @param model
* @return 搜索员工页面
*/
@RequestMapping("/searchemployees")
public String getAllEmployees(Employee employee, @RequestParam(defaultValue = "1") Integer page, Model model){
List<Employee> emps = employeeService.getAllEmps(employee,page,PAGE_SIZE);//分页搜索员工方法
Long total = employeeService.getTotal(employee);//查询员工总条数方法
model.addAttribute("emps",emps);
model.addAttribute("total",total);//总条数
model.addAttribute("page",page);//当前页
model.addAttribute("pagenum",total%PAGE_SIZE == 0?total/PAGE_SIZE :total/PAGE_SIZE+1);//可以分为多少页
return "searchemployees";
}
在EmployeeService:添加方法:
//分页搜索员工方法
public List<Employee> getAllEmps(Employee employee, Integer page, Integer pageSize) {
//这个page是从第几行数据开始查
page = (page - 1)*pageSize;
return employeeMapper.getAllEmps(employee,page,pageSize);
}
//查询员工总条数方法
public Long getTotal(Employee employee) {
return employeeMapper.getTotal(employee);
}
在EmployeeMapper接口:
//搜索员工方法
List<Employee> getAllEmps(@Param("emp") Employee employee, @Param("page") Integer page, @Param("pageSize") Integer pageSize);
//查询员工总条数方法
Long getTotal(Employee employee);
在EmployeeMapper.xml添加sql语句:
<!--分页搜索员所有员工方法-->
<select id="getAllEmps" resultType="com.xzb.meeting.model.Employee">
select *
from employee
where status = #{emp.status}
<if test="emp.employeeName != null">
and employeename like concat('%',#{emp.employeeName},'%')
</if>
<if test="emp.username != null">
and username like concat('%',#{emp.username},'%')
</if>
limit #{page},#{pageSize}
</select>
<!--查询员工总条数方法-->
<select id="getTotal" resultType="java.lang.Long">
select count(*)
from employee
where status = #{status}
<if test="employeeName != null">
and employeename like concat('%',#{employeeName},'%')
</if>
<if test="username != null">
and username like concat('%',#{username},'%')
</if>
</select>
删除页面searchemployees.ftl的固定代码:
添加:
修改form表单:添加action name属性
<form action="/admin/searchemployees" method="get">
<fieldset>
<legend>搜索员工</legend>
<table class="formtable">
<tr>
<td>姓名:</td>
<td>
<input type="text" id="employeename" name="employeeName" value="<#if employee??>${employee.employeeName!''}</#if>" maxlength="20"/>
</td>
<td>账号名:</td>
<td>
<input type="text" id="accountname" name="username" value="<#if employee??>${employee.username!''}</#if>" maxlength="20"/>
</td>
<td>状态:</td>
<td>
<#if employee??>
<#if employee.status == 0>
<input type="radio" id="status" name="status" value="1"/><label>已批准</label>
<input checked="checked" type="radio" id="status" name="status" value="0"/>
<label>待审批</label>
<input type="radio" id="status" name="status" value="2"/><label>已关闭</label>
<#elseif employee.status == 1>
<input checked="checked" type="radio" id="status" name="status" value="1"/>
<label>已批准</label>
<input type="radio" id="status" name="status" value="0"/>
<label>待审批</label>
<input type="radio" id="status" name="status" value="2"/><label>已关闭</label>
<#elseif employee.status == 2>
<input type="radio" id="status" name="status" value="1"/>
<label>已批准</label>
<input type="radio" id="status" name="status" value="0"/>
<label>待审批</label>
<input checked="checked" type="radio" id="status" name="status" value="2"/>
<label>已关闭</label>
</#if>
<#else >
<input type="radio" id="status" name="status" value="1"
checked="checked"/><label>已批准</label>
<input type="radio" id="status" name="status" value="0"/><label>待审批</label>
<input type="radio" id="status" name="status" value="2"/><label>已关闭</label>
</#if>
</td>
</tr>
<tr>
<td colspan="6" class="command">
<input type="submit" class="clickbutton" value="查询"/>
<input type="reset" id="myset" class="clickbutton" value="重置" onclick="clear()"/>
</td>
</tr>
</table>
</fieldset>
</form>
<h3 style="text-align:center;color:black">查询结果</h3>
<div class="pager-header">
<div class="header-info">
共<span class="info-number">${total}</span>条结果,
分成<span class="info-number">${pagenum}</span>页显示,
当前第<span class="info-number">${page}</span>页
</div>
<div class="header-nav">
<a type="button" class="clickbutton" href="/admin/searchemployees?status=${employee.status}&page=1">首页</a>
<a type="button" class="clickbutton"
href="/admin/searchemployees?status=${employee.status}&page=${page-1}">上页</a>
<a type="button" class="clickbutton"
href="/admin/searchemployees?status=${employee.status}&page=${page+1}">下页</a>
<a type="button" class="clickbutton"
href="/admin/searchemployees?status=${employee.status}&page=${pagenum}">末页</a>
<form action="/admin/searchemployees"
style="display: inline"
method="get">
<input type="hidden" name="status" value="${employee.status}">
跳到第<input name="page" type="text" id="pagenum" class="nav-number"/>页
<input type="submit" class="clickbutton" value="跳转"/>
</form>
</div>
</div>
在EmployeeController:
/**
* 关闭账号 修改状态为2
*
* @param id 员工编号
* @return 重定向到审批通过的员工页面
*/
@RequestMapping("/updateemp")
public String updateemp(Integer id){
employeeService.updateStatus(id,2);
return "redirect:/admin/searchemployees?status=1";
}
EmployeeService:
//更新用户状态(status)
public Integer updateStatus(Integer employeeid, Integer status) {
return employeeMapper.updateStatus(employeeid,status);
}
在EmoloyeeMapper:
//更新用户状态(status)
Integer updateStatus(@Param("employeeid") Integer employeeid,@Param("status") Integer status);
EmoloyeeMapper.xml:sql语句
<!--更新用户状态(status)-->
<update id="updateStatus">
update employee
set status = #{status}
where employeeid = #{employeeid}
</update>
(2)查看会议室
创建MeetingRoomController:
创建Meetingroom实体类:
创建MeetingMapper接口、MeetingMapper.xml
创建MeetingRoomService:
在MeetingRoomController加方法:
//查询会议室,并进行会议室页面的跳转
@RequestMapping("/meetingrooms")
public String meetingrooms(Model model){
model.addAttribute("mrs",meetingRoomService.getAllMr());//调用查询所有会议室名称的方法
return "meetingrooms";
}
在MeetingRoomService添加这个方法:
//查询所有会议室
public List<MeetingRoom> getAllMr() {
return meetingRoomMapper.getAllMr();
}
在MeetingRoomMapper添加方法:
//查询所有会议室
public List<MeetingRoom> getAllMr();
在MeetingRoomMapper.xml添加sql语句:
<!--查询所有会议室-->
<select id="getAllMr" resultType="com.xzb.meeting.model.MeetingRoom">
select *
from meetingroom
</select>
删除meetingroom页面的固定数据:从数据库中获取数据
(3)会议室详情
修改a标签的连接:
在MeetingRoomController:添加方法:
//会议室详情页面
@RequestMapping("/roomdetails")
public String roomdetails(Integer roomid,Model model){
model.addAttribute("mr",meetingRoomService.getMrById(roomid));
return "roomdetails";
}
在MeetingRoomService添加方法:
//根据roomid获取对应的会议室
public MeetingRoom getMrById(Integer roomid) {
return meetingRoomMapper.getMrById(roomid);
}
在MeetingRoomMapper添加方法:
//根据roomid获取对应的会议室
MeetingRoom getMrById(Integer roomid);
MeetingRoomMapper.xml添加对应的sql语句:
<!--根据roomid获取对应的会议室-->
<select id="getMrById" resultType="com.xzb.meeting.model.MeetingRoom">
select *
from meetingroom
where roomid = #{roomid}
</select>
修改meetingdetail会议室详情页面:
<form action="/updateroom" method="post">
<fieldset>
<legend>会议室信息</legend>
<table class="formtable">
<tr>
<td>门牌号:</td>
<td>
<input id="roomnumber" name="roomnum" type="text" value="${mr.roomnum}" maxlength="10"/>
</td>
</tr>
<tr>
<td>会议室名称:</td>
<td>
<input id="capacity" name="roomname" type="text" value="${mr.roomname}" maxlength="20"/>
</td>
</tr>
<tr>
<td>最多容纳人数:</td>
<td>
<input id="roomcapacity" name="capacity" type="text" value="${mr.capacity}"/>
</td>
</tr>
<tr>
<td>当前状态:</td>
<td>
<#if mr.status==0>
<input type="radio" id="status" name="status" checked="checked" value="0"/><label
for="status">启用</label>
<input type="radio" id="status" value="1" name="status"/><label for="status">已占用</label>
<#else >
<input type="radio" id="status" name="status" value="0"/><label for="status">启用</label>
<input type="radio" id="status" name="status" value="1" checked="checked"/><label for="status"
>已占用</label>
</#if>
</td>
</tr>
<tr>
<td>备注:</td>
<td>
<textarea id="description" name="description" maxlength="200" rows="5"
cols="60">${mr.description}</textarea>
</td>
</tr>
<tr>
<td colspan="2" class="command">
<input type="hidden" value="${mr.roomid}" name="roomid">
<input type="submit" value="确认修改" class="clickbutton"/>
<input type="button" class="clickbutton" value="返回" onclick="window.history.back();"/>
</td>
</tr>
</table>
</fieldset>
</form>
点击:
修改会议室:
在MeetingRoomController:添加修改请求:
/**
* 更新会议房间信息
*
* @param meetingRoom MeetingRoom
* @return Integer
*/
@RequestMapping("/updateroom")
public String updateroom(MeetingRoom meetingRoom){
Integer result = meetingRoomService.updateroom(meetingRoom);
if (result == 1){
return "redirect:/meetingrooms";//更新成功跳转会议室页面
}else {
return "forward:/roomdetails?roomid="+meetingRoom.getRoomid();//失败还返回这个页面详情更改页面
}
}
在MeetingRoomService添加方法:
//更新会议房间信息
public Integer updateroom(MeetingRoom meetingRoom) {
return meetingRoomMapper.updateroom(meetingRoom);
}
在MeetingRoomMapper添加修改方法:
//更新会议房间信息
Integer updateroom(MeetingRoom meetingRoom);
MeetingRoomMapper.xml:添加sql语句
<!--更新会议房间信息-->
<update id="updateroom">
update meetingroom
set roomnum = #{roomnum},roomname = #{roomname},capacity = #{capacity},status = #{status},description = #{description}
where roomid = #{roomid}
</update>
给详情页面的表单添加form action
添加name属性:
添加roomid:
(4)添加会议室
在MeetingRoomController中添加:跳转提加页面请求:
//跳转到添加添加会议室页面
@RequestMapping("/admin/addmeetingroom")
public String addmeetingroom(){
return "addmeetingroom";
}
添加请求:
//添加会议室请求
@RequestMapping("/admin/doAddMr")
public String doAddMr(MeetingRoom meetingRoom){
meetingRoomService.doAddMr(meetingRoom);
return "redirect:/meetingrooms";//添加成功跳转会议室页面
}
在MeetingRoomServoce添加这个方法:
//添加会议室请求
public Integer doAddMr(MeetingRoom meetingRoom) {
return meetingRoomMapper.doAddMr(meetingRoom);
}
在MeetingRoomMapper添加:
//添加会议室请求
Integer doAddMr(MeetingRoom meetingRoom);
MeetingRoomMapper.xml添加sql语句:
<!--添加会议室请求-->
<insert id="doAddMr">
insert into meetingroom (roomnum,roomname,capacity,status,description)
values (#{roomnum},#{roomname},#{capacity},#{status},#{description})
</insert>
给添加会议页面:修改form表单:name属性
<form action="/admin/doAddMr" method="post">
<fieldset>
<legend>会议室信息</legend>
<table class="formtable">
<tr>
<td>门牌号:</td>
<td>
<input name="roomnum" id="roomnumber" type="text" placeholder="例如:201" maxlength="10"/>
</td>
</tr>
<tr>
<td>会议室名称:</td>
<td>
<input name="roomname" id="capacity" type="text" placeholder="例如:第一会议室" maxlength="20"/>
</td>
</tr>
<tr>
<td>最多容纳人数:</td>
<td>
<input name="capacity" id="roomcapacity" type="text" placeholder="填写一个正整数"/>
</td>
</tr>
<tr>
<td>当前状态:</td>
<td>
<input type="radio" id="status" name="status" checked="checked" value="0"/><label for="status">启用</label>
<input type="radio" id="status" name="status" value="1"/><label for="status" >已占用</label>
</td>
</tr>
<tr>
<td>备注:</td>
<td>
<textarea name="description" id="description" maxlength="200" rows="5" cols="60" placeholder="200字以内的文字描述"></textarea>
</td>
</tr>
<tr>
<td colspan="2" class="command">
<input type="submit" value="添加" class="clickbutton"/>
<input type="reset" value="重置" class="clickbutton"/>
</td>
</tr>
</table>
</fieldset>
</form>