📄 querycar2.java
字号:
package com.t60.oa.service.car;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import com.t60.oa.po.Apply;
import com.t60.oa.po.Employee;
import com.t60.oa.web.car.Querycar2ActionForm;
import hong.javanet.dao.HibernateUtil;
import org.hibernate.Session;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
public class Querycar2
{
private String message;
private List result;
private Employee em;
private Querycar2ActionForm form;
private static SimpleDateFormat sdf =
new SimpleDateFormat("yyyy-MM-dd");
private int pageIndex;
private int pageSize=4;
private boolean needCount;
private int pageCount;
private int rowCount;
public void querycar2() throws ParseException {
Session session=HibernateUtil.currentSession();
org.hibernate.Criteria crem=session.createCriteria(Apply.class);
//// org.hibernate.Criteria cremEmpb=crem.createCriteria("buser");
//// org.hibernate.Criteria cremEmpl=crem.createCriteria("luse");
//// org.hibernate.Criteria cremEmpa=crem.createCriteria("ause");
//// org.hibernate.Criteria cremEmpo=crem.createCriteria("ouser");
// //querycar2ActionForm form=new querycar2ActionForm();
//Apply apply=new Apply();
//org.hibernate.Criteria cram=crem.createCriteria("empId");
if(form.getCarnum()!=null&&form.getCarnum().trim().length()>0)
{
String carnum =form.getCarnum();
crem.add(Restrictions.like("carnum.num", "%" + carnum + "%"));
//Hibernate.initialize(apply.getCarnum());
System.out.println(form.getCarnum());
}
if(form.getCartype()!=null&&form.getCartype().trim().length()>0)
{
String cartype=form.getCartype().trim();
crem.add(Restrictions.like("cartype","%"+cartype+"%"));
System.out.println(cartype);
//Hibernate.initialize(apply.getCartype());
}
if(form.getState()!=null&&form.getState().trim().length()>0)
{
String state=form.getState().trim();
crem.add(Restrictions.like("state","%"+state+"%"));
System.out.println(form.getState());
//Hibernate.initialize(apply.getState());
}
if(form.getAuse()!=null&&form.getAuse().trim().length()>0)
{
String ause=form.getAuse().trim().toString();
crem.add(Restrictions.eq("ause.id",new Integer(ause)));
//Hibernate.initialize(apply.getAuse());
}
if(form.getOuser()!=null&&form.getOuser().trim().length()>0)
{
String ouser=form.getOuser().trim().toString();
crem.add(Restrictions.eq("ouser.id",new Integer(ouser)));
//Hibernate.initialize(apply.getOuser());
}
if(form.getBuser()!=null&&form.getBuser().trim().length()>0)
{
String buser=form.getBuser().trim().toString();
crem.add(Restrictions.eq("buser.id",new Integer(buser)));
//Hibernate.initialize(apply.getBuser());
}
if(form.getLuse()!=null&&form.getLuse().trim().length()>0)
{
String luse=form.getLuse().trim().toString();
crem.add(Restrictions.eq("luse.id",new Integer(luse)));
//Hibernate.initialize(apply.getLuse());
}
if(form.getDateTime1()!=null&&form.getDateTime1().trim().length()>0&&form.getDateTime2()!=null&&form.getDateTime2().trim().length()>0)
{
String strDate1 = form.getDateTime1();
String strDate2 = form.getDateTime2();
// Date date1= to_date(strDate1,"YYYY-MM-DD");
Date date1 = (Date) sdf.parse(strDate1);
Date date2 = (Date) sdf.parse(strDate2);
int i = date1.compareTo(date2);
if (i < 0)
{
crem.add(Restrictions.between("gagebreakout", date1, date2));
}
}
// System.out.print(strDate1);
// System.out.print(strDate2);
// if (form.getDateTime1() != null && form.getDateTime1().trim().length()>0)
// {
// crem.add(Restrictions.sqlRestriction(" DATEDIFF(d,factgiveback ,'" + form.getDateTime1() + "')<=0"));
// }
// if(form.getDateTime2()!=null && form.getDateTime2().trim().length()>0)
// {
// crem.add(Restrictions.sqlRestriction(" DATEDIFF(d,factbreakout ,'"+form.getDateTime2()+"')>=0"));
// }
// System.out.print(form.getDateTime1());
// System.out.print(form.getDateTime2());
// Query query = session.createQuery(
// "select * from Apply inner join Employee where carnum like carnum and cartype like cartype and state like state")
// .setString("carnum","%carnum%")
// .setString("cartype","%cartype%")
// .setString("state","%state%")
// .setFirstResult(0)
// .setMaxResults(3)
// ;
// java.util.List result = query.list();
// if(form.getShenqingren()!=null&&form.getShenqingren().trim().length()>0)
// {
// String shenqingren=form.getShenqingren();
// cremEmpa.add(Restrictions.like("xm","%"+shenqingren+"%"));
// Hibernate.initialize(apply.getAuse().getEmpName());
// }
// if (form.getOuser() != null &&
// form.getOuser().trim().length() > 0) {
// String ouser = form.getOuser();
// cremEmpo.add(Restrictions.like("xm", "%" + ouser + "%"));
// Hibernate.initialize(apply.getOuser().getEmpName());
// }
// if (form.getBuser() != null &&
// form.getBuser().trim().length() > 0) {
// String buser = form.getBuser();
// cremEmpb.add(Restrictions.like("xm", "%" + buser + "%"));
// Hibernate.initialize(apply.getBuser().getEmpName());
// }
//Hibernate.initialize(apply);
crem.setMaxResults(this.pageSize);
crem.setFirstResult((this.pageIndex - 1) * this.pageSize);
this.result=crem.list();
if (this.needCount)
{
crem.setProjection(Projections.rowCount());
this.rowCount = ((Integer) crem.uniqueResult()).intValue();
this.pageCount = (this.rowCount - 1) / this.pageSize + 1;
}
Iterator iter = this.result.iterator();
while (iter.hasNext()) {
Apply item = (Apply) iter.next();
// item.getJob().getJob_desc();
org.hibernate.Hibernate.initialize(item.getAuse());
org.hibernate.Hibernate.initialize(item.getBuser());
org.hibernate.Hibernate.initialize(item.getOuser());
org.hibernate.Hibernate.initialize(item.getLuse());
org.hibernate.Hibernate.initialize(item.getCarnum());
org.hibernate.Hibernate.initialize(item.getCartype());
}
}
public Employee getEm() {
return em;
}
public Querycar2ActionForm getForm() {
return form;
}
public String getMessage() {
return message;
}
public List getResult() {
return result;
}
public boolean isNeedCount() {
return needCount;
}
public int getPageCount() {
return pageCount;
}
public int getPageIndex() {
return pageIndex;
}
public int getPageSize() {
return pageSize;
}
public int getRowCount() {
return rowCount;
}
public SimpleDateFormat getSdf() {
return sdf;
}
public void setEm(Employee em) {
this.em = em;
}
public void setForm(Querycar2ActionForm form) {
this.form = form;
}
public void setMessage(String message) {
this.message = message;
}
public void setResult(List result) {
this.result = result;
}
public void setNeedCount(boolean needCount) {
this.needCount = needCount;
}
public void setPageCount(int pageCount) {
this.pageCount = pageCount;
}
public void setPageIndex(int pageIndex) {
this.pageIndex = pageIndex;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public void setRowCount(int rowCount) {
this.rowCount = rowCount;
}
public void setSdf(SimpleDateFormat sdf) {
this.sdf = sdf;
}
public static void main(String[] args) throws ParseException {
Date date1 = sdf.parse("2004-04-12");
System.out.println(date1);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -