Spring整合myBatis 方式二
2022-04-25 23:13:30

UserMapperImpl

和原来比,需要继承SqlSessionDaoSupport ,不用set方法

package com.liu.mapper;

import com.liu.pojo.User;
import org.mybatis.spring.support.SqlSessionDaoSupport;

import java.util.List;

public class UserMapperImpl2 extends SqlSessionDaoSupport implements UserMapper {
    @Override
    public List<User> selectUser() {
        return getSqlSession().getMapper(UserMapper.class).selectUser();
    }
}

Spring-dao.xml

    <bean id="selectUserImpl2" class="com.liu.mapper.UserMapperImpl2">
        <property name="sqlSessionFactory" ref="sqlSessionFactory"/>
    </bean>

其他和方式一相同

本文摘自 :https://www.cnblogs.com/123xian/p/16192300.html


更多科技新闻 ......