- MyBatis11-MyBatis的逆向工程
- 一、创建逆向工程的步骤
- a>添加依赖和插件
- b>创建MyBatis的核心配置文件
- c>创建逆向工程的配置文件
- d>执行MBG插件的generate目标
- 二、QBC查询
- 正向工程:先创建Java实体类,由框架负责根据实体类生成数据库表。Hibernate是支持正向工程的。
- 逆向工程:先创建数据库表,由框架负责根据数据库表,反向生成如下资源:
- Java实体类
- Mapper接口
- Mapper映射文件
b>创建MyBatis的核心配置文件4.0.0 com.atguigu.mybatis MyBatis_MBG 1.0-SNAPSHOT jar org.mybatis mybatis 3.5.7 junit junit 4.12 test mysql mysql-connector-java 5.1.3 log4j log4j 1.2.17 com.github.pagehelper pagehelper 5.2.0 org.mybatis.generator mybatis-generator-maven-plugin 1.3.0 org.mybatis.generator mybatis-generator-core 1.3.2 com.mchange c3p0 0.9.2 mysql mysql-connector-java 5.1.8
c>创建逆向工程的配置文件
文件名必须是:generatorConfig.xml
d>执行MBG插件的generate目标
效果:
二、QBC查询@Test
public void testMBG(){
try {
InputStream is = Resources.getResourceAsStream("mybatis-config.xml");
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
SqlSession sqlSession = sqlSessionFactory.openSession(true);
EmpMapper mapper = sqlSession.getMapper(EmpMapper.class);
//查询所有数据
//根据条件查询
mapper.updateByPrimaryKeySelective(new Emp(1,"admin",22,null,"456@qq.com",3));
} catch (IOException e) {
e.printStackTrace();
}
}
;
list.forEach(emp -> System.out.println(emp));*/
mapper.updateByPrimaryKeySelective(new Emp(1,"admin",22,null,"456@qq.com",3));
} catch (IOException e) {
e.printStackTrace();
}
}
暑期编程PK赛
得CSDN机械键盘等精美礼品!


