基础步骤:
1 数据源
2 sqlSessionFactory
3 MapperScan
打包。
db.properties文件
db.username=root db.password=123456 db.url=jdbc:mysql://192.168.15.135:3310/user db.driverClassName=com.mysql.jdbc.Driver
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd"> <!-- 数据源 --> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"> <property name="username" value="${db.username}" /> <property name="password" value="${db.password}" /> <property name="url" value="${db.url}" /> <property name="driverClassName" value="${db.driverClassName}" /> </bean> <!-- sqlSessionFactory --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <!-- is org.apache.ibatis.builder.BuilderException 缺少约束头导致 --> <property name="configLocation" value="classpath:mybatis.cfg.xml"/> </bean> <!-- mapperScan --> <bean id="mapperScan" class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.sxt.mapper"/> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/> </bean> </beans>
原文:https://www.cnblogs.com/topshark/p/10859636.html