MyBatis Generator自动生成实体、接口和Mapper


MyBatis Generator自动生成实体、接口和Mapper_第1张图片

1,先建表和字段,根据表的字段来生成实体类


MyBatis Generator自动生成实体、接口和Mapper_第2张图片

2,在项目的pom.xml中加入依赖包


MyBatis Generator自动生成实体、接口和Mapper_第3张图片

3,写generatorConfig.xml文件


MyBatis Generator自动生成实体、接口和Mapper_第4张图片
MyBatis Generator自动生成实体、接口和Mapper_第5张图片


MyBatis Generator自动生成实体、接口和Mapper_第6张图片
MyBatis Generator自动生成实体、接口和Mapper_第7张图片

4,写generator.properties配置文件注入到generatorConfig.xml文件


MyBatis Generator自动生成实体、接口和Mapper_第8张图片

5,运行方法:在eclipse 中,选择pom.xml文件,击右键先择Run AS——>Maven Build… ——>在Goals框中输入:mybatis-generator:generate运行即可。

6,之后会生成

UserMapper(方法接口)

UserMapper.xml(mybatis操作数据库语句)

User(实体类)

UserExample(example类用来写sql)

你可能感兴趣的:(MyBatis Generator自动生成实体、接口和Mapper)