11智能在线
新记
MyBatis如何连接数据库
如题所述
举报该文章
相关建议 2018-07-16
通过配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="
http://www.springframework.org/schema/beans
"
xmlns:context="
http://www.springframework.org/schema/context
"
xmlns:p="
http://www.springframework.org/schema/p
"
xmlns:aop="
http://www.springframework.org/schema/aop
"
xmlns:tx="
http://www.springframework.org/schema/tx
"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance
"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans
/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context
/spring-context-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop
/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx
/spring-tx-4.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util
/spring-util-4.0.xsd">
<!-- 开启注解扫描 -->
<context:component-scan base-package="com.ijava.springmvc.dao"/>
<!-- 加载配置文件 --> <!-- placeholder 占位符 -->
<context:property-placeholder location="classpath:resources/db.properties"/>
<!-- 数据库连接池 -->
<bean id="datasource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<!-- 创建对象 -->
<bean id="userDao" class="com.ijava.springmvc.dao.UserDaoImpl"></bean>
<bean id="userService" class="com.ijava.springmvc.service.UserServiceImpl"></bean>
<bean class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="datasource"></property>
</bean>
</beans>
温馨提示:内容为网友见解,仅供参考
当前网址:
https://11.t2y.org/zz/8487fsff7psq2smfvs.html
其他看法
无其他回答
相似回答
大家正在搜
相关问题
spring+springmvc+mybatis是怎么连接数...
mybatis 怎么创建数据库
DW如何连接数据库
java中mybatis怎么连接mysql数据库
spring和mybatis整合怎么连接数据库
Java 怎么关闭 mybatis的数据库连接?
mybatis可以连接远程mysql吗?
java mybatis框架外连接数据库在哪里配置?