- 浏览: 197761 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
mao_lu:
cor_ggsearch.init("中国,中国人民 ...
仿google搜索框下拉提示效果 -
aas7612:
, thanks very much
JPA映射文件jpa.reveng.xml的配置问题 -
ghbhaozi:
...
Ext MultiSelect实现双击删除
package com.dudu.moa.dao; import java.io.Serializable; import java.lang.reflect.ParameterizedType; import java.util.Collection; import java.util.List; import javax.persistence.EntityManager; import javax.persistence.Query; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.orm.jpa.JpaCallback; import org.springframework.orm.jpa.support.JpaDaoSupport; import org.springframework.util.Assert; /** * 泛化DAO基类. * * 由MyEclipse自动逆向生成的DAO泛化而成. * 用户可扩展此类,定制自己项目中的DAO基类. * * @param <T> DAO访问的entity类 * @param <PK> DAO访问的entity的主键类 * * @see JpaDaoSupport * * @author calvin */ public class GenericJpaDao<T, Serializable extends PK> extends JpaDaoSupport { protected final Log log = LogFactory.getLog(getClass()); protected Class<T> entityClass; protected String className; @SuppressWarnings("unchecked") public GenericJpaDao() { // 通过范型反射,取得在子类中定义的entityClass. this.entityClass = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]; className = entityClass.getSimpleName(); } public void create(T entity) { Assert.notNull(entity); log.debug("saveing " + className + "instance"); getJpaTemplate().persist(entity); logger.debug("save successful"); } public T update(T entity) { Assert.notNull(entity); log.debug("updating " + className + " instance"); T result = getJpaTemplate().merge(entity); logger.debug("update successful"); return result; } public void delete(T entity) { Assert.notNull(entity); log.debug("deleting " + className + " instance"); getJpaTemplate().remove(entity); logger.debug("delete successful"); } public void delete(final PK id) { Assert.notNull(id); log.debug("deleting " + className + " instance"); getJpaTemplate().remove(findById(id)); logger.debug("delete successful"); } /** * @return id对应的Entity.如果id不存在,返回Null. */ public T findById(final PK id) { Assert.notNull(id); log.debug("finding " + className + " instance with id: " + id); return getJpaTemplate().find(entityClass, id); } /** * 根据属性查找对象. * * @param propertyName 属性名 * @param value 属性值 * @param rowStartIdxAndCount 可选的分页参数.第一个参数为起始的记录,第二个参数为返回的对象数量. * * eg. * <CODE> * findByProperty("country","china"); //查找属性值country为china的对象,返回所有对象. * findByProperty("country","china",0,10); //查找属性值country为china的对象,返回第1-10个符合的对象. * </CODE> */ @SuppressWarnings("unchecked") public List<T> findByProperty(final String propertyName, final Object value, final int... rowStartIdxAndCount) { Assert.hasLength(propertyName); log.info("finding " + className + " instance with property: " + propertyName + " , value: " + value); final String queryString = "select model from " + className + " model where model." + propertyName + "= ?"; int rowStartIdx = 0; int rowCount = 0; if (rowStartIdxAndCount != null && rowStartIdxAndCount.length > 0) { rowStartIdx = Math.max(0, rowStartIdxAndCount[0]); if (rowStartIdxAndCount.length > 1) rowCount = Math.max(0, rowStartIdxAndCount[1]); } return findPaged(queryString, rowStartIdx, rowCount, value); } /** * 根据属性查找唯一对象. * * @return 唯一对象.如果不存在符合条件的结果,返回Null,如果有多个对象符合条件,抛出异常. * * @param propertyName 属性名 * @param value 属性值 */ public T findUniqueByProperty(final String propertyName, final Object value) { return uniqueResult(findByProperty(propertyName, value)); } /** * 获取全部对象. * * @param rowStartIdxAndCount 可选的分页参数.第一个参数为起始的记录,第二个参数为返回的对象数量. * * eg. * <CODE> * findAll(); //返回所有对象. * findAll(0,10); //返回第1-10个对象. * </CODE> */ @SuppressWarnings("unchecked") public List<T> findAll(final int... rowStartIdxAndCount) { log.info("finding all " + className + " instances"); final String queryString = "select model from " + className + " model"; int rowStartIdx = 0; int rowCount = 0; if (rowStartIdxAndCount != null && rowStartIdxAndCount.length > 0) { rowStartIdx = Math.max(0, rowStartIdxAndCount[0]); if (rowStartIdxAndCount.length > 1) rowCount = Math.max(0, rowStartIdxAndCount[1]); } return findPaged(queryString, rowStartIdx, rowCount); } /** * 直接使用查询语句查询. * * @param values 任意数量的参数. */ @SuppressWarnings("unchecked") public List find(final String queryString, final Object... values) { Assert.hasLength(queryString); return getJpaTemplate().find(queryString, values); } /** * 直接使用查询语句查询,带分页参数. * * @param rowStartIdx 起始的记录,如不想设定,可设为-1. * @param rowCount 返回的记录数,如不想设定,可设为-1. * @param values 任意数量的参数. */ @SuppressWarnings("unchecked") public List findPaged(final String queryString, final int rowStartIdx, final int rowCount, final Object... values) { return getJpaTemplate().executeFind(new JpaCallback() { public Object doInJpa(EntityManager em) { Query query = em.createQuery(queryString); if (values != null) for (int i = 0; i < values.length; i++) query.setParameter(i + 1, values[i]); if (rowStartIdx > 0) query.setFirstResult(rowStartIdx); if (rowCount > 0) query.setMaxResults(rowCount); return query.getResultList(); } }); } /** * 直接使用查询语句查询,返回唯一对象 * * @param values 任意数量的参数. * @return 唯一对象.如果不存在符合条件的结果,返回NULL,如果有多个对象符合条件,抛出异常. */ @SuppressWarnings("unchecked") public Object findUnique(final String queryString, final Object... values) { Assert.hasLength(queryString); return uniqueResult(getJpaTemplate().find(queryString, values)); } /** * 取得entity的class. */ public Class<T> getEntityClass() { return entityClass; } /** * 取出列表的第一个对象. * 如果列表为空返回Null,如果有多于一个对象,抛出异常. */ private static <E> E uniqueResult(Collection<E> results) { if (results == null || results.isEmpty()) return null; if (results.size() > 1) throw new IllegalArgumentException("the Collection size is larger than 1"); return results.iterator().next(); } }
发表评论
-
邮件发送主题为空的问题?
2010-05-17 15:16 1455还是包冲突的问题,geronimo-javamail_1.4_ ... -
JPA映射文件jpa.reveng.xml的配置问题
2010-05-01 03:03 2638JAP映射oracle 表时,因为字段类型是number, 所 ... -
SpringMVC MultiActionController的使用-最简化教程
2009-06-23 18:08 884Step 1:配置web.xml <?xml ver ... -
Spring 如何在Tomcat 启动时加载资源到内存
2009-06-12 12:17 3423我们常常需要将一些数据在Tomcat启动时加载到内存中,提供其 ... -
webwork与spring的分工[推荐]
2009-06-11 13:55 759webwork的工作,总得来说是提供一个流程的控制: 1. ... -
webwork+spring+hibernate的整合
2009-06-11 13:47 10851、webwork、spring的集成 ... -
WebWork 2.1 / 2.2 与 Spring 集成方法总结
2009-06-11 13:37 638第一部分:WebWork2.1与Spring集成 两种方法: ... -
Spring 启动时报错,空格惹来的麻烦
2009-06-10 20:51 1754工程部署在Tomcat下时,Spring启动没有任何问题,但是 ... -
关于spring启动的优化的问题
2009-06-08 16:02 787最近在负责一个大项目,项目组成员包括项目经理大概10个人左右 ... -
DispatcherServlet定義檔
2009-06-08 14:50 810DispatcherServlet預設使用servlet名稱加 ... -
集合物件注入
2009-06-08 14:24 704對於像陣列、java.util.List、java.util. ... -
Bean定義檔進階讀取
2009-06-08 14:13 842BeanFactory可以接受InputStream作為建構函 ...
相关推荐
那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据
下单系统的Spnigboot和微信小程序实现(全栈微信小程式下单)
该项目是一款基于Java的智能文件管家设计源码,涵盖102个文件,包括29个Java源文件、27个类文件、19个XML配置文件、10个YAML文件、8个列表文件、4个属性文件、4个JAR包文件以及1个Git忽略文件。该系统旨在提供高效便捷的文件管理解决方案。
基于YoloV8的简单目标检测和跟踪,使用KMNET进行鼠标移动(处理多目标移动抖动,处理鼠标平滑移动)
本项目是一款基于Vue和JavaScript开发的心旅途个性化推荐旅游平台设计源码,整合了513个Java文件、76个PNG图片、70个XML配置文件、62个JavaScript文件、42个Vue组件文件、28个CSS样式文件、22个HTML文件、18个YAML配置文件、16个属性文件、11个Vue模板文件,总计919个文件。平台采用现代化前端技术堆栈,旨在为用户提供个性化的旅游推荐服务。
AutoLine是一个基于Python的通用自动化测试开源平台,包含了657个文件,涵盖228个PNG图片、209个CSS样式、95个JavaScript脚本、39个Python源代码、21个HTML文件、19个XML文件、14个GIF图片、6个DS_Store文件、5个文本文件、4个Markdown文件。该平台的设计源码由多种编程语言编写,旨在提供灵活高效的自动化测试解决方案。
微信小程序图像裁剪工具_ e-cropper
【作品名称】:基于MATLAB的答题卡识别系统。带一个GUI可视化界面,通过输入答题卡旋转校正,边缘检测,霍夫曼变换检测答题卡填涂区域 【适用人群】:适用于希望学习不同技术领域的小白或进阶学习者。可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。 【项目介绍】: 传统的阅卷方式为流水线的手工作业方式。这样的方式存在很多的问题,因为很容易受到阅卷者的主观因素的影响,从而产生一定的偏差。所以很多人就讨论如何将人为的因素降低到最低,来确保考生的考试成绩的公平公正和准确。 基于MATLAB的答题卡识别系统。带一个GUI可视化界面,通过输入答题卡旋转校正,边缘检测,霍夫曼变换检测答题卡填涂区域,分割,识别属于ABCD等,通过和实现设置好的标准答案excel对比,从而得出最终分数 【资源声明】:本资源作为“参考资料”而不是“定制需求”,代码只能作为参考,不能完全复制照搬。需要有一定的基础能够看懂代码,能够自行调试代码并解决报错,能够自行添加功能修改代码。
那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据
本项目深入解析并实现了基于Java核心技术的Nacos配置中心,包含2707个文件,涵盖2180个Java源文件、177个JavaScript文件、52个XML文件、35个SCSS文件、22个PEM文件、20个属性文件、18个Markdown文件、16个Protocol Buffers文件、12个JSON文件、11个字体文件。项目涉及多种语言和技术,旨在提供一个全面的配置中心解决方案。
枝晶生长Comsol仿真模型。 锂枝晶生长过程的 枝晶生长Comsol仿真模型。 锂枝晶生长过程的枝晶形貌,温度场耦合,应力场,浓度场,电势场。 C++程序,基于元胞自动机法模拟枝晶生长,能实现任意角度(偏心正方算法),同时采用LBM考虑了对流作用对枝晶生长的影响
本项目为apple_pro客户关系管理系统的组件化开发源码,采用Python、CSS、HTML和JavaScript等多种语言编写,总计包含1078个文件。其中,Python源文件254个,Python编译后文件244个,CSS样式文件65个,HTML模板61个,JavaScript脚本40个,以及其他类型文件如LESS、SCSS、XML、PNG等。该系统通过组件化设计,旨在提升客户关系管理的效率与用户体验。
微信小程序日历插件_Calendar
那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据
另一个小型购物中心。Litemall=Spring Boot后端+Vue管理员前端+微信小程序用户前端+Vue用户移动端_stemall
该项目为基于GitHub的ESPnet语音处理工具包设计源码,包含10633个文件,涵盖Shell脚本、Python、MATLAB、C++等多种编程语言。文件类型包括2872个shell脚本、2303个YAML配置文件、1662个Python脚本、1567个配置文件、306个Markdown文件、223个Perl脚本、39个文本文件、35个Bash脚本、27个PNG图片、21个补丁文件。该项目定期更新,适用于语音处理领域的研究与开发。
该项目是一款基于Python开发的pyecharts可视化图表库源码,包含166个文件,涵盖了121个Python源文件、12个HTML文件、9个JSON文件、6个PNG图片文件、4个Markdown文件、3个文本文件、2个YAML文件以及少量配置和管理文件。该库旨在提供强大的数据可视化解决方案,适用于各种数据分析与展示需求。
STM32软件学习资料GPS与GPRSSTM32软件学习资料GPS与GPRS
那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据
那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据