- 新建maven工程。
- 添加mybatis和mysql包,以及log4j的包。
- 新建或者使用现存的数据库,并准备好若干语句。例如使用mysql的默认数据库world。
- 新建mybatis-config.xml配置文件,作为mybaits的基础配置。
- 新建POJO,City。
- 新建mapper文件:city.xml,进行配置。
- 新建Interface,CityMapper,对应city.xml的方法。
- 新建Class: CityService,并implemente CityMapper,实现各种方法。
- 新建Class:MyBatisSqlSessionFactory,用户获取mybatis的session
- 新建测试文件,进行测试。
idea中jar 包配置
log4中写入的代码
实体类中写入代码
在IgoodsTypeDao接口中写入要执行的sql语句
小配置中写入的代码 (resultType与resultMap)(id与接口中方法名相同)
大配置中写入的代码