package com.example.kaoqin.controller;
import com.example.kaoqin.entity.Check;
import com.example.kaoqin.service.CheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
/**
* @author example
* @date 2020/2/23 9:50 上午
*/
@Controller
public class CheckController {
@Autowired
private CheckService checkService;
/**
* 一小时的毫秒数
*/
public static final int HOUR = 1000 * 3600;
/**
* 列表页面
*
* @param model
* @return
*/
@RequestMapping(value = "/check", method = RequestMethod.GET)
public String findAll(@RequestParam(value = "query", required = false) String query, Model model) {
List<Check> checkList;
if (query != null && !"".equals(query)) {
checkList = checkService.findByName(query);
} else {
checkList = checkService.findAll();
}
model.addAttribute("checkList", checkList);
return "check/list";
}
/**
* 添加页面
*
* @return
*/
@RequestMapping(value = "/check/add", method = RequestMethod.GET)
public String add() {
return "check/add";
}
/**
* 编辑页面
*
* @return
*/
@RequestMapping(value = "/check/edit/{id}", method = RequestMethod.GET)
public String add(@PathVariable("id") Long id, Model model) {
Check check = checkService.findById(id);
// 如果不存在,则跳到添加页面
if (check == null) {
return "redirect:/check/add";
}
model.addAttribute("check", check);
return "check/edit";
}
/**
* 保存提交(更新提交或新建提交)
*
* @return
*/
@RequestMapping(value = "/check/save", method = RequestMethod.POST)
public String save(@RequestParam(value = "id", required = false) Long id,
@RequestParam(value = "name") String name,
@RequestParam(value = "age") Integer age,
@RequestParam(value = "number") String number,
@RequestParam(value = "checkInTime") String checkInTime,
@RequestParam(value = "checkOutTime") String checkOutTime) throws ParseException {
Check check = new Check();
check.setAge(age);
check.setName(name);
check.setNumber(number);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("YYYY-MM-dd'T'HH:mm");
Date checkInDate = simpleDateFormat.parse(checkInTime);
Date checkOutDate = simpleDateFormat.parse(checkOutTime);
check.setCheckInTime(checkInDate);
check.setCheckOutTime(checkOutDate);
double duration = (checkOutDate.getTime() - checkInDate.getTime()) * 1.0 / HOUR;
check.setDuration(duration);
if (id != null) {
check.setId(id);
checkService.update(check);
} else {
checkService.insert(check);
}
return "redirect:/check";
}
/**
* 删除提交
*
* @return
*/
@RequestMapping(value = "/check/delete/{id}", method = RequestMethod.GET)
public String add(@PathVariable("id") Long id) {
checkService.deleteById(id);
return "redirect:/check";
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
SSM入门项目,SSM增删改查demo+数据库
共46个文件
jsp:8个
css:7个
xml:6个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 16 浏览量
2023-10-12
15:19:06
上传
评论
收藏 446KB ZIP 举报
温馨提示
SSM入门项目,SSM增删改查demo+数据库
资源推荐
资源详情
资源评论
收起资源包目录
sms_demo-master.zip (46个子文件)
sms_demo-master
ssm.sql 1KB
pom.xml 8KB
src
main
resources
mapper
CheckMapper.xml 3KB
spring
spring-mvc.xml 2KB
spring-mybatis.xml 5KB
db.properties 379B
log4j.properties 502B
mybatis
mybatis-config.xml 1KB
java
com
example
kaoqin
mapper
CheckMapper.java 1KB
controller
CheckController.java 3KB
service
CheckService.java 915B
impl
CheckServiceImpl.java 1KB
entity
Check.java 2KB
webapp
plugins
bootstrap-3.3.7
js
bootstrap.js 68KB
npm.js 484B
bootstrap.min.js 36KB
bootstrapValidator.min.js 83KB
css
bootstrap-theme.min.css.map 25KB
bootstrap.min.css 118KB
bootstrap-theme.css.map 47KB
ie10-viewport-bug-workaround.css 433B
bootstrap-theme.css 26KB
bootstrap.css.map 380KB
bootstrap.css 143KB
bootstrap-theme.min.css 23KB
bootstrap.min.css.map 529KB
favicon.ico 5KB
fonts
glyphicons-halflings-regular.svg 106KB
glyphicons-halflings-regular.ttf 44KB
glyphicons-halflings-regular.woff 23KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.woff2 18KB
WEB-INF
web.xml 4KB
index.jsp 446B
static
js
jquery.min.js 95KB
css
jquery-confirm.min.js 27KB
back.css 2KB
jquery-confirm.min.css 22KB
jsp
check
list.jsp 3KB
edit.jsp 4KB
add.jsp 3KB
common
footer.jsp 497B
sidebar.jsp 833B
header.jsp 1KB
nav.jsp 1KB
.gitignore 293B
共 46 条
- 1
资源评论
云哲-吉吉2021
- 粉丝: 3345
- 资源: 1129
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功