文章目录
- 实验室设备管理系统
- 一、项目演示
- 二、项目介绍
- 三、系统部分功能截图
- 四、部分代码展示
- 五、底部获取项目源码(9.9¥带走)
实验室设备管理系统
一、项目演示
实验室设备管理系统
二、项目介绍
基于ssh+jsp的实验室设备管理系统
系统角色:管理员、教师、学生
1、管理员:通知管理、用户列表、实验室管理、实验室预约、实验室预约记录、设备管理、运行数据管理、电子文档管理、设备维修管理、设备保修日志、设备借用管理、设备借用日志
2、教师:通知管理、用户管理、实验室预约、设备借用管理
3、教师:通知管理、用户管理、设备借用管理
三、系统部分功能截图
四、部分代码展示
package com.xznu.edu.leave.utils;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
/**
* 日期格式化类
*/
public class DateUtils extends java.util.Date {
private static final long serialVersionUID = 1L;
private static final DateFormat datetimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
private static final String strFormat1 = "yyyy-MM-dd HH:mm";
/**
M 年中的月份 Month July; Jul; 07
w 年中的周数 Number 27
W 月份中的周数 Number 2
D 年中的天数 Number 189
d 月份中的天数 Number 10
F 月份中的星期 Number 2
E 星期中的天数 Text Tuesday; Tue
a Am/pm 标记 Text PM
H 一天中的小时数(0-23) Number 0
k 一天中的小时数(1-24) Number 24
K am/pm 中的小时数(0-11) Number 0
h am/pm 中的小时数(1-12) Number 12
m 小时中的分钟数 Number 30
s 分钟中的秒数 Number 55
S 毫秒数 Number 978
z 时区 General time zone Pacific Standard Time; PST; GMT-08:00
Z 时区 RFC 822 time zone -0800
*/
/**
* 构造函数
*/
public DateUtils() {
super(getSystemDate().getTime().getTime());
}
/**
* 当前时间
*
* @return 时间Timestamp
*/
public java.sql.Timestamp parseTime() {
return new java.sql.Timestamp(this.getTime());
}
/**
* 将Date类型转换为字符串 yyyy-MM-dd HH:mm:ss
*
* @param Date
* @return String
*/
public static String format(Date date) {
return format(date, null);
}
/**
* 将Date类型转换为字符串
*
* @param Date
* @param pattern 字符串格式
* @return String
*/
public static String format(Date date, String pattern) {
if (date == null) {
return "";
} else if (pattern == null || pattern.equals("") || pattern.equals("null")) {
return datetimeFormat.format(date);
} else {
return new SimpleDateFormat(pattern).format(date);
}
}
/**
* 将Date类型转换为字符串 yyyy-MM-dd
*
* @param Date
* @return String
*/
public static String formatDate(Date date) {
if (date == null) {
return "";
}
return dateFormat.format(date);
}
/**
* 将字符串转换为Date类型
*
* @param sDate yyyy-MM-dd HH:mm:ss
* @return
*/
public static Date convert(String sDate) {
try {
if (sDate != null) {
if (sDate.length() == 10) {
return dateFormat.parse(sDate);
} else if (sDate.length() == 19) {
return datetimeFormat.parse(sDate);
}
}
} catch (ParseException pe) {
}
return convert(sDate, null);
}
/**
* 将字符串转换为Date类型
*
* @param sDate
* @param pattern 格式
* @return
*/
public static Date convert(String sDate, String pattern) {
Date date = null;
try {
if (sDate == null || sDate.equals("") || sDate.equals("null")) {
return null;
} else if (pattern == null || pattern.equals("") || pattern.equals("null")) {
return datetimeFormat.parse(sDate);
} else {
return new SimpleDateFormat(pattern).parse(sDate);
}
} catch (ParseException pe) {
}
return date;
}
/**
* String转换为Date
*
* @param sDate 日期"yyyy-MM-dd"
* @return 日期Date
*/
public static Date convertDate(String dateStr) {
return convert(dateStr, "yyyy-MM-dd");
}
/**
* String转换为Timestamp
*
* @param sDate 日期 "yyyy-MM-dd" / "yyyy-MM-dd HH:mm:ss"
* @return 日期Timestamp
*/
public static Timestamp convertTimestamp(String sDate) {
if (sDate.length() == 10) {
sDate = sDate + " 00:00:00";
}
if (sDate.length() == 16) {
sDate = sDate + ":00";
}
return Timestamp.valueOf(sDate);
}
/**
* Date转换为Timestamp
*/
public static Timestamp convert(Date date) {
return new Timestamp(date.getTime());
}
/**
* 取当前日期(yyyy-mm-dd)
*
* @return 时间Timestamp
*/
public static String getTodayDate() {
return formatDate(new Date());
}
/**
* 取当前日期(yyyy-mm-dd hh:mm:ss)
*
* @return 时间Timestamp
*/
public static String getTodayDateTime() {
return format(new Date());
}
/**
* 取得n分钟后的时间
*
* @param date 日期
* @param afterMins
* @return 时间Timestamp
*/
public static Date getAfterMinute(Date date, long afterMins) {
if (date == null)
date = new Date();
long longTime = date.getTime() + afterMins * 60 * 1000;
return new Date(longTime);
}
// public static void main(String[] arg) {
// System.err.println(format((new Date())));
// System.err.println(format(getAfterMinute(new Date(), 3)));
// }
/**
* 取得指定日期几天后的日期
*
* @param date 日期
* @param afterDays 天数
* @return 日期
*/
public static Date getAfterDay(Date date, int afterDays) {
if (date == null)
date = new Date();
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
cal.add(java.util.Calendar.DATE, afterDays);
return cal.getTime();
}
/**
* 取得指定日期几天后的日期
*
* @param sDate 日期 yyyy-MM-dd
* @param afterDays 天数
* @return 日期
*/
public static String getAfterDay(String sDate, int afterDays) {
Date date = convertDate(sDate);
date = getAfterDay(date, afterDays);
return formatDate(date);
}
/**
* 取得指定日期几天前的日期
*
* @param date 日期
* @param beforeDays 天数(大于0)
* @return 日期
*/
public static Date getBeforeDay(Date date, int beforeDays) {
if (date == null)
date = new Date();
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
cal.add(java.util.Calendar.DATE, 0 - Math.abs(beforeDays));
return cal.getTime();
}
/**
* 取得指定日期几天前的日期
*
* @param sDate 日期 yyyy-MM-dd
* @param beforeDays 天数(大于0)
* @return 日期
*/
public static String getBeforeDay(String sDate, int beforeDays) {
Date date = convertDate(sDate);
date = getBeforeDay(date, beforeDays);
return formatDate(date);
}
/**
* 获得几个月后的日期
*
* @param date 日期
* @param afterMonth 月数
* @return 日期Date
*/
public static Date getAfterMonth(Date date, int afterMonth) {
if (date == null)
date = new Date();
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
cal.add(java.util.Calendar.MONTH, afterMonth);
return cal.getTime();
}
/**
* 获得几个月后的日期
*
* @param sDate 日期
* @param afterMonth 月数
* @return 日期"yyyy-MM-dd"
*/
public static String getAfterMonth(String sDate, int afterMonth) {
Date date = convertDate(sDate);
date = getAfterMonth(date, afterMonth);
return formatDate(date);
}
/**
* 获得几年后的日期
*
* @param date 日期
* @param afterYear 年数
* @return 日期Date
*/
public static Date getAfterYear(Date date, int afterYear) {
if (date == null)
date = new Date();
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
cal.add(java.util.Calendar.YEAR, afterYear);
return cal.getTime();
}
/**
* 获得几年后的日期
*
* @param date 日期
* @param afterYear 年数
* @return 日期Date
*/
public static String getAfterYear(String sDate, int afterYear) {
Date date = convertDate(sDate);
date = getAfterYear(date, afterYear);
return formatDate(date);
}
/**
* 取得月份第一天日期
*
* @param sDate(yyyy-mm-dd) : 如为Null,默认取当前系统时间
* @return yyyy-mm-dd
*/
public static String getMonthFirstDay(String sDate) {
Date date = null;
if (sDate != null && sDate.length() > 0) {
date = convertDate(sDate);
}
Calendar gc = Calendar.getInstance();
if (date != null) {
gc.setTime(date);
}
gc.set(Calendar.DATE, 1);
return formatDate(gc.getTime());
}
/**
* 取得月份最后一天日期
*
* @param sDate(yyyy-mm-dd) : 如为Null,默认取当前系统时间
* @return yyyy-mm-dd
*/
public static String getMonthLastDay(String sDate) {
Date date = null;
if (sDate != null && sDate.length() > 0) {
date = convertDate(sDate);
}
Calendar gc = Calendar.getInstance();
if (date != null) {
gc.setTime(date);
}
gc.add(Calendar.MONTH, 1);
gc.add(Calendar.DATE, -gc.get(Calendar.DAY_OF_MONTH));
return formatDate(gc.getTime());
}
/**
* 取得日期,星期几
*
* @param dateTime : dateTime
* @return "星期日","星期一","星期二","星期三","星期四","星期五","星期六"
*/
public static String getWeekDayName(String dateTime) throws ParseException {
String dayNames[] = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
Date d = convertDate(dateTime);
Calendar cal = Calendar.getInstance();
cal.setTime(d);
int day = cal.get(Calendar.DAY_OF_WEEK);
String week_day_name = dayNames[day - 1];
return week_day_name;
}
/**
* 传入的日期格式是否是yyyy-MM-dd
*
* @param in 被检查的日期
* @return 是指定的日期格式:true,否则:false
*/
public static boolean isFormatDate(String in) {
return isFormatDate(in, "yyyy-MM-dd");
}
/**
* 传入的日期格式是否是指定的日期格式
*
* @param in 被检查的日期
* @param format 指定的日期格式
* @return 是指定的日期格式:true,否则:false
*/
private static boolean isFormatDate(String in, String format) {
if (format != null & format.length() > 0) {
return false;
}
final SimpleDateFormat sdFormat = new SimpleDateFormat(format);
Date dateCompare = null;
String sDate = "";
try {
dateCompare = sdFormat.parse(in, new ParsePosition(0));
sDate = sdFormat.format(dateCompare);
} catch (final Exception e) {
return false;
}
if (dateCompare == null) {
return false;
} else {
return sDate.equals(in);
}
}
/**
* 比较两个日期先后
*
* @param date1 : yyyy-MM-dd
* @param date1 : yyyy-MM-dd
* @return date1 > date2 : true, else : false
*/
public static boolean compareDate(String date1, String date2) {
if (isFormatDate(date1, "yyyy-MM-dd") && isFormatDate(date2, "yyyy-MM-dd")) {
if (date1.compareTo(date2) > 0) {
return false;
} else {
return true;
}
} else {
return false;
}
}
/**
* 取当前系统时间
*
* @return 时间Calendar
*/
public static Calendar getSystemDate() {
return Calendar.getInstance();
}
/**
* 转换类型
*
* @param sDate 日期"yyyy-MM-dd HH:mm"
* @return 日期Date
* @throws Exception
*/
public static java.util.Date convertDate1(String sDate) throws Exception {
SimpleDateFormat sFormat1 = new SimpleDateFormat(strFormat1);
return sFormat1.parse(sDate);
}
/**
* 取得输入时间n分钟前的时间
*
* @param date 日期
* @param lminute
* @return 时间Timestamp
*/
public static Timestamp gettimebefore(java.util.Date date, long lminute) {
long lngTime = date.getTime() - lminute * 60 * 1000;
return new Timestamp(lngTime);
}
/**
* 取得日期,星期几
*
* @param dateTime
* : dateTime
* @return "周日","周一","周二","周三","周四","周五","周六"
*/
public static String getWeekDays(Date dateTime){
String dayNames[] = { "周日", "周一", "周二", "周三", "周四", "周五", "周六" };
int day = getWeekDay(dateTime);
String week_day_name = dayNames[day - 1];
return week_day_name;
}
/**
* 取得日期,星期几
*
* @param dateTime
* : dateTime
* @return "周日","周一","周二","周三","周四","周五","周六"
*/
public static String getWeekOfDate(Date dateTime){
String dayNames[] = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
int day = getWeekDay(dateTime);
String week_day_name = dayNames[day - 1];
return week_day_name;
}
/**
* 取得日期是星期的第几天
*
* @param dateTime
* : dateTime
* @return :1: "星期日",2:"星期一", 3:"星期二",,4:"星期三", 5:"星期四", 6:"星期五", 7:"星期六"
*/
public static int getWeekDay(Date dateTime) {
Calendar cal = Calendar.getInstance();
cal.setTime(dateTime);
return cal.get(Calendar.DAY_OF_WEEK);
}
/**
* 求2个日期之间的天数
*
* @param StartDay 开始日期
* @param endDay 结束日期
* @param IncludeEndFlag 是否把结束当天算在内,Y:是,N:否
* @return
* @throws Exception
*/
public static long DayCountBetweenDays(String StartDay, String endDay,
String IncludeEndFlag) throws Exception {
long DAY = 24L * 60L * 60L * 1000L;
long countBetweenDay = 0;
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date d1 = df.parse(StartDay);
Date d2 = df.parse(endDay);
countBetweenDay = (d2.getTime() - d1.getTime()) / DAY;
if (IncludeEndFlag == "Y") {
countBetweenDay++;
}
return countBetweenDay;
}
}
package com.xznu.edu.leave.dao.impl;
import com.xznu.edu.leave.base.dao.impl.BaseDaoImpl;
import com.xznu.edu.leave.dao.UserDao;
import com.xznu.edu.leave.model.User;
import com.xznu.edu.leave.utils.Pager;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Repository
public class UserDaoImpl extends BaseDaoImpl<User> implements UserDao {
@Override
public Pager<User> getList(User bean) {
Map<String, Object> alias = new HashMap<String, Object>();
StringBuffer sb = new StringBuffer();
sb.append("from User where isDelete = 0");
if (bean != null) {
if (bean.getRealName() != null && !"".equals(bean.getRealName())) {
sb.append(" and realName like :realName");
alias.put("realName", "%" + bean.getRealName().trim() + "%");
}
if (bean.getName() != null && !"".equals(bean.getName())) {
sb.append(" and name like :name");
alias.put("name", "%" + bean.getName().trim() + "%");
}
if (bean.getNumber() != null && !"".equals(bean.getNumber())) {
sb.append(" and number like :number");
alias.put("number", "%" + bean.getNumber().trim() + "%");
}
if (bean.getPhone() != null && !"".equals(bean.getPhone())) {
sb.append(" and phone like :phone");
alias.put("phone", "%" + bean.getPhone().trim() + "%");
}
if (bean.getXy() != null && !"".equals(bean.getXy())) {
sb.append(" and xy like :xy");
alias.put("xy", "%" + bean.getXy().trim() + "%");
}
if (bean.getBj() != null && !"".equals(bean.getBj())) {
sb.append(" and bj like :bj");
alias.put("bj", "%" + bean.getBj().trim() + "%");
}
}
return findByAlias(sb.toString(), alias);
}
@Override
public List<User> getListAdmin() {
StringBuilder sb = new StringBuilder();
sb.append("from User where isDelete = 0 and role.enName = :admin");
Query query = getSession().createQuery(sb.toString());
query.setParameter("admin", "admin");
return query.list();
}
@Override
public User getUser(User user) {
StringBuilder sb = new StringBuilder();
sb.append("from User where isDelete = 0");
if (user.getName() != null && !user.getName().equals("")) {
sb.append(" and name = :name");
}
if (user.getPass() != null && !user.getPass().equals("")) {
sb.append(" and pass = :pass");
}
Query query = getSession().createQuery(sb.toString());
if (user.getName() != null && !user.getName().equals("")) {
query.setParameter("name", user.getName().trim());
}
if (user.getPass() != null && !user.getPass().equals("")) {
query.setParameter("pass", user.getPass().trim());
}
List<User> list = query.list();
if (list.size() > 0) {
return (User) query.list().get(0);
}
return null;
}
@Override
public User findById(Integer id) {
StringBuilder sb = new StringBuilder();
sb.append("from User where isDelete = 0 and id = :id");
Query query = getSession().createQuery(sb.toString());
query.setParameter("id", id);
return (User) query.uniqueResult();
}
}
package com.xznu.edu.leave.base.dao.impl;
import java.lang.reflect.ParameterizedType;
import java.math.BigInteger;
import java.util.*;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.metadata.ClassMetadata;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.transform.Transformers;
import org.springframework.beans.factory.annotation.Autowired;
import com.xznu.edu.leave.base.dao.BaseDao;
import com.xznu.edu.leave.utils.Pager;
import com.xznu.edu.leave.utils.SystemContext;
public class BaseDaoImpl<T> implements BaseDao<T> {
@Autowired
private SessionFactory sessionFactory;
/**
* 创建一个Class的对象来获取泛型的class
*/
private Class<?> clz;
public Class<?> getClz() {
if(clz==null) {
//获取泛型的Class对象
clz = ((Class<?>)
(((ParameterizedType)(this.getClass().getGenericSuperclass())).getActualTypeArguments()[0]));
}
return clz;
}
public SessionFactory getSessionFactory() {
return sessionFactory;
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
protected Session getSession() {
return sessionFactory.getCurrentSession();
}
public T add(T t) {
getSession().save(t);
return t;
}
public void update(T t) {
getSession().update(t);
}
public void delete(int id) {
getSession().delete(this.load(id));
}
public T load(int id) {
return (T)getSession().load(getClz(), id);
}
@Override
public T findById(Integer id) {
return (T)getSession().load(getClz(), id);
}
public T updates(T bean) {
// 取得元数据
ClassMetadata cm = sessionFactory.getClassMetadata(getClz());
// 取得主键名称
String identifierName = cm.getIdentifierPropertyName();
// 反射取得主键值
Integer id = (Integer) getSimpleProperty(bean, identifierName);
// 取得数据库中的对象
T po = findById(id);
// 取得所有属性
String[] propNames = cm.getPropertyNames();
// 定义存储新值
Object newValue;
for (String propName : propNames) {
// 如果是主键就跳过
if (propName.equals(identifierName)) {
continue;
}
// 反射取得新值
newValue = getSimpleProperty(bean, propName);
if (newValue != null) {
// 设置新值
cm.setPropertyValue(po, propName, newValue);
}
}
return po;
}
public static Object getSimpleProperty(Object bean, String propName) {
try {
return bean.getClass().getMethod(getReadMethod(propName)).invoke(bean);
} catch (Exception e) {
throw new RuntimeException("get object property failed: '" + propName + "'", e);
}
}
private static String getReadMethod(String name) {
return "get" + name.substring(0, 1).toUpperCase(Locale.ENGLISH)
+ name.substring(1);
}
private static String setReadMethod(String name) {
return "set" + name.substring(0, 1).toUpperCase(Locale.ENGLISH)
+ name.substring(1);
}
/**
* 通过参数查询一个
* @param hql
* @param alias
* @return
*/
public T getByParams(String hql, Map<String, Object> alias){
List<T> t = this.list(hql, null, alias);
if(t !=null){
return t.get(0);
}else{
return null;
}
}
public List<T> list(String hql, Object[] args) {
return this.list(hql, args, null);
}
public List<T> list(String hql, Object arg) {
return this.list(hql, new Object[]{arg});
}
public List<T> list(String hql) {
return this.list(hql,null);
}
private String initSort(String hql) {
String order = SystemContext.getOrder();
String sort = SystemContext.getSort();
if(sort!=null&&!"".equals(sort.trim())) {
hql+=" order by "+sort;
if(!"desc".equals(order)) hql+=" asc";
else hql+=" desc";
}
return hql;
}
@SuppressWarnings("rawtypes")
private void setAliasParameter(Query query,Map<String,Object> alias) {
if(alias!=null) {
Set<String> keys = alias.keySet();
for(String key:keys) {
Object val = alias.get(key);
if(val instanceof Collection) {
//查询条件是列表
query.setParameterList(key, (Collection)val);
} else {
query.setParameter(key, val);
}
}
}
}
private void setParameter(Query query,Object[] args) {
if(args!=null&&args.length>0) {
int index = 0;
for(Object arg:args) {
query.setParameter(index++, arg);
}
}
}
public List<T> list(String hql, Object[] args, Map<String, Object> alias) {
hql = initSort(hql);
Query query = getSession().createQuery(hql);
setAliasParameter(query, alias);
setParameter(query, args);
return query.list();
}
public List<T> listByAlias(String hql, Map<String, Object> alias) {
return this.list(hql, null, alias);
}
public Pager<T> find(String hql, Object[] args) {
return this.find(hql, args, null);
}
public Pager<T> find(String hql, Object arg) {
return this.find(hql, new Object[]{arg});
}
public Pager<T> find(String hql) {
return this.find(hql,null);
}
@SuppressWarnings("rawtypes")
private void setPagers(Query query,Pager pages) {
Integer pageSize = SystemContext.getPageSize();
Integer pageOffset = SystemContext.getPageOffset();
if(pageOffset==null||pageOffset<0) pageOffset = 0;
if(pageSize==null||pageSize<0) pageSize = 15;
pages.setOffset(pageOffset);
pages.setSize(pageSize);
query.setFirstResult(pageOffset).setMaxResults(pageSize);
}
private String getCountHql(String hql,boolean isHql) {
String e = hql.substring(hql.indexOf("from"));
String c = "select count(*) "+e;
if(isHql)
c.replaceAll("fetch", "");
return c;
}
public Pager<T> find(String hql, Object[] args, Map<String, Object> alias) {
hql = initSort(hql);
String cq = getCountHql(hql,true);
Query cquery = getSession().createQuery(cq);
Query query = getSession().createQuery(hql);
//设置别名参数
setAliasParameter(query, alias);
setAliasParameter(cquery, alias);
//设置参数
setParameter(query, args);
setParameter(cquery, args);
Pager<T> pages = new Pager<T>();
setPagers(query,pages);
List<T> datas = query.list();
pages.setDatas(datas);
long total = (Long)cquery.uniqueResult();
pages.setTotal(total);
return pages;
}
public Pager<T> findByAlias(String hql, Map<String, Object> alias) {
return this.find(hql,null, alias);
}
public Object queryObject(String hql, Object[] args) {
return this.queryObject(hql, args,null);
}
public Object queryObject(String hql, Object arg) {
return this.queryObject(hql, new Object[]{arg});
}
public Object queryObject(String hql) {
return this.queryObject(hql,null);
}
public void updateByHql(String hql, Object[] args) {
Query query = getSession().createQuery(hql);
setParameter(query, args);
query.executeUpdate();
}
public void updateByHql(String hql, Object arg) {
this.updateByHql(hql,new Object[]{arg});
}
public void updateByHql(String hql) {
this.updateByHql(hql,null);
}
public <N extends Object>List<N> listBySql(String sql, Object[] args, Class<?> clz,
boolean hasEntity) {
return this.listBySql(sql, args, null, clz, hasEntity);
}
public <N extends Object>List<N> listBySql(String sql, Object arg, Class<?> clz,
boolean hasEntity) {
return this.listBySql(sql, new Object[]{arg}, clz, hasEntity);
}
public <N extends Object>List<N> listBySql(String sql, Class<?> clz, boolean hasEntity) {
return this.listBySql(sql, null, clz, hasEntity);
}
public <N extends Object>List<N> listBySql(String sql, Object[] args,
Map<String, Object> alias, Class<?> clz, boolean hasEntity) {
sql = initSort(sql);
SQLQuery sq = getSession().createSQLQuery(sql);
setAliasParameter(sq, alias);
setParameter(sq, args);
if(hasEntity) {
sq.addEntity(clz);
} else
sq.setResultTransformer(Transformers.aliasToBean(clz));
return sq.list();
}
public <N extends Object>List<N> listByAliasSql(String sql, Map<String, Object> alias,
Class<?> clz, boolean hasEntity) {
return this.listBySql(sql, null, alias, clz, hasEntity);
}
public <N extends Object>Pager<N> findBySql(String sql, Object[] args, Class<?> clz,
boolean hasEntity) {
return this.findBySql(sql, args, null, clz, hasEntity);
}
public <N extends Object>Pager<N> findBySql(String sql, Object arg, Class<?> clz,
boolean hasEntity) {
return this.findBySql(sql, new Object[]{arg}, clz, hasEntity);
}
public <N extends Object>Pager<N> findBySql(String sql, Class<?> clz, boolean hasEntity) {
return this.findBySql(sql, null, clz, hasEntity);
}
public <N extends Object>Pager<N> findBySql(String sql, Object[] args,
Map<String, Object> alias, Class<?> clz, boolean hasEntity) {
sql = initSort(sql);
String cq = getCountHql(sql,false);
SQLQuery sq = getSession().createSQLQuery(sql);
SQLQuery cquery = getSession().createSQLQuery(cq);
setAliasParameter(sq, alias);
setAliasParameter(cquery, alias);
setParameter(sq, args);
setParameter(cquery, args);
Pager<N> pages = new Pager<N>();
setPagers(sq, pages);
if(hasEntity) {
sq.addEntity(clz);
} else {
sq.setResultTransformer(Transformers.aliasToBean(clz));
}
List<N> datas = sq.list();
pages.setDatas(datas);
long total = ((BigInteger)cquery.uniqueResult()).longValue();
pages.setTotal(total);
return pages;
}
public <N extends Object>Pager<N> findByAliasSql(String sql, Map<String, Object> alias,
Class<?> clz, boolean hasEntity) {
return this.findBySql(sql, null, alias, clz, hasEntity);
}
public Object queryObject(String hql, Object[] args,
Map<String, Object> alias) {
Query query = getSession().createQuery(hql);
setAliasParameter(query, alias);
setParameter(query, args);
return query.uniqueResult();
}
public Object queryObjectByAlias(String hql, Map<String, Object> alias) {
return this.queryObject(hql,null,alias);
}
}
五、底部获取项目源码(9.9¥带走)
有问题,或者需要协助调试运行项目的也可以