1.导入jar包
mybatis入门程序

2.配置xml文件
一、log4j.properties
# Global logging configuration,建议开发环境中要用debug
log4j.rootLogger=DEBUG, stdout
# Console output…
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
二、SqlMapConfig.xml (配置jdbc数据库连接 mappers 连接写sql的xml文件中)
mybatis入门程序
三、UserMapper.xml (主要写sql代码) 建议命名规则:表名+mapper.xml
mybatis入门程序
3.测试类:
第一种:没有接口,
sqlSessionFactory.openSession 获取sqlSession然后sqlSession.openSession里面配 置xml中的namespace.id
mybatis入门程序
第二种:有接口,
sqlSessionFactory.openSession 获取sqlSession然后sqlSession.getMapper(类.class) 再调用接口中的方法
mybatis入门程序
mybaties开发过程小结
1、编写SqlMapConfig.xml
2、编写mapper.xml
定义了statement
3、编程通过配置文件创建SqlSessionFactory
4、通过SqlSessionFactory获取SqlSession
5、通过SqlSession操作数据库
如果执行添加、更新、删除需要调用SqlSession.commit()
6、SqlSesion使用完成要关闭

相关文章:

  • 2021-10-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-27
  • 2022-03-05
  • 2021-05-17
  • 2022-03-09
猜你喜欢
  • 2021-09-21
  • 2021-11-01
  • 2022-12-23
  • 2021-12-02
相关资源
相似解决方案