开发者学堂课程【Java Web 开发系列课程:Spring 框架入门:spring 整合 mybatis 03】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/538/detail/7353
spring整合 mybatis 03
内容简介:
一、mybatis 使用注解
二、UserMapper
三、Spring 的配置文件
一、mybatis 使用注解
spring 整合 mybatis 第三种方式
1.mybatis 使用注解
2.UserMapper
二、UserMapper
代码如下:
UserMapper
public interface UserMapper
@Select("select * from user") public List selectUser();}
UserServcielmpl
public class UserServiceImpl implements UserService{
private UserMapper userMapper=null;
public void setUserMapper(UserMapper userMapper) {
this.userMapper =userMapper;
@override
public List selectUser(){
return userMapper.selectUser();
}
三、Spring 的配置文件
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns;aop="http://www.springframework.org/schema/aop xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
class="org.springframework.jdbc.datasource.DriverManagerData Source">
value="com.mysql.jdbc.Driver"/>
value="com.mysgl.jdbc,Driver"/>
value="jdbc:mysql://localhost:3306/test"/>
cn.sxt,secvice,impl.*.*(..))"id="pointcut"y>
pointcut-ref="pointcut"/>
class="org.mybatis.spring,SalsessionfactoryBean">
value="classpath:mybatis.cfg.xml"/>
class="org.mybatis.spring.mapper.MapperFactoryBean">
value="cn.sxt.dao.UserMapper"/>
ref="sglSessionFactory"/>
class="cn.sxt.service.impl.UserServiceImpl">