spring boot 换宿舍 时间格式

spring boot 换宿舍

1.展示层
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
  <head>
  <title>My JSP 'list.jsp' starting page</title>
  <link rel="stylesheet" href="<%=path%>/css/index_work.css"></link>
  <script type="text/javascript" src="<%=path%>/js/jquery-1.7.js"></script></head>
  <script type="text/javascript">
  	$(function(){
  		$(":radio[value=${stu.sex}]").attr("checked",true);
  		
  	})
  </script>
  <body>
		<form action="update" method="post">
					<input type="text" name="sid" value="${stu.sid }">
			<table>
				<tr>
					<td>姓名:${stu.sname }</td>
				</tr>
				<tr>
					<td>性别:<input type="radio" name="sex" value="男"><input type="radio" name="sex" value="女"></td>
				</tr>
				<tr>
					<td>所属学院:${stu.scollege }</td>
				</tr>
				<tr>
					<td>当前宿舍:${stu.dname }</td>
				</tr>
				<tr>
					<td>可选宿舍:<select name="did">
						<c:forEach items="${list }" var="s">
							<option value="${s.did }">${s.dname }</option>
						</c:forEach>
						</select>
					</td>
				</tr>
				<tr>
					<td><input type="submit" value="修改"></td>
				</tr>
			</table>
		</form>
  </body>
</html>
2.controller层
package com.bwie.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Timer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.bwie.entity.Dorm;
import com.bwie.entity.DormExample;
import com.bwie.entity.DormExample.Criteria;
import com.bwie.entity.Record;
import com.bwie.entity.RecordExample;
import com.bwie.entity.Student;
import com.bwie.mapper.DormMapper;
import com.bwie.mapper.RecordMapper;
import com.bwie.mapper.StudentMapper;
import com.bwie.utils.PageUtils;
import com.github.pagehelper.PageHelper;

@Controller
public class StudentController {

	@Autowired
	StudentMapper studentMapper;
	@Autowired
	DormMapper dormMapper;
	@Autowired
	RecordMapper recordMapper;
	private com.bwie.entity.RecordExample.Criteria criteria;
	private List<Record> list;
	
	@RequestMapping("list")
	public String list(Model model,PageUtils pu,Student stu) {
		//查询总记录数
		/*StudentExample example = new StudentExample();
		Criteria criteria = example.createCriteria();
		criteria.andSnameEqualTo(stu.getSname());*/
		int count = studentMapper.countByExample(null);
		pu.setCount(count);
		//设置分页,开始查询页,每页的大小
		PageHelper.startPage(pu.getStartPage(),pu.getPageSize());
		
		List<Student> list = studentMapper.selectAllStudent();
		//宿舍人数
		for (Student student : list) {
			if(student.getDid()!=null) {
			int num = studentMapper.tjNum(student.getDid());
			student.setNum(num);
			}
		}
		model.addAttribute("list",list);
		model.addAttribute("pu", pu); 
		return "list";
	}
	
	//换宿舍的回想功能
	@RequestMapping("change")
	public String change(Student student,Model model) {
		//查询学生信息
		Student stu = studentMapper.selectByPrimaryKey(student.getSid());
		if(stu.getDid()!=null) {
			Dorm dorm = dormMapper.selectByPrimaryKey(stu.getDid());
			stu.setDname(dorm.getDname());
			}
		//回现学生可选择的宿舍
		DormExample example = new DormExample();
		Criteria criteria = example.createCriteria();
		if(stu.getDid()!=null)
		{	//当宿舍id不为空的时候,排除该id对应的宿舍
			criteria.andDidNotEqualTo(stu.getDid());
		}
		 List<Dorm> list = dormMapper.selectByExample(example);
		 model.addAttribute("list", list);
		 model.addAttribute("stu",stu);
		return "change";
	}
	
	@RequestMapping("update")
	public String update(Model model,Record rec) {
		//修改学生的宿舍号
		 Student student = studentMapper.selectByPrimaryKey(rec.getSid());
		 student.setDid(rec.getDid());
		 studentMapper.updateByPrimaryKey(student);
		//跟新学生的离开信息
		studentMapper.updateLastRecord(rec);
		//添加变更记录
		
		 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");//时间格式
		 String str = sdf.format(new Date());//获取当前时间
		 rec.setEdate(str);
		 rec.setLdate("至今");
		 recordMapper.insert(rec);
		 
		 //查询变更记录表
		 RecordExample example = new RecordExample();
		 criteria = example.createCriteria();
		 criteria.andSidEqualTo(rec.getSid());
		 list = recordMapper.selectByExample(example);
		 model.addAttribute("list", list);
		return "record";
	}
	
	
}

3. StudentMapper层
 //自定义一个两表联查的方法
	List<Student> selectAllStudent();
	//从学生表中统计宿舍id为did的宿舍个数有几个
	@Select("select count(*) from d_student where did = #{did}")
	int tjNum(Integer did);
	@Update("update d_record set ldate = now() where sid=#{sid} and ldate='至今'")
	void updateLastRecord(Record rec);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值