欢迎来到天天文库
浏览记录
ID:42575258
大小:164.76 KB
页数:17页
时间:2019-09-18
《Hibernate Maven Spring JDBC 入门》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、HibernateMavenSpringJDBC入门目录SpringJDBC1首先给出项目的Maven依赖:1第一步Dao和Service2第二步写配置文件3第三步编写测试类7SpringHibernate8首先给出项目的maven依赖8第一步编写ORM、DAO和Service9第二步配置文件13第三步编写测试类16SpringJDBC这个例子是银行转账的例子。只做一件事情:从A转钱给B。首先给出项目的Maven依赖:junitjunit3.8.1
2、testorg.springframeworkspring-context4.2.0.RELEASEmysqlmysql-connector-java5.1.363、ncy>c3p0c3p00.9.1.2org.springframeworkspring-jdbc4.2.0.RELEASEorg.springframework4、tifactId>spring-test4.2.0.RELEASEorg.springframeworkspring-aspects4.2.0.RELEASE第一步Dao和Service写DAO和Service。这里需要注意的是一定要用面向接口编程,要不然后面用SpringTest会遇到麻烦。AccountDao.5、javapackagecom.rhythm.springtransaction.demos.demo3;publicinterfaceAccountDao{publicvoidin(Stringin,doublemoney);publicvoidout(Stringout,doublemoney);}AccountImpl.java/**这里用到了JDBC的模板。需要继承自JdbcDaoSupport。*/packagecom.rhythm.springtransaction.demos.demo3;importorg.springframework.jdbc.core.su6、pport.JdbcDaoSupport;publicclassAccountDaoImplextendsJdbcDaoSupportimplementsAccountDao{publicvoidin(Stringin,doublemoney){//TODOAuto-generatedmethodstubthis.getJdbcTemplate().update("updateaccountsetmoney=money+?wherename=?",money,in);}publicvoidout(Stringout,doublemoney){//TODOAuto-genera7、tedmethodstubthis.getJdbcTemplate().update("updateaccountsetmoney=money-?wherename=?",money,out);}}AccountService.javapackagecom.rhythm.springtransaction.demos.demo3;publicinterfaceAccountService{publicvoidtransfer(Stringin,Stringout,doublemoney);}Accoun
3、ncy>c3p0c3p00.9.1.2org.springframeworkspring-jdbc4.2.0.RELEASEorg.springframework4、tifactId>spring-test4.2.0.RELEASEorg.springframeworkspring-aspects4.2.0.RELEASE第一步Dao和Service写DAO和Service。这里需要注意的是一定要用面向接口编程,要不然后面用SpringTest会遇到麻烦。AccountDao.
4、tifactId>spring-test4.2.0.RELEASE
5、javapackagecom.rhythm.springtransaction.demos.demo3;publicinterfaceAccountDao{publicvoidin(Stringin,doublemoney);publicvoidout(Stringout,doublemoney);}AccountImpl.java/**这里用到了JDBC的模板。需要继承自JdbcDaoSupport。*/packagecom.rhythm.springtransaction.demos.demo3;importorg.springframework.jdbc.core.su
6、pport.JdbcDaoSupport;publicclassAccountDaoImplextendsJdbcDaoSupportimplementsAccountDao{publicvoidin(Stringin,doublemoney){//TODOAuto-generatedmethodstubthis.getJdbcTemplate().update("updateaccountsetmoney=money+?wherename=?",money,in);}publicvoidout(Stringout,doublemoney){//TODOAuto-genera
7、tedmethodstubthis.getJdbcTemplate().update("updateaccountsetmoney=money-?wherename=?",money,out);}}AccountService.javapackagecom.rhythm.springtransaction.demos.demo3;publicinterfaceAccountService{publicvoidtransfer(Stringin,Stringout,doublemoney);}Accoun
此文档下载收益归作者所有