我這裏需要存的是年月日時分秒,在數據庫裏存放數據類型是Date格式。
Java實體類裏邊存放了時間戳Timestrap。Oracle確實沒有MySQL那麼隨意,出了太多的問題。
在Java的實體類裏邊,getter方法上邊加上註解:
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
public Timestamp getSubDate() {
return subDate;
}
不加註解的話查詢的時候就會顯示一串的數字。
Dao:
@Update("update t_flow set status=#{status},passDate=#{passDate} where flow_id=#{flow_id}")
int updateFlow(Flow flow);
Service:
public Map<String,Object> updateFlow(Flow flow){
Map<String,Object> map=new HashMap<>();
int result=flowdao.updateFlow(flow);
System.out.println(flow+"sssssssssskkkkkkkkkkkk");
if(result>0){
map.put("status", "ok");
}else{
map.put("status", "error");
}
return map;
}
Controller:
@RequestMapping(value="checkFlow",method=RequestMethod.POST)
@ResponseBody
public Map<String,Object> checkFlow(Flow flow){
return flowservice.updateFlow(flow);
}
JSP:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
String path=request.getContextPath();
String basePath=request.getScheme()+"//"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="<%=path %>/jquery/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="<%=path %>/bootstrap/js/bootstrap.js"></script>
<link type="text/css" rel="stylesheet" href="<%=path %>/bootstrap/css/bootstrap.min.css"/>
<script type="text/javascript" src="<%=path%>/layer/layer.js"></script>
<style type="text/css">
#form{
margin:0 auto;
margin-top:100px;
margin-left:350px;
}
</style>
</head>
<body>
<form class="form-horizontal" role="form" id="fm">
<input type="hidden" name="flow_id" value="${flow.flow_id }"/>
<div id="form">
<div class="form-group">
<label class="col-sm-2 control-label"><span style="color:red;">*</span> 申請人:</label>
<div class="col-sm-3">
<input type="text" class="form-control" name="sq_id" value="${flow.sq_id }" disabled="disabled">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"><span style="color:red;">*</span> 審批人:</label>
<div class="col-sm-3">
<input type="text" class="form-control" name="sq_id" value="${flow.sp_id }" disabled="disabled">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"><span style="color:red;">*</span> 申請標題:</label>
<div class="col-sm-3">
<input type="text" class="form-control" name="flow_title" value="${flow.flow_title }" disabled="disabled">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"><span style="color:red;">*</span> 申請類型:</label>
<div class="col-sm-3">
<input type="text" class="form-control" name="flow_type" value="${flow.flow_type}" disabled="disabled">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"><span style="color:red;">*</span> 申請原因:</label>
<div class="col-sm-3">
<input type="text" class="form-control" name="flow_reason" value="${flow.flow_reason}" disabled="disabled">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">開始時間:</label>
<div class="col-sm-3">
<input type="text" class="form-control" name="begindate" value="${flow.beginDate }" disabled="disabled">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">結束時間:</label>
<div class="col-sm-3">
<input type="text" class="form-control" name="enddate" value="${flow.endDate }" disabled="disabled">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">提交時間:</label>
<div class="col-sm-3">
<input type="text" class="form-control" name="subdate" value="${flow.subDate}" disabled="disabled"/>
</div>
</div>
<input type="hidden" class="form-control" id="passDate" name="passDate" value=""/>
<input type="hidden" class="form-control" id="status" name="status" value=""/>
<br>
<div class="box-footer col-xs-4" style="text-align: center;">
<button type="submit" class="btn btn-primary" id="subBtn1">同意</button>
<button type="submit" class="btn btn-primary" id="subBtn2">拒絕</button>
<button type="submit" class="btn btn-primary" onclick="javascript:window.history.back();">返回</button>
</div>
</div>
</form>
</body>
<script type="text/javascript">
$("#subBtn1").click(function(){
$('#status').val(1);
var time = new Date();
var year = time.getFullYear();
var month = time.getMonth()+1;
var date = time.getDate();
var h = time.getHours();
var m = time.getMinutes();
var s = time.getSeconds();
$("#passDate").val(year+"-"+month+"-"+date+" "+h+":"+m+":"+s);
$.ajax({
method:'post',
url:'${pageContext.request.contextPath}/checkFlow',
data:$('#fm').serialize(),
dataType:'json',
success:function(ret){
if(ret.status=='ok'){
layer.msg('審批成功!',{time:3000,icon:1});
setTimeout(function(){ location.href ='${pageContext.request.contextPath}/flowDataBySpIdInput'; },1000);
}else if(ret.status=='error'){
layer.msg('審批信息失敗!!!接口方法異常,請聯繫管理員!',{time:3000,icon:7});
}
}
})
});
$("#subBtn2").click(function(){
$('#status').val(2);
var time = new Date();
var year = time.getFullYear();
var month = time.getMonth()+1;
var date = time.getDate();
var h = time.getHours();
var m = time.getMinutes();
var s = time.getSeconds();
$("#passDate").val(year+"-"+month+"-"+date+" "+h+":"+m+":"+s);
$.ajax({
method:'post',
url:'${pageContext.request.contextPath}/checkFlow',
data:$('#fm').serialize(),
dataType:'json',
success:function(ret){
if(ret.status=='ok'){
layer.msg('審批成功!',{time:3000,icon:1});
setTimeout(function(){ location.href ='${pageContext.request.contextPath}/flowDataBySpIdInput'; },1000);
}else if(ret.status=='error'){
layer.msg('審批信息失敗!!!接口方法異常,請聯繫管理員!',{time:3000,icon:7});
}
}
})
})
</script>
</html>
數據可以了,ajax有點問題 操作成功後並沒有執行跳轉操作,時間原因 明天修改。