使用mybatisX逆向生成数据表实体类(pojo,dao),mapper,service

先看使用mybatisX后生成的文件。

1.先在idea安装mybatisX插件,在file->setting->plugins,搜索mybatisX插件,重新启动idea即可。

2.在idea编辑器右侧点击Database,点击“+”链接你的数据库类型,这里我选mysql。

 

 

输入root,密码:xxxx

输入url:jdbc:mysql://localhost:3306/emos?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai

后会自动填上:Database: emos

 点击“Test Connection"能连上数据库。如果连不上。需要你按照提示安装mysql插件的。

 

3.确定之后,关闭,右击”Refresh“,数据表就出来了。

 

 

4.右击某一个数据表,出现MybatisX-Generator

 

5.解析下着界面下的意思。

6.下一步,选择mybatis-plus3的模板,并且勾选lombok,勾选lombok生成的实体类会带有lombok的注解。

7. 点击”Finish"完成,提示

8.效果图是:

 

9. 打开自动生成的某一个class,提示bug爆红。

程序包com.baomidou.mybatisplus.extension.service不存在

 在pom.xml安装依赖即可

<dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.3.1.tmp</version>
        </dependency>

10. 启动项目时报bug

springboot available: expected at least 1 bean which qualifies as autowire candidate

是因为SpringBoot项目的Bean装配默认规则是根据Application类所在的包位置从上往下扫描的。

所以需在application启动类中加上

@MapperScan("com.*.dao")//加上你项目的dao或service所在文件位置即可

 

最后项目启动成功。 

猜你喜欢

转载自blog.csdn.net/deng_zhihao692817/article/details/130535182