首页 > 编程知识 正文

jpa更新数据(jpa更新部分字段)

时间:2023-05-04 20:16:12 阅读:71456 作者:589

一、数据源配置冷黑米

@ configuration @ enabletransactionmanagement @ enablejparepositories (entitymanagerfactoryref=' entitymanagerfactoryaleryaleret TT TT anageralert ',base packages={ ' com.Dian hun.multiple data sources.repository.alert ' } publiccclassalertdbconfig { @ atior @ autowiredprivatehibernatepropertieshibernateproperties; @bean(name='entitymanageralert ' ) publicentitymanagerentitymanageralert (entitymanagerfactorybuilderbuilder ) return } publiclocalcontainerentitymanagerfactorybeanentitymanagerfactoryalert (entitymanagerfactorybuilderbuilder () )。 { return builder.data source (alert数据源).packages (' com.Dian hun.multiple data sources.model.alert ' ).pers objectgetvendorproperties ((returnhibernateproperties.determinehibernateproperties ) ) JPAproperties。 } @ bean (name=' transaction manageralert ' ) publicplatformtransaction managertransaction manageralert (entitymanagerfactory { returnnewjpatransactionmanager (entitymanagerfactoryalert (builder ).getObject ); }} AppDbConfig

@ configuration @ enabletransaction management @ enablejparepositories (entitymanagerfactoryref=' entitymanagerfactoryapp ' ) nagerapp ',base packages={ ' com.Dian hun.multiple data sources.repository.app ' } publiccclassappdbconfig { @ auto wite } @ autowiredprivatehibernatepropertieshibernateproperties; @ primary @ bean (name=' entitymanager app ' ) publicentitymanagerentitymanager (entitymanagerfactorybuilderbuilder ) retymer @ primary @ bean (name=' entitymanagerfactoryapp ' ) publiclocalcontainerentitymanagerfactorybeanentitymanagerfactoryapp () { return builder.data source (appdata source ).packages (' com.Dian hun.multiple data sources.model.app ' ).persisteer }私有映射,objectgetvendorproperties ((returnhibernateproperties.determinehibernateproperties ) ) JPAproperties } @ primary @ bean (name=' transaction managerapp ' ) publicplatformtransaction managertransaction managerapp (entymanager faction wjpatransactionmanager (entitymanagerfactoryapp (builder ).getObject ); } }数据源配置

@ configurationpublicclassdatasourceconfig { @ bean @ primary @ configuration properties (com.Dian hun.s Harding.datasourtiourt ) publicdatasourcepropertiesappdatasourceproperties ({ returnnewdatasourceproperties ) }; } @ bean @ primary @ configuration properties (com.Dian hun.s Harding.data source.app.configuration ' ) publichikarididion asourcebuilder ).type (hikari数据source.class ).build ); } @ bean @ configuration properties (com.Dian hun.s Harding.data source.alert ) publicdatasourcepropertiesalertdatasourt @ bean @ configuration properties (com.Dian hun.s Harding.data source.alert.configuration ' ) publichikaridatatasources { eDataSourceBuilder ).type(Hikaridatasource.class ).build ); (二、项目配置冷黑米

spring : JPA : show-SQL : true com : Dian hun : s Harding : data source : app : URL : JDBC 3360 MySQL 3360/use unicode=truecharacterencoding=utf-8 server time zone=GMT8zerodatetimebehavior=converttonullusername 3360 roootpasword gu ration :最大池大小336030警报: URL : JDBC : MySQL 3360///12360 use unicode=truecharacterencoding=utf-8 server time zone=GMT8zerodatetimebehavior=converttonulllusername 3360 rootpaspatior configuration :最大池大小336030日志记录3360 level : root : info三、实体和接口冷

@动态插入@动态更新@ equalsandhashcode @ entity @ data @ allargsconstructor @ noargsconstructor @ table (namic carashcode ) publicclassappentity { @ id @ column (name=' id ',nullable=false )生成值) strategy=generate gy private string }@Repositorypublic interface曾经的翅膀extends JpaRepositoryAppEntity,Integer {}三,测试冷艳的黑米

@runwith(springrunner.class ) springboottestpublicclassmultipledatasourcesapplicationtest (@ auto wired曾经的翅膀资料库; @ autowiredalertrepositoryalertrepository; @ testpublicvoidtestapp ((存储库. save ) newappentity ) 1,' app ' ); } @ testpublicvoidtestalert ((alert repository.save ) newalertentity )、' testalert ' ); }

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。