<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- namespace:该mapper.xml映射文件的 唯一标识 -->
<mapper namespace="mapper.StudentMapper">
<select id="queryStudentByStuno" parameterType="int" resultType="entity.Student">
select * from student where stuno = #{stuNo}
</select>
<insert id="addStudent" parameterType="entity.Student">
insert into student(stuno,stuname,stuage) values(#{stuNo},#{stuName},#{stuAge})
</insert>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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.xsd">
<bean id="config" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="locations">
<array>
<value>classpath:db.properties</value>
</array>
</property>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${driver}"></property>
<property name="url" value="${url}"></property>
<property name="username" value="${username}"></property>
<property name="password" value="${password}"></property>
</bean>
<bean id="sqlSessionFacotry" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="mapperLocations" value="mapper/*.xml"></property>
</bean>
<!-- 第一种方式生成mapper对象 -->
<!--<bean >-->
<!--<property name="sqlSessionFactory" ref="sqlSessionFacotry"></property>-->
<!--</bean>-->
<!-- 第二种方式生成mapper对象 -->
<!--<bean >-->
<!--<property name="mapperInterface" value="mapper.StudentMapper"></property>-->
<!--<property name="sqlSessionFactory" ref="sqlSessionFacotry"></property>-->
<!--</bean>-->
<!-- 第三种方式生成mapper对象(批量产生多个mapper)
批量产生Mapper对在SpringIOC中的 id值 默认就是 首字母小写接口名 (首字母小写的接口名=id值) -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="sqlSessionFacotry"></property>
<property name="basePackage" value="mapper"></property>
</bean>
<bean id="studentService" class="service.impl.StudentServiceImpl">
<property name="studentMapper" ref="studentMapper"></property>
</bean>
</beans>
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/jdbc
username=root
password=root
maxIdle=1000
maxActive=500