package core.dao;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.Resource;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.log4j.Logger;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.hibernate.transform.Transformers;
import core.extjs.ExtJSBaseParameter;
import core.support.BaseParameter;
import core.support.QueryResult;
import ypc.zwz.model.SysUser;
/**
* @author Yang Tian
* @email 1298588579@qq.com
*/
public class BaseDao<E> implements Dao<E> {
protected final Logger log = Logger.getLogger(BaseDao.class);
private static Map<String, Method> MAP_METHOD = new HashMap<String, Method>();
private SessionFactory sessionFactory;
public SessionFactory getSessionFactory() {
return sessionFactory;
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public Session getSession() {
return sessionFactory.getCurrentSession();
}
@Resource(name = "sessionFactory")
public void setSF(SessionFactory sessionFactory) {
setSessionFactory(sessionFactory);
}
protected Class<E> entityClass;
public BaseDao(Class<E> entityClass) {
this.entityClass = entityClass;
}
public void persist(E entity) {
getSession().save(entity);
}
/**
* 获取属性类型(type),属性名(name),属性值(value)的map组成的list
* */
private ArrayList getFiledsInfo(Object o){
Field[] fields=o.getClass().getDeclaredFields();
String[] fieldNames=new String[fields.length];
ArrayList list = new ArrayList();
Map infoMap=null;
for(int i=0;i<fields.length;i++){
infoMap = new HashMap();
infoMap.put("type", fields[i].getType().toString());
infoMap.put("name", fields[i].getName());
infoMap.put("value", getFieldValueByName(fields[i].getName(), o));
list.add(infoMap);
}
return list;
}
/**
* 根据属性名获取属性值
* */
private Object getFieldValueByName(String fieldName, Object o) {
try {
String firstLetter = fieldName.substring(0, 1).toUpperCase();
String getter = "get" + firstLetter + fieldName.substring(1);
Method method = o.getClass().getMethod(getter, new Class[] {});
Object value = method.invoke(o, new Object[] {});
return value;
} catch (Exception e) {
log.error(e.getMessage(),e);
return null;
}
}
/**
* 获取属性名数组
* */
private String[] getFiledName(Object o){
Field[] fields=o.getClass().getDeclaredFields();
String[] fieldNames=new String[fields.length];
for(int i=0;i<fields.length;i++){
System.out.println(fields[i].getType());
fieldNames[i]=fields[i].getName();
}
return fieldNames;
}
public static java.sql.Date StringToDate(String sDate) {
/**
*str转date方法
*/
String str = sDate;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
java.util.Date d = null;
try {
d = format.parse(str);
} catch (Exception e) {
e.printStackTrace();
}
java.sql.Date date = new java.sql.Date(d.getTime());
return date;
}
public void updateQmm(Object entity){
String[] conditionName= {"id"};
Long[] conditionValue= new Long[1];
ArrayList<String> arrPropertyName=new ArrayList();
ArrayList<String> arrPropertyValue=new ArrayList();
ArrayList<String> arrPropertyType=new ArrayList();
ArrayList<Map> fieldsInfo=getFiledsInfo(entity);
for(int i=0;i<fieldsInfo.size();i++) {
Map m=(Map)fieldsInfo.get(i);
String type=(String)m.get("type");
String name=(String)m.get("name");
if(!name.equals("serialVersionUID")) {
if(m.get("value")!=null) {
String value=String.valueOf(m.get("value"));
if(((String)m.get("name")).equals("id")){
conditionValue[0]=Long.valueOf(value);
}else {
arrPropertyName.add(name);
arrPropertyValue.add(value);
arrPropertyType.add(type);
}
}
}
}
String[] propertyName= new String[arrPropertyName.size()];
Object[] propertyValue= new Object[arrPropertyValue.size()];
for(int i=0;i<arrPropertyName.size();i++) {
String name=(String)arrPropertyName.get(i);
String type=(String)arrPropertyType.get(i);
String value=(String)arrPropertyValue.get(i);
propertyName[i]=name;
if(type.equals("class java.lang.Long")){
propertyValue[i]=Long.valueOf(value);
}else
if(type.equals("class java.lang.String")){
propertyValue[i]=String.valueOf(value);
}else
if(type.equals("class java.sql.Date")){
propertyValue[i]=StringToDate((String)value);
}else
if(type.equals("class java.util.Date")){
propertyValue[i]=StringToDate((String)value);
}
}
updateByProperties(conditionName,conditionValue,propertyName,propertyValue);
}
public boolean deleteByPK(Serializable... id) {
boolean result = false;
if (id != null && id.length > 0) {
for (int i = 0; i < id.length; i++) {
E entity = get(id[i]);
if (entity != null) {
getSession().delete(entity);
result = true;
}
}
}
return result;
}
public void deleteByProperties(String[] propName, Object[] propValue) {
if (propName != null && propName.length > 0 && propValue != null && propValue.length > 0 && propValue.length == propName.length) {
StringBuffer sb = new StringBuffer("delete from " + entityClass.getName() + " o where 1=1 ");
appendQL(sb, propName, propValue);
Query query = getSession().createQuery(sb.toString());
setParameter(query, propName, propValue);
query.executeUpdate();
}
}
public void delete(E entity) {
getSession().delete(entity);
}
public void deleteByProperties(String propName, Object propValue) {
deleteByProperties(new String[] { propName }, new Object[] { propValue });
}
public void updateByProperties(String[] conditionName, Object[] conditionValue, String[] propertyName, Object[] propertyValue) {
if (propertyName != null && propertyName.length > 0 && propertyValue != null && propertyValue.length > 0 && propertyName.length == propertyValue.length && conditionValue != null && conditionValue.length > 0) {
StringBuffer sb = new StringBuffer();
sb.append("update " + entityClass.getName() + " o set ");
for (int i = 0; i < propertyName.length; i++) {
sb.append(propertyName[i] + " = :p_" + propertyName[i] + ",");
}
sb.deleteCharAt(sb.length() - 1);
sb.append(" where 1=1 ");
appendQL(sb, conditionName, conditionValue);
Query query = getSession().createQuery(sb.toString());
for (int i = 0; i < propertyName.length; i++) {
query.setParameter("p_" + propertyName[i], propertyValue[i]);
}
setParameter(query, conditionName, conditionValue);
query.executeUpdate();
} else {
throw new IllegalArgumentException("Method updateByProperties in BaseDao argument is illegal!");
}
}
public void updateByProperties(String[] conditionName, Object[] conditionValue, String propertyName, Object propertyValue) {
updateByProperties(conditionName, conditionValue, new String[] { propertyName }, new Object[] { propertyValu
没有合适的资源?快使用搜索试试~ 我知道了~
基于Vue和SpringBoot的通讯录管理系统源码+sql数据库+项目说明(毕业设计).zip
共2000个文件
gif:1650个
png:463个
java:260个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 44 浏览量
2023-07-20
18:04:55
上传
评论
收藏 45.16MB ZIP 举报
温馨提示
<项目介绍> 基于Vue和SpringBoot的通讯录管理系统源码+sql数据库+项目说明(毕业设计).zip 基于Vue和SpringBoot的通讯录管理系统源码+sql数据库+项目说明(毕业设计).zip 基于Vue和SpringBoot的通讯录管理系统源码+sql数据库+项目说明(毕业设计).zip 该资源内项目源码是个人的毕设,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到94.5分,放心下载使用! 该资源适合计算机相关专业(如人工智能、通信工程、自动化、软件工程等)的在校学生、老师或者企业员工下载,适合小白学习或者实际项目借鉴参考! 当然也可作为毕业设计、课程设计、课程作业、项目初期立项演示等。如果基础还行,可以在此代码基础之上做改动以实现更多功能。 ExtJS 版本的项目在 `extjs` 文件夹下;Vue 版本的项目在 `vue` 文件夹下,自述说明请往下拉! ExtJS 版本是大三《数据库编程》的课程设计,Vue 版本是工作后因个人兴趣编写的版本。 Vue 版本的项目是一个很好的开发模板 ExtJS 版本 `extjs`文件夹下的项目是一个基于 **ExtJS** 和 **SpringBoot** 的通讯录管理系统,模拟了通讯录记录的业务流程,主要包含通讯录类型模块、通讯录明细模块、用户管理、菜单权限管理、图表分析大屏这五个模块。 前端 - Extjs - JQuery 后端 - SpringBoot - Jpa 数据库 - MySql 8.0.30 模块预览 首先是 ExtJS 版本的登陆页,是暗黑风格的登陆模块,登陆界面需要输入标准三大套件:账号、密码、验证码
资源推荐
资源详情
资源评论
收起资源包目录
基于Vue和SpringBoot的通讯录管理系统源码+sql数据库+项目说明(毕业设计).zip (2000个子文件)
tree.btl 26KB
table.btl 26KB
tableIndex.btl 18KB
add.btl 9KB
edit.btl 9KB
mpController.btl 4KB
entity.btl 3KB
mplus.btl 1KB
mpServiceImpl.btl 844B
api.btl 839B
treeApi.btl 739B
mapper.btl 327B
mpService.btl 312B
mapperXml.btl 225B
.classpath 6KB
org.eclipse.wst.common.component 654B
org.eclipse.wst.jsdt.ui.superType.container 49B
ext-theme-neptune-all-rtl-debug.css 676KB
ext-theme-neptune-all-debug.css 661KB
ext-theme-classic-all-rtl-debug.css 633KB
ext-theme-gray-all-rtl-debug.css 625KB
ext-theme-classic-all-debug.css 578KB
ext-theme-gray-all-debug.css 572KB
ext-theme-neptune-all-rtl.css 317KB
ext-theme-neptune-all.css 311KB
ext-theme-classic-all-rtl.css 298KB
ext-theme-gray-all-rtl.css 290KB
ext-theme-classic-all.css 265KB
ext-theme-gray-all.css 258KB
bootstrap.min.css 118KB
layui.css 60KB
extjs.css 8KB
GroupTabPanel.css 4KB
map.css 4KB
statusbar.css 3KB
forestry-style.css 2KB
example.css 1KB
common.css 1KB
portal.css 1KB
ItemSelector.css 629B
login.css 537B
TabScrollerMenu.css 408B
RangeMenu.css 382B
GridFilters.css 189B
LiveSearchGridPanel.css 187B
ext-sandbox-debug.css 79B
DragSelector.css 76B
ext-sandbox.css 73B
ext-all-rtl-debug.css 67B
ext-all-neptune-rtl-debug.css 67B
ext-all-access-rtl-debug.css 65B
ext-all-debug.css 63B
ext-all-neptune-debug.css 63B
ext-all-rtl.css 61B
ext-all-access-debug.css 61B
ext-all-gray-rtl-debug.css 61B
ext-all-neptune-rtl.css 61B
ext-all-access-rtl.css 59B
ext-all-neptune.css 57B
ext-all.css 57B
ext-all-gray-debug.css 57B
ext-all-access.css 55B
ext-all-gray-rtl.css 55B
ext-all-gray.css 51B
kitchensink.gif 16KB
loading2.gif 13KB
chart-area.gif 12KB
chart-themed.gif 11KB
chart-bar-renderer.gif 11KB
chart-mixed.gif 11KB
chart-bar.gif 10KB
chart-area-browser.gif 10KB
chart-radar.gif 10KB
chart-radar-fill.gif 10KB
chart-pie.gif 10KB
chart-line.gif 10KB
chart-column.gif 10KB
chart-bar-stacked.gif 9KB
chart-pie-renderer.gif 9KB
keyboard.gif 8KB
area-browsers.gif 8KB
chart-scatter.gif 7KB
form-custom-access.gif 7KB
nested-loading.gif 7KB
restful-thumb.gif 7KB
form-dashboard.gif 7KB
draw-tiger.gif 6KB
air.gif 6KB
sandbox.gif 6KB
direct.gif 6KB
chooser.gif 6KB
tool-sprites.gif 6KB
tool-sprites.gif 6KB
buttons.gif 6KB
tool-sprites.gif 5KB
tool-sprites.gif 5KB
tab-panel-scroller-menu.gif 5KB
pivotgrid.gif 5KB
column2.gif 5KB
grid-xml.gif 5KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
Make程序设计
- 粉丝: 5723
- 资源: 3570
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功