Mybatis-Dao层实现(通过代理方式)
生活随笔
收集整理的這篇文章主要介紹了
Mybatis-Dao层实现(通过代理方式)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.代理方式開發是主流
2.Mapper接口開發方法只需要編寫Mapper接口(相當于Dao接口),然后由Mybatis根據接口創建動態代理對象
Mapper接口開發需要遵循以下規范
一一對應
UserMapper.xml
UserMapper接口(dao層)
public User findById(int Id);ServiceTest類
public class ServiceTest {public static void main(String[] args) throws IOException {InputStream stream = Resources.getResourceAsStream("SqlMapConfig.xml");SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(stream);SqlSession sqlSession = factory.openSession();UserMapper mapper = sqlSession.getMapper(UserMapper.class);User user = mapper.findById(1);System.out.println(user);} }總結
以上是生活随笔為你收集整理的Mybatis-Dao层实现(通过代理方式)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Mybatis-typeAliases的
- 下一篇: Mybatis映射文件动态SQL语句-0