Ajax进行删除更新分页显示页面(JSP+Struts2+Poolman)
项目结构:
数据表设计:
申请表:
My97DatePicker插件及其使用文档免费下载:http://download.csdn.net/detail/u012750578/6597619
显示列表:
批准:
删除:
翻页:
条件查询:
VIEW(Jsp):
apply.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'Apply.jsp' starting page</title>
<script type="text/javascript" src="../js/jquery-1.4.2.js"></script>
<script type="text/javascript" src="../plugs/My97DatePicker/WdatePicker.js"></script>
<script>
var contextPath=$("#contextPath").val();
//文档加载完成时运行
$(function(){
init();
})
function init(){
initSchedTime();
}
function onchage(rv){
if(rv==1){
$("#p1").show();
$("#p2").hide();
$("#p3").show();
}else if(rv==2){
$("#p2").show();
$("#p3").show();
$("#p1").hide();
}else{
$("#p2").hide();
$("#p1").hide();
$("#p3").hide();
}
}
//获取单选框的值
function getapplytype(){
var value="";
var radio=document.getElementsByName("dutyApply.apptype");
for(var i=0;i<radio.length;i++){
value=radio[i].value;
break;
}
return value;
}
//请假申请表单验证
function checkApplyForm(){
var apptype=getapplytype();
if(apptype==1){
if($("#appplace").val().length==0){
alert("请您填入出差地点.");
return false;//不提交表单
}
}else if(apptype==2){
if($("#appplace").val().length==0){
alert("请您填入培训地点");
return false;
}
}
if($("#appreSEOn").val().length==0){
alert("请您填入请假事由.");
return false;
}
var falg=checkDate();
if(falg==false){
return false;
}
}
//验证日期:
function checkDate(){
var sc=$("#startcalender").val();
var ec=$("#endcalender").val();
var st=$("#appSTime").val();
var et=$("#appETime").val();
if(sc.length==0){
alert("请您选择请假开始日期!");
return false;
}
if(ec.length==0){
alert("请您选择请假结束日期!");
return false;
}
sc=sc.substring(0,4)+sc.substring(5,7)+sc.substring(8,10);
ec=ec.substring(0,4)+ec.substring(5,7)+ec.substring(8,10);
if(getSysdate(sc,st)==false){
alert("请假开始时间不能小于当前时间");
return false;
}
if(getSysdate(ec,et)==false){
alert("请假结束时间不能小于当前时间");
return false;
}
if(sc-ec>0){
alert("请假开始日期不能大于请假结束日期");
return false;
}else if(sc==ec){
if(st>=et){
alert("请假开始的时间不能大于或等于请假结束时间");
return false;
}
}
}
function applySubmit(){
var falg=checkApplyForm();
if(falg==false){
return false;
}
param=$("#applyForm").serialize();//ajax form序列化参数,根据name取值,根据表单的id进行参数序列化
var url=contextPath+"/qwsq/addData.action";
SubmitApply(param,url);
}
function SubmitApply(param,url){
//alert(param);
$.ajax({
url:url,
type:"post",
data:param,
dataType:"json",
error:function(XMLHttpRequest,textStatus,errorThrown){
//alert("--"+XMLHttpRequest.redayState+"|"+textStatus+"|"+errorThrown)
},
success:function(data){
//如果后台传送的是list集合就进行循环 var i=0;i<data.length;i++
// var du=data[i];//对象数组
//alert(du.id);//对象值
if(data==1){
alert("申请表提交成功!");
}
else{
alert("申请表提交失败!");
}
}//success
})//ajax
}//函数
//同系统时间比较
function getSysdate(calender,time){
var now = new Date();
var year=now.getFullYear();
var month = now.getMonth()+1 > 9?now.getMonth()+1:'0'+(now.getMonth()+1);
var day = now.getDate()+1 > 9?now.getDate():'0'+now.getDate();
var hours=now.getHours()+1>9?now.getHours():'0'+(now.getHours()+1);
var minutes=now.getMinutes()+1>9?now.getMinutes():'0'+(now.getMinutes());
var strdate =year+"-"+month+"-"+day;
strdate=strdate.substring(0,4)+strdate.substring(5,7)+strdate.substring(8,10)
var strtime=hours+"-"+minutes;
strtime=strtime.substring(0,2)+strtime.substring(3,5);
var flag=false;
if(calender>strdate){
flag= true;
}else if(calender=strdate){
if(time>strtime){
flag=true;
}
}
return flag;
}
//下拉列表框赋值
function initSchedTime(){
var appSTimeObj=$("#appSTime");
var appETimeObj=$("#appETime");
for(var i=0;i<24;i++){
var hour=i;
if(i<10){
hour="0"+i;
}
var html1="<option value='"+hour+"00'>"+hour+":00</option>";
var html2="<option value='"+hour+"30'>"+hour+":30</option>";
appSTimeObj.append(html1);
appSTimeObj.append(html2);
appETimeObj.append(html1);
appETimeObj.append(html2);
}
}
</script>
</head>
<body>
<input type="hidden" value="${pageContext.request.contextPath} id="contextPath">
<center>
<form id="applyForm">
<table border="1" align="center" >
<tr colspan="2"><h2>请假申请表(Ajax提交)</h2></tr>
<tr>
<td>
请假类型:
</td>
<td>
<input type="radio" name="dutyBean.apptype" checked="checked" value="0" onclick="onchage(this.value)">请假
<input type="radio" name="dutyBean.apptype" value="1" onclick="onchage(this.value)" >出差
<input type="radio" name="dutyBean.apptype" value="2" onclick="onchage(this.value)"/>培训
</td>
</tr>
<tr >
<td>事由:</td>
<td>
<textarea rows="5" cols="40" id="appreSEOn" name="dutyBean.appresson"></textarea>
</td>
</tr>
<tr >
<td style="DISPLAY: none" id="p1">出差地点:</td>
<td style="DISPLAY: none" id="p2">培训地点:</td>
<td style="DISPLAY: none" id="p3">
<input type="text" id="appplace" name="dutyBean.appplace"/>
</td>
</tr>
<tr>
<td>
请选择开始日期:
</td>
<td>
<input type="text" id="startcalender" name="startcalender" onFocus="WdatePicker({isShowClear:false,readOnly:true})"/>
<select id="appSTime" name="dutyBean.starttime"></select>
</td>
</tr>
<tr>
<td>
请假结束日期:
</td>
<td>
<input type="text" id="endcalender" name="endcalender" onFocus="WdatePicker({isShowClear:false,readOnly:true})"/>
<select id="appETime" name="dutyBean.endtime"></select>
</td>
</tr>
<tr>
<td colspan="2" >
<!-- ajax提交button类型不能为submit,为submit的话ajax提交一次,又再次进行提交,有刷新效果,即没有达到ajax效果 -->
<!-- 验证表单需要使用return 方法名()来进行验证,未验证成功不能提交 -->
<input type="button" value="提交" onclick="return applySubmit()"/>
<input type="reset" value="取消"/>
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
dutyApply.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript" src="../js/jquery-1.4.2.js"></script>
<script>
var maxpagesize=1;//最大页数,初始定义为1
//alert("maxpagesize="+maxpagesize);
var contextPath=$("#contextPath").val();
$(function(){
init();
})
//初始化方法
function init(){
//alert("hello world!");
var url=contextPath+"/qwsq/queryDutyList.action";
var param="";
var tb=$("#dutyApply");
addDutyApplTableData(tb,url,param);
initSchedTime();
}
//初始化数据,表头固定加<thread>表头</thread>,<tbody>数据</tbody>
function addDutyApplTableData(tb,param){
//alert("分页参数2"+param);
var html="";
html+="<tbody>"
$.ajax({
url:url,//记住,data为传送的参数
dataType:"json",errorThrown){
//alert("========"+XMLHttpRequest.redayState+"|"+textStatus+"|"+errorThrown);
},
success:function(data){
//alert("currentPage=:"+data.currentPage)//进行分页封装后,弹出当前页
maxpagesize=data.totalPage;
//alert("最大页数:"+maxpagesize);
//alert(data.totalCount);//打印记录行数
if(data.totalCount==0){
html+="<tr><th colspan='12' align='left'>您好,没有符合条件的记录,请重置搜索条件</th></tr></tbody>";
tb.append(html);
//alert("您好,没有符合条件的记录,请重置搜索条件");
}
$.each(data.datas,function(i,du){
//alert(du.agreetime)
html+="<tr>";
html+="<th>"+du.id+"</th>";
html+="<th>"+du.startcalender+"</th>";
html+="<th>"+du.starttime+"</th>";
html+="<th>"+du.endcalender+"</th>";
html+="<th>"+du.endtime+"</th>";
if(du.apptype==0){
html+="<th>请假</th>";
}else if(du.apptype==1){
html+="<th>出差</th>";
}else if(du.apptype==2){
html+="<th>培训</th>";
}
html+="<th>"+du.apptime+"</th>";
if(du.isagree==0){
html+="<th>未批准</th>";
}else if(du.isagree==1){
html+="<th>已批准</th>";
}else if(du.isagree==2){
html+="<th>不批准</th>";
}
html+="<th>"+du.appresson+"</th>";
html+="<th>"+du.appplace+"</th>";
//如果isagree==1设置button为不可用
if(du.isagree==1){
html+="<th><input type='button' value='批准' disabled='disabled' onclick='agree("+du.id+")'/></th>";
}else{
html+="<th><input type='button' value='批准' onclick='agree("+du.id+")'/></th>";
}
html+="<th><input type='button' value='删除' onclick='del("+du.id+")'/></th>";
html+="</tr>";
});//.each循环结束
//分页
html+="<tr>";
html+="<th colspan='12'>当前页"+data.currentPage;
html+="  共有"+data.totalPage+"页 ";
//alert("共有多少页:"+data.totalPage);
html+="<a onclick='paging(1);' href='javascript:void(0);'>首页</a> ";
if(data.currentPage>1){
html+="<a onclick='paging("+(data.currentPage-1)+");' href='javascript:void(0);'>上一页</a> ";
}else{
html+="上一页 ";
}
if(data.currentPage<data.totalPage){
html+="<a onclick='paging("+(data.currentPage+1)+");' href='javascript:void(0);'>下一页</a> ";
}else{
html+="下一页 ";
}
if(data.currentPage<data.totalPage){
html+="<a onclick='paging("+(data.totalPage)+");' href='javascript:void(0);'>尾页</a> ";
}else{
html+="尾页 ";
}
html+="<input type='text' id='page' size='1'onkeypress='EnterPress(event)'/>"+"页 "+"<input type='button' value='跳转' onclick='goPage()'/>";
html+="</th>";
html+="</tr>";
html+="</tbody>";
tb.append(html);
}//success
})//ajax
};//函数
function EnterPress(e){ //传入 event
var e = e || window.event;
if(e.keyCode == 13){
//alert($("#page").val());
//alert("最大页数:"+$("#maxpagesize").val());
if(valPagesize($("#page").val())){
paging($("#page").val());
}
}
}
//跳转
function goPage(){
//页数合法进行分页
if(valPagesize($("#page").val())==true){
paging($("#page").val());
}
}
//判断是否合法页数
function valPagesize(size){
if(size>=1&&size<=maxpagesize){
return true;
}else if(size<1){
alert("页不能小于1");
$("#page").focus();
return false;
}else if(size>maxpagesize){
alert("输入的页数不能大于最大页数");
$("#page").focus();
return false;
}else{
alert("输入的页数不合法");
$("#page").focus();
return false;
}
}
//分页
function paging(param){
var param="pageInfo.currentPage="+param+"¤tPage="+param;
//alert("分页参数 :"+param)
var tb=$("#dutyApply");
tb.html("");//清空内容
addDutyApplyTableHead();//添加表头
var url=contextPath+"/qwsq/queryDutyList.action";
addDutyApplTableData(tb,param);
}
//删除
function del(id){
//alert(id);
var id=id;
var url=contextPath+"/qwsq/deleteData.action";
save(id,url);
}
//批准
function agree(id){
//alert(id);
var id=id;
var url=contextPath+"/qwsq/updateData.action";
save(id,url);
}
//修改,删除
function save(id,url){
if(confirm("确定要对记录进行修改吗?")){
//多个参数为:param="id="+id+"&id2="+id2+.....
var param="dutyBean.id="+id;
$.ajax({
url:url,
type:"post",
data:param,
error:function(XMLHttpRequest,errorThrown){
//alert("========"+XMLHttpRequest.redayState+"|"+textStatus+"|"+errorThrown);//弹出信息
},
success:function(data){
if(data==1){
alert("操作成功!");
}else{
alert("操作失败!");
}
//由于ajax是异步,要把显示的数据写在操作成功后里面,即success:function(data){执行的操作}
var tb=$("#dutyApply");
tb.html("");
addDutyApplyTableHead();//添加表头
var url=contextPath+"/qwsq/queryDutyList.action";
var param="";
addDutyApplTableData(tb,param);
}
})//ajax
}//confirm
}//函数
//生成表头
function addDutyApplyTableHead(){
var tb=$("#dutyApply");
//为了使表头固定,这是先加<thread></thread>
tb.append("<thread align='center'>")
.append("<tr>")
.append("<td>ID</td>")
.append("<td>开始日期</td>")
.append("<td>开始时间</td>")
.append("<td>结束日期</td>")
.append("<td>结束时间</td>")
.append("<td>请假类型</td>")
.append("<td>申请时间</td>")
.append("<td>是否批准</td>")
.append("<td>请假事由</td>")
.append("<td>地点</td>")
.append("<td>审核批准</td>")
.append("<td>管理</td>")
.append("</tr>")
.append("</thread>");
}
//搜索
function search(){
var tb=$("#dutyApply");
var param=$("#searchForm").serialize();//表单参数序列化
tb.html("");
addDutyApplyTableHead();
var url=contextPath+"/qwsq/queryDutyList.action";
var tb=$("#dutyApply");
//alert("============参数===========:"+param);
addDutyApplTableData(tb,param);
}
//下拉列表框赋值
function initSchedTime(){
var sTimeObj=$("#sTime");
var eTimeObj=$("#eTime");
var appSTimeObj=$("#appSTime");
var appETimeObj=$("#appETime");
for(var i=0;i<24;i++){
var hour=i;
if(i<10){
hour="0"+i;
}
var html1="<option value='"+hour+"00'>"+hour+":00</option>";
var html2="<option value='"+hour+"30'>"+hour+":30</option>";
sTimeObj.append(html1);
sTimeObj.append(html2);
eTimeObj.append(html1);
eTimeObj.append(html2);
appSTimeObj.append(html1);
appSTimeObj.append(html2);
appETimeObj.append(html1);
appETimeObj.append(html2);
}
}
</script>
</head>
<body>
<!-- 用来获取工程的根目录,需要用的名称都使用对象名.属性名,充分利用Struts2面向对象的功能 -->
<input type="hidden" value="${pageContext.request.contextPath} id="contextPath">
<center>
<h2>Ajax进行删除更新分页显示页面(JSP+Struts2+Poolman)</h2>
<form id="searchForm">
<table width="1024px" >
<tr>
<td>请假类型</td>
<td>
<select name="dutyBean.apptype" >
<option value="0">请假</option>
<option value="1">出差</option>
<option value="2">培训</option>
</select>
</td>
<td>审核批准</td>
<td>
<select name="dutyBean.isagree">
<option value="0">未批准</option>
<option value="1">已批准</option>
<option value="2">不批准</option>
</select>
</td>
<td align="center">
<input type="button" id="btnSeach" value="查询" onclick="search()"/>
<input type="reset" value="重置"/>
</td>
<td width="500px">
</td>
</tr>
</table>
</form>
<!-- 在这里可以定义table的样式 -->
<table id="dutyApply" border="1" align="center" width="1024px">
<tr>
<td>ID</td>
<td>开始日期</td>
<td>开始时间</td>
<td>结束日期</td>
<td>结束时间</td>
<td>请假类型</td>
<td>申请时间</td>
<td>是否批准</td>
<td>请假事由</td>
<td>地点</td>
<td>审核批准</td>
<td>管理</td>
</tr>
</table>
</center>
</body>
</html>
C:
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="qwsq" extends="default" namespace="/qwsq">
<action name="*"
class="com.chinacreator.qwgl.action.DutyApplyAction"
method="{1}">
</action>
</package>
</struts>
DutyApplyAction
public class DutyApplyAction extends PaginationAction{
private static final long serialVersionUID = 4712604081209033471L;
@SuppressWarnings("unused")
private static DutyApplyService dutyService=new DutyApplyService();
private DutyApplyBean dutyBean=new DutyApplyBean();
private PageInfo pageInfo=new PageInfo();
private String startcalender;
private String endcalender;
public PageInfo getPageInfo() {
return pageInfo;
}
public void setPageInfo(PageInfo pageInfo) {
this.pageInfo = pageInfo;
}
public DutyApplyBean getDutyBean() {
return dutyBean;
}
public void setDutyBean(DutyApplyBean dutyBean) {
this.dutyBean = dutyBean;
}
public String getStartcalender() {
return startcalender;
}
public void setStartcalender(String startcalender) {
this.startcalender = startcalender;
}
public String getEndcalender() {
return endcalender;
}
public void setEndcalender(String endcalender) {
this.endcalender = endcalender;
}
public void queryDutyList(){
pageInfo = this.getPageInfo();
try {
PageResultInfo<DutyApplyBean> resultList = dutyService.queryDutyApplyList(pageInfo,dutyBean);
this.responseWrite(resultList);//向页面输出对象
} catch (Exception e) {
e.printStackTrace();
}
}
public void deleteData(){
try{
dutyService.delDutyApply(dutyBean.getId());
returnValue("1");
}catch(Exception e){
returnValue("0");
e.printStackTrace();
}
}
public void updateData(){
try{
dutyBean.setIsagree(1);
dutyService.updateDutyApplyInfo(dutyBean);
returnValue("1");
}catch(Exception e){
returnValue("0");
e.printStackTrace();
}
}
public void addData(){
System.out.println("apptype:"+dutyBean.getApptype());
String scalender=dutyService.substr(startcalender);
String ecalender=dutyService.substr(endcalender);
if(dutyService.isDate(scalender,dutyBean.getStarttime())&&dutyService.isDate(ecalender,dutyBean.getEndtime())){
if(dutyService.isLegal(scalender,ecalender,dutyBean.getStarttime(),dutyBean.getEndtime())){
try{
dutyBean.setStartcalender(dutyService.strToNum(scalender));
dutyBean.setEndcalender(dutyService.strToNum(ecalender));
dutyService.addDutyApply(dutyBean);
}catch(Exception e){
returnValue("0");//失败为0 ajax返回值
e.printStackTrace();
}
}else{
returnValue("0");//失败为0 ajax返回值
System.out.println("请假开始日期大于或等于请假结束日期");
}
}else{
returnValue("0");//失败为0 ajax返回值
System.out.println("申请的日期小于或等于当前日期");
}
returnValue("1");//成功为1 ajax返回值
}
}
这个基类Action定义的方法:因为使用框架,有很东西,这里只显示关键性代码:
/**
* 输出文本
* @param object
* @return
*/
protected String responseWrite(Object object)
{
try {
String resStr = JSONUtil.serialize(object);
this.returnValue(resStr);
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void returnValue(String resStr){
try
{
Object obj = getSession().getServletContext().getAttribute("encoding");
String encoding = obj != null ? obj.toString() : "UTF-8";
response.setCharacterEncoding(encoding);
response.setContentType("text/plain;Charset=" + encoding);
response.setHeader("Cache-Control","no-cache");
LOG.info(resStr);
response.getWriter().write(resStr);
}
catch(Exception e)
{
e.printStackTrace();
}
}
用到分页的action
public class PaginationAction extends BaseAction {
/**
* serialVersionUID
*/
private static final long serialVersionUID = 543834409862081709L;
private PageInfo pageInfo;
// 当前页
private int currentPage = 1;
//每页显示多少记录
private int pageSize = 10;
public PageInfo getPageInfo() {
pageInfo = new PageInfo();
pageInfo.setCurrentPage(currentPage);
pageInfo.setPageSize(pageSize);
return pageInfo;
}
public void setPageInfo(PageInfo pageInfo) {
this.pageInfo = pageInfo;
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
}
M
业务层
DutyApplyService
package com.chinacreator.qwgl.service;
import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import javax.transaction.RollbackException;
import org.junit.Test;
import com.chinacreator.code.pages.PageInfo;
import com.chinacreator.code.pages.PageResultInfo;
import com.chinacreator.common.constant.CommonConstant;
import com.chinacreator.qwgl.bean.DutyApplyBean;
import com.chinacreator.qwgl.dao.DutyApplyDao;
import com.frameworkset.orm.transaction.TransactionManager;
public class DutyApplyService implements Serializable{
private static DutyApplyDao dutyDao=new DutyApplyDao();
public static PageResultInfo<DutyApplyBean> queryDutyApplyList(PageInfo pageInfo,DutyApplyBean dutyApplyBean) throws Exception{
return dutyDao.queryDutyApplyLis(pageInfo,dutyApplyBean);
}
public static DutyApplyBean queryDutyApply(DutyApplyBean dutyApplyBean)throws Exception{
return dutyDao.queryDutyApply(dutyApplyBean);
}
public static void delDutyApply(int id){
TransactionManager tm = new TransactionManager();
try{
tm.begin();
dutyDao.delDutyApply(id);
tm.commit();
}catch(Exception e){
try {
tm.rollback();
} catch (RollbackException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
tm.commit();
} catch (RollbackException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
e.printStackTrace();
}
}
public static void addDutyApply(DutyApplyBean dutyApplyBean){
TransactionManager tm = new TransactionManager();
try{
tm.begin();
dutyDao.addDutyApply(dutyApplyBean);
tm.commit();
}catch(Exception e){
try {
tm.rollback();
} catch (RollbackException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
tm.commit();
} catch (RollbackException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
e.printStackTrace();
}
}
public static void updateDutyApplyInfo(DutyApplyBean dutyApplyBean){
TransactionManager tm = new TransactionManager();
try{
tm.begin();
dutyDao.updateDutyApplyInfo(dutyApplyBean);
tm.commit();
}catch(Exception e){
try {
tm.rollback();
} catch (RollbackException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
tm.commit();
} catch (RollbackException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
e.printStackTrace();
}
}
//日期字符截断2011-11-12 20111112
public String substr(String str){
if(isNotNull(str)){
str=str.substring(0,4)+str.substring(5,7)+str.substring(8,10);
}
return str;
}
//判断请假开始日期不能大于等于请假结束日期
public boolean isLegal(String scalender,String ecalender,String stime,String etime){
boolean falg=false;
if(strToNum(scalender)<strToNum(ecalender)){
falg=true;
}else if(strToNum(scalender)==strToNum(ecalender)){
if(strToNum(stime)<strToNum(etime)){
falg=true;
}
}
return falg;
}
//判断用户选择的日期时间不能大于当前日期时间
public boolean isDate(String calender,String time){
String uDate=calender;
Calendar cal = Calendar.getInstance();//使用默认时区和语言环境获得一个日历。
java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyyMMddHHmm");
String strDate=format.format(Calendar.getInstance().getTime()).toString();
String sDate=strDate.substring(0,8);
String stime=strDate.substring(8,12);
System.out.println("sdate:"+sDate);
if(strToNum(uDate)>strToNum(sDate)){
return true;
}else if(strToNum(uDate)==strToNum(sDate)){
if(strToNum(time)>strToNum(stime)){
return true;
}
}
return false;
}
@Test
public void testDate(){
boolean falg=false;
falg=isDate("20131123","1410");
if(falg){
System.out.println("yes");
}else{
System.out.println("no");
}
}
@Test
public void testIsLegal(){
boolean falg=false;
falg=isLegal("20111111","20111112","2200","0000");
if(falg){
System.out.println("yes");
}else{
System.out.println("no");
}
}
//字符转数字
public int strToNum(String str){
int num=0;
System.out.println(str);
if(isNotNull(str)){
num=Integer.parseInt(str);
}
return num;
}
//判断非空
public boolean isNotNull(String str){
if(str!=null&&!str.equals("")){
return true;
}else{
return false;
}
}
}
Dao持久化层
DutyApplyDao
package com.chinacreator.qwgl.dao;
import java.io.Serializable;
import org.junit.Test;
import com.chinacreator.code.pages.PageInfo;
import com.chinacreator.code.pages.PageResultInfo;
import com.chinacreator.common.constant.CommonConstant;
import com.chinacreator.common.helper.PaginationHelper;
import com.chinacreator.qwgl.bean.DutyApplyBean;
import com.frameworkset.common.poolman.ConfigsqlExecutor;
import com.frameworkset.util.ListInfo;
public class DutyApplyDao implements Serializable{
private static ConfigsqlExecutor executor = new ConfigsqlExecutor("com/chinacreator/qwgl/dao/qwsq-sql.xml");
/**
* 分页查询
* @param pageInfo
* @param dutyApplyBean
* @return
* @throws Exception
*/
public static PageResultInfo<DutyApplyBean> queryDutyApplyLis(PageInfo pageInfo,DutyApplyBean dutyApplyBean) throws Exception{
ListInfo listInfo = executor.queryListInfoBeanWithDBName(
DutyApplyBean.class,CommonConstant.DBNAME_XTPT,"queryDutyApplyListInfo",
pageInfo.getOffset(),pageInfo.getPageSize(),dutyApplyBean);
return PaginationHelper.wrapPageResultInfo(pageInfo,listInfo
.getTotalSize(),listInfo.getDatas());
}
/**
* 根据条件查询一个Bean信息
* @param dutyApplyBean
* @return
* @throws Exception
*/
public static DutyApplyBean queryDutyApply(DutyApplyBean dutyApplyBean)throws Exception{
return executor.queryObjectBeanWithDBName(DutyApplyBean.class,"queryDutyApplyInfo",dutyApplyBean);
}
/**
* 增加信息
* @param dutyApplyBean
* @throws Exception
*/
public static void addDutyApply(DutyApplyBean dutyApplyBean)throws Exception{
executor.insertBean(CommonConstant.DBNAME_XTPT,"insertDutyApply",dutyApplyBean);
}
/**
* 删除信息
* @param id
* @throws Exception
*/
public static void delDutyApply(int id) throws Exception{
executor.deleteByKeysWithDBName(CommonConstant.DBNAME_XTPT,"deleteDutyApply",id);
}
/**
* 修改用户信息
* @param userBean
* @throws Exception
*/
public static void updateDutyApplyInfo(DutyApplyBean dutyApplyBean) throws Exception{
executor.updateBean(CommonConstant.DBNAME_XTPT,"updateDutyApply",dutyApplyBean);
}
}
qwsq-sql.xml
<?xml version="1.0" encoding="UTF-8"?>
<properties>
<property id="queryDutyApplyListInfo">
<![CDATA[
select id,
startcalender,
starttime,
endcalender,
endtime,
apptype,
appuserid,
appusername,
apptime,
isagree,
agreeuserid,
agreeusername,
agreetime,
APPRESSON,
appplace
from dutyapply
where 1=1
#if($isagree && $isagree!=0)
and isagree = #[isagree]
#end
#if($apptype && $apptype!=0)
and apptype = #[apptype]
#end
order by id desc
]]>
</property>
<property id="queryDutyApplyInfo">
<![CDATA[
select id,
appplace
from dutyapply
where 1=1
#if($id && $id!=0))
and id = #[id]
#end
#if($isagree && $isagree!=0))
and agree = #[agree]
#end
#if($apptype && $apptype!=0)
and casue = #[casue]
#end
]]>
</property>
<property id="insertDutyApply">
<![CDATA[
insert into
dutyapply(
id,
startcalender,
starttime,
endcalender,
endtime,
apptype,
apptime,
appuserid,
appusername,
isagree,
agreeuserid,
agreeusername,
agreetime,
appresson,
appplace
)
values(
td_sequence_dutyApply.nextval,
#[startcalender],
#[starttime],
#[endcalender],
#[endtime],
#[apptype],
to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),
#[appuserid],
#[appusername],
#[isagree],
#[agreeuserid],
#[agreeusername],
#[agreetime],
#[appresson],
#[appplace]
)
]]>
</property>
<property id="updateDutyApply">
<![CDATA[
update dutyapply
set agreetime=to_char(sysdate,
#if($isagree && $isagree!=0)
isagree = #[isagree]
#end
where id=#[id]
]]>
</property>
<property id="deleteDutyApply">
<![CDATA[
delete from dutyapply where id=?
]]>
</property>
</properties>
业务Bean
DutyApplyBean
package com.chinacreator.qwgl.bean; public class DutyApplyBean { private int id; private int startcalender; private String starttime; private int endcalender; private String endtime; private int apptype; private String apptime; private int appuserid; private String appusername; private int isagree; private int agreeuserid; private String agreeusername; private String agreetime; private String appresson; private String appplace; public int getId() { return id; } public void setId(int id) { this.id = id; } public int getStartcalender() { return startcalender; } public void setStartcalender(int startcalender) { this.startcalender = startcalender; } public String getStarttime() { return starttime; } public void setStarttime(String starttime) { this.starttime = starttime; } public int getEndcalender() { return endcalender; } public void setEndcalender(int endcalender) { this.endcalender = endcalender; } public String getEndtime() { return endtime; } public void setEndtime(String endtime) { this.endtime = endtime; } public int getApptype() { return apptype; } public void setApptype(int apptype) { this.apptype = apptype; } public int getAppuserid() { return appuserid; } public void setAppuserid(int appuserid) { this.appuserid = appuserid; } public String getAppusername() { return appusername; } public void setAppusername(String appusername) { this.appusername = appusername; } public int getIsagree() { return isagree; } public void setIsagree(int isagree) { this.isagree = isagree; } public int getAgreeuserid() { return agreeuserid; } public void setAgreeuserid(int agreeuserid) { this.agreeuserid = agreeuserid; } public String getAgreeusername() { return agreeusername; } public void setAgreeusername(String agreeusername) { this.agreeusername = agreeusername; } public String getAgreetime() { return agreetime; } public void setAgreetime(String agreetime) { this.agreetime = agreetime; } public String getAppresson() { return appresson; } public void setAppresson(String appresson) { this.appresson = appresson; } public String getAppplace() { return appplace; } public void setAppplace(String appplace) { this.appplace = appplace; } public String getApptime() { return apptime; } public void setApptime(String apptime) { this.apptime = apptime; } }