本文会基于一个搭建好的工程更新配置文件完成。 1、准备 您需要一个搭建好的SpringHibernate工程。 可以直接参考(含下载):Eclipse搭建Maven工程集成Spring4Hibernate5SpringMVC 2、jdbc驱动 若已安装Oracle,在Oracle主目录中有,比如本人的为:C:\app\ia
本文会基于一个搭建好的工程更新配置文件完成。
您需要一个搭建好的Spring+Hibernate工程。
可以直接参考(含下载):Eclipse搭建Maven工程集成Spring4+Hibernate5+SpringMVC
若已安装Oracle,在Oracle主目录中有,比如本人的为:C:\app\iamanxpp\product\12.1.0\dbhome_1\jdbc。
把ojdbc7.jar添加到工程中即可。
因为为Maven工程,添加jar包方式如下:
<ol class="linenums" style="padding:0px 0px 0px 10px; margin:0px; border-left-width:30px; border-left-style:solid; border-left-color:rgb(79,54,57); list-style-type:decimal-leading-zero; color:rgb(176,235,231)"><li class="L0" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"><dependency></span></li><li class="L1" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"><groupId></span><span class="pln" style="color:rgb(198,249,131)">com.oracle</span><span class="tag" style="color:rgb(0,150,219)"></groupId></span></li><li class="L2" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"><artifactId></span><span class="pln" style="color:rgb(198,249,131)">ojdbc14</span><span class="tag" style="color:rgb(0,150,219)"></artifactId></span></li><li class="L3" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"><version></span><span class="pln" style="color:rgb(198,249,131)">10.2.0.4.0</span><span class="tag" style="color:rgb(0,150,219)"></version></span></li><li class="L4" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"><scope></span><span class="pln" style="color:rgb(198,249,131)">system</span><span class="tag" style="color:rgb(0,150,219)"></scope></span></li><li class="L5" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"><systemPath></span><span class="pln" style="color:rgb(198,249,131)">C:\java\workspace\web\Oracle12JDBC\lib\ojdbc7.jar</span><span class="tag" style="color:rgb(0,150,219)"></systemPath></span></li><li class="L6" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"></dependency></span></li></ol>
其中systemPath请填入您实际的jdbc地址。
如果web容器使用tomcat,请将ojdbc7.jar同时添加到tomcat中的lib目录,比如本人为:
<ol class="linenums" style="padding:0px 0px 0px 10px; margin:0px; border-left-width:30px; border-left-style:solid; border-left-color:rgb(79,54,57); list-style-type:decimal-leading-zero; color:rgb(176,235,231)"><li class="L0" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">C</span><span class="pun" style="color:rgb(204,153,153)">:</span><span class="pln" style="color:rgb(198,249,131)">\java\apache</span><span class="pun" style="color:rgb(204,153,153)">-</span><span class="pln" style="color:rgb(198,249,131)">tomcat</span><span class="pun" style="color:rgb(204,153,153)">-</span><span class="lit" style="color:rgb(128,255,128)">7.0</span><span class="pun" style="color:rgb(204,153,153)">.</span><span class="lit" style="color:rgb(128,255,128)">61</span><span class="pln" style="color:rgb(198,249,131)">\lib</span></li></ol>
下面开始更新项目的配置。
db.properties
请修改相关参数为您实际的值:
<ol class="linenums" style="padding:0px 0px 0px 10px; margin:0px; border-left-width:30px; border-left-style:solid; border-left-color:rgb(79,54,57); list-style-type:decimal-leading-zero; color:rgb(176,235,231)"><li class="L0" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="com" style="color:rgb(145,251,250)">#Oracle</span></li><li class="L1" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">jdbc</span><span class="pun" style="color:rgb(204,153,153)">.</span><span class="pln" style="color:rgb(198,249,131)">driverClassName</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="pln" style="color:rgb(198,249,131)">oracle</span><span class="pun" style="color:rgb(204,153,153)">.</span><span class="pln" style="color:rgb(198,249,131)">jdbc</span><span class="pun" style="color:rgb(204,153,153)">.</span><span class="pln" style="color:rgb(198,249,131)">driver</span><span class="pun" style="color:rgb(204,153,153)">.</span><span class="typ" style="color:rgb(246,105,154)">OracleDriver</span></li><li class="L2" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">jdbc</span><span class="pun" style="color:rgb(204,153,153)">.</span><span class="pln" style="color:rgb(198,249,131)">url</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="pln" style="color:rgb(198,249,131)">jdbc</span><span class="pun" style="color:rgb(204,153,153)">:</span><span class="pln" style="color:rgb(198,249,131)">oracle</span><span class="pun" style="color:rgb(204,153,153)">:</span><span class="pln" style="color:rgb(198,249,131)">thin</span><span class="pun" style="color:rgb(204,153,153)">:@</span><span class="com" style="color:rgb(145,251,250)">//127.0.0.1:1521/orcl</span></li><li class="L3" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">jdbc</span><span class="pun" style="color:rgb(204,153,153)">.</span><span class="pln" style="color:rgb(198,249,131)">username</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="pln" style="color:rgb(198,249,131)">yourusername</span></li><li class="L4" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">jdbc</span><span class="pun" style="color:rgb(204,153,153)">.</span><span class="pln" style="color:rgb(198,249,131)">password</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="pln" style="color:rgb(198,249,131)">yourpassword</span></li></ol>
applicationContext.xml
数据源的配置请保证如下:
<ol class="linenums" style="padding:0px 0px 0px 10px; margin:0px; border-left-width:30px; border-left-style:solid; border-left-color:rgb(79,54,57); list-style-type:decimal-leading-zero; color:rgb(176,235,231)"><li class="L0" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"><context:property-placeholder</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">location</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"classpath:/db.properties"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)">/></span></li><li class="L1" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"><bean</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">id</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"dataSource"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">class</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"org.apache.commons.dbcp.BasicDataSource"</span></li><li class="L2" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">destroy-method</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"close"</span><span class="tag" style="color:rgb(0,150,219)">></span></li><li class="L3" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"><property</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">name</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"driverClassName"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">value</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"${jdbc.driverClassName}"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)">/></span></li><li class="L4" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"><property</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">name</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"url"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">value</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"${jdbc.url}"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)">/></span></li><li class="L5" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"><property</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">name</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"username"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">value</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"${jdbc.username}"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)">/></span></li><li class="L6" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"><property</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">name</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"password"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">value</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"${jdbc.password}"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)">/></span></li><li class="L7" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"><property</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">name</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"maxActive"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">value</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"100"</span><span class="tag" style="color:rgb(0,150,219)">></property></span></li><li class="L8" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"><property</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">name</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"minIdle"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">value</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"20"</span><span class="tag" style="color:rgb(0,150,219)">></property></span></li><li class="L9" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"><property</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">name</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"maxWait"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">value</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"3000"</span><span class="tag" style="color:rgb(0,150,219)">></property></span></li><li class="L0" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"><property</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">name</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"initialSize"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">value</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"30"</span><span class="tag" style="color:rgb(0,150,219)">></property></span></li><li class="L1" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"></bean></span></li></ol>
各大数据库sql是有差别的,需要配置方言:
<ol class="linenums" style="padding:0px 0px 0px 10px; margin:0px; border-left-width:30px; border-left-style:solid; border-left-color:rgb(79,54,57); list-style-type:decimal-leading-zero; color:rgb(176,235,231)"><li class="L0" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"><bean</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">id</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"sessionFactory"</span></li><li class="L1" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">class</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"org.springframework.orm.hibernate5.LocalSessionFactoryBean"</span><span class="tag" style="color:rgb(0,150,219)">></span></li><li class="L2" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"><property</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">name</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"dataSource"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">ref</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"dataSource"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)">/></span></li><li class="L3" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"><property</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">name</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"packagesToScan"</span><span class="tag" style="color:rgb(0,150,219)">></span></li><li class="L4" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"><list></span></li><li class="L5" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"><value></span><span class="pln" style="color:rgb(198,249,131)">com.anxpp.demo.core.entity</span><span class="tag" style="color:rgb(0,150,219)"></value></span></li><li class="L6" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"></list></span></li><li class="L7" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"></property></span></li><li class="L8" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"><property</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">name</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"hibernateProperties"</span><span class="tag" style="color:rgb(0,150,219)">></span></li><li class="L9" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"><props></span></li><li class="L0" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"><prop</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">key</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"hibernate.dialect"</span><span class="tag" style="color:rgb(0,150,219)">></span><span class="pln" style="color:rgb(198,249,131)">org.hibernate.dialect.OracleDialect</span><span class="tag" style="color:rgb(0,150,219)"></prop></span></li><li class="L1" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"><prop</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">key</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"hibernate.show_sql"</span><span class="tag" style="color:rgb(0,150,219)">></span><span class="pln" style="color:rgb(198,249,131)">false</span><span class="tag" style="color:rgb(0,150,219)"></prop></span></li><li class="L2" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"><prop</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">key</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"hibernate.format_sql"</span><span class="tag" style="color:rgb(0,150,219)">></span><span class="pln" style="color:rgb(198,249,131)">true</span><span class="tag" style="color:rgb(0,150,219)"></prop></span></li><li class="L3" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"><prop</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">key</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"hibernate.hbm2ddl.auto"</span><span class="tag" style="color:rgb(0,150,219)">></span><span class="pln" style="color:rgb(198,249,131)">update</span><span class="tag" style="color:rgb(0,150,219)"></prop></span></li><li class="L4" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"></props></span></li><li class="L5" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"></property></span></li><li class="L6" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)"></bean></span></li></ol>
如果以上内容有疑问,请先阅读:Eclipse搭建Maven工程集成Spring4+Hibernate5+SpringMVC
接下来就可以编写对应的Controller、Service和Dao层代码了,因为是基于上面提到的那个工程的,所以这里简单修改就能演示了。
添加代码:
<ol class="linenums" style="padding:0px 0px 0px 10px; margin:0px; border-left-width:30px; border-left-style:solid; border-left-color:rgb(79,54,57); list-style-type:decimal-leading-zero; color:rgb(176,235,231)"><li class="L0" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="lit" style="color:rgb(128,255,128)">@RequestMapping</span><span class="pun" style="color:rgb(204,153,153)">(</span><span class="str">"/oracle"</span><span class="pun" style="color:rgb(204,153,153)">)</span></li><li class="L1" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="lit" style="color:rgb(128,255,128)">@ResponseBody</span></li><li class="L2" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="kwd" style="color:rgb(251,140,105)">public</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="typ" style="color:rgb(246,105,154)">String</span><span class="pln" style="color:rgb(198,249,131)"> oracleCreateTable</span><span class="pun" style="color:rgb(204,153,153)">(){</span></li><li class="L3" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> logger</span><span class="pun" style="color:rgb(204,153,153)">.</span><span class="pln" style="color:rgb(198,249,131)">trace</span><span class="pun" style="color:rgb(204,153,153)">(</span><span class="str">"oracle"</span><span class="pun" style="color:rgb(204,153,153)">);</span></li><li class="L4" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> demoService</span><span class="pun" style="color:rgb(204,153,153)">.</span><span class="pln" style="color:rgb(198,249,131)">save</span><span class="pun" style="color:rgb(204,153,153)">(</span><span class="str">"anxpp"</span><span class="pun" style="color:rgb(204,153,153)">);</span></li><li class="L5" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="kwd" style="color:rgb(251,140,105)">return</span><span class="pln" style="color:rgb(198,249,131)"> demoService</span><span class="pun" style="color:rgb(204,153,153)">.</span><span class="pln" style="color:rgb(198,249,131)">findAll</span><span class="pun" style="color:rgb(204,153,153)">();</span></li><li class="L6" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)"> </span><span class="pun" style="color:rgb(204,153,153)">}</span></li></ol>
运行测试:
多次请求将多次插入值到数据库,并返回。
Oracle 12c Windows安装、介绍及简单使用(图文)
Oracle 12c 简单的jdbc使用
Eclipse搭建Maven工程集成Spring4+Hibernate5+SpringMVC