当前位置: 首页 > news >正文

重庆江津网站建设网址在线生成短链接

重庆江津网站建设,网址在线生成短链接,wordpress 如何改中文字体,网站禁止右键代码Spring Data是一个非常方便的库。 但是#xff0c;由于该项目是一个相当新的项目#xff0c;因此功能不佳。 默认情况下#xff0c;Spring Data JPA将基于SimpleJpaRepository提供DAO的实现。 在最近的项目中#xff0c;我开发了一个定制的存储库基类#xff0c;以便可以在… Spring Data是一个非常方便的库。 但是由于该项目是一个相当新的项目因此功能不佳。 默认情况下Spring Data JPA将基于SimpleJpaRepository提供DAO的实现。 在最近的项目中我开发了一个定制的存储库基类以便可以在其上添加更多功能。 您可以根据需要向该存储库基类添加特定于供应商的功能。 组态 您必须在spring bean配置文件中添加以下配置。 您必须指定一个新的存储库工厂类。 我们将在以后开发课程。 jpa:repositories base-packageexample.borislam.dao factory-classexample.borislam.data.springData.DefaultRepositoryFactoryBean/ 只需开发一个扩展JpaRepository的接口即可。 您应该记得用NoRepositoryBean对其进行注释。 NoRepositoryBean public interface GenericRepository T, ID extends Serializable extends JpaRepositoryT, ID { } 定义自定义存储库基础实现类 下一步是开发定制的基础存储库类。 您可以看到我只是这个自定义基础存储库中的一个属性即springDataRepositoryInterface。 我只想对存储库接口的自定义行为的行为进行更多控制。 在下一篇文章中我将展示如何添加此基础存储库类的更多功能。 SuppressWarnings(unchecked) NoRepositoryBean public class GenericRepositoryImplT, ID extends Serializable extends SimpleJpaRepositoryT, ID implements GenericRepositoryT, ID , Serializable{private static final long serialVersionUID 1L;static Logger logger Logger.getLogger(GenericRepositoryImpl.class);private final JpaEntityInformationT, ? entityInformation;private final EntityManager em;private final DefaultPersistenceProvider provider;private Class? springDataRepositoryInterface; public Class? getSpringDataRepositoryInterface() {return springDataRepositoryInterface;}public void setSpringDataRepositoryInterface(Class? springDataRepositoryInterface) {this.springDataRepositoryInterface springDataRepositoryInterface;}/*** Creates a new {link SimpleJpaRepository} to manage objects of the given* {link JpaEntityInformation}.* * param entityInformation* param entityManager*/public GenericRepositoryImpl (JpaEntityInformationT, ? entityInformation, EntityManager entityManager , Class? springDataRepositoryInterface) {super(entityInformation, entityManager);this.entityInformation entityInformation;this.em entityManager;this.provider DefaultPersistenceProvider.fromEntityManager(entityManager);this.springDataRepositoryInterface springDataRepositoryInterface;}/*** Creates a new {link SimpleJpaRepository} to manage objects of the given* domain type.* * param domainClass* param em*/public GenericRepositoryImpl(ClassT domainClass, EntityManager em) {this(JpaEntityInformationSupport.getMetadata(domainClass, em), em, null); }public S extends T S save(S entity){ if (this.entityInformation.isNew(entity)) {this.em.persist(entity);flush();return entity;}entity this.em.merge(entity);flush();return entity;}public T saveWithoutFlush(T entity){return super.save(entity);}public ListT saveWithoutFlush(Iterable? extends T entities){ListT result new ArrayListT();if (entities null) {return result;}for (T entity : entities) {result.add(saveWithoutFlush(entity));}return result;} } 作为一个简单的示例我只是覆盖了SimpleJPARepository的默认保存方法。 持久保存后save方法的默认行为不会刷新。 我进行了修改使其在持久化后保持冲洗状态。 另一方面我添加了另一个名为saveWithoutFlush的方法以允许开发人员调用保存实体而无需刷新。 定义自定义存储库工厂bean 最后一步是创建一个工厂bean类和一个工厂类以根据您自定义的基础存储库类来生成存储库。 public class DefaultRepositoryFactoryBean T extends JpaRepositoryS, ID, S, ID extends Serializableextends JpaRepositoryFactoryBeanT, S, ID {/*** Returns a {link RepositoryFactorySupport}.* * param entityManager* return*/protected RepositoryFactorySupport createRepositoryFactory(EntityManager entityManager) {return new DefaultRepositoryFactory(entityManager);} }/*** * The purpose of this class is to override the default behaviour of the spring JpaRepositoryFactory class.* It will produce a GenericRepositoryImpl object instead of SimpleJpaRepository. * */ public class DefaultRepositoryFactory extends JpaRepositoryFactory{private final EntityManager entityManager;private final QueryExtractor extractor;public DefaultRepositoryFactory(EntityManager entityManager) {super(entityManager);Assert.notNull(entityManager);this.entityManager entityManager;this.extractor DefaultPersistenceProvider.fromEntityManager(entityManager);}SuppressWarnings({ unchecked, rawtypes })protected T, ID extends Serializable JpaRepository?, ? getTargetRepository(RepositoryMetadata metadata, EntityManager entityManager) {Class? repositoryInterface metadata.getRepositoryInterface();JpaEntityInformation?, Serializable entityInformation getEntityInformation(metadata.getDomainType());if (isQueryDslExecutor(repositoryInterface)) {return new QueryDslJpaRepository(entityInformation, entityManager);} else {return new GenericRepositoryImpl(entityInformation, entityManager, repositoryInterface); //custom implementation}}Overrideprotected Class? getRepositoryBaseClass(RepositoryMetadata metadata) {if (isQueryDslExecutor(metadata.getRepositoryInterface())) {return QueryDslJpaRepository.class;} else {return GenericRepositoryImpl.class;}}/*** Returns whether the given repository interface requires a QueryDsl* specific implementation to be chosen.* * param repositoryInterface* return*/private boolean isQueryDslExecutor(Class? repositoryInterface) {return QUERY_DSL_PRESENT QueryDslPredicateExecutor.class.isAssignableFrom(repositoryInterface);} } 结论 现在您可以向基础存储库类添加更多功能。 在您的程序中您现在可以创建自己的存储库接口扩展GenericRepository而不是JpaRepository。 public interface MyRepository T, ID extends Serializableextends GenericRepository T, ID {void someCustomMethod(ID id); } 在下一篇文章中我将向您展示如何向此GenericRepository添加Hibernate过滤器功能。 参考来自我们的JCG合作伙伴 Boris Lam在Programming Peacely博客上定制Spring Data JPA存储库 。 翻译自: https://www.javacodegeeks.com/2012/08/customizing-spring-data-jpa-repository.html
http://wiki.neutronadmin.com/news/475844/

相关文章:

  • 杭州做网站哪家最好小说主题+wordpress
  • 怎么学习制作网站创意设计服务是什么
  • 网站全屏视频怎么做上海最新新闻
  • 网站维护北京苏州营销型网站制作
  • 电商平台网站运营方案7k7k小游戏大全
  • 青岛手机建站模板响应式网站自助建设平台
  • 外贸建站手机百度浏览器
  • 濮阳h5建站常州网站建设包括哪些
  • 网站后台怎么做友情链接资源搜索神器
  • 深圳网站制作公司报价seocms
  • 宜春代做网站网站维护 关站 seo
  • 免费网站优化软件珠海网站建设技术支持
  • 新安商品混泥土网站建设网站运营刚做时的工作内容
  • 移动营销做手机网站新乡网站建设公司黄页
  • 手机网站预约表单装修公司网站设计规划
  • 临沂网站seo厦门网站制
  • 百度网站联系方式学历提升销售好做吗
  • ps做网页怎么在网站上打开关键词歌曲免费听
  • 阿里巴巴官网网站网站备案名称的影响
  • 营销型网站建设制作推广淘宝网网页版登陆网址
  • 服务器与网站的关系花生壳域名直接做网站
  • 南翔镇网站建设公司成都网站制作在线
  • 网站建设分为什么黄冈网站推广策略
  • 英迈思网站做不下去可以退款吗网站是怎么做
  • 为何有的网站打不开外贸公司有必要建设网站吗
  • 开封网站建设价格服务器上的网站
  • 有没有什么网站做泰国的东西百度seo算法
  • 北湖区网站建设哪个好开发一个定制的网站
  • 网站建设手机端pc端分开如何建设一个人工智能网站
  • 新手自学做网站多久如何自己建造网站