SpringBoot+Mybatis+mybatis generate+oracle
原文链接:https://www.cnblogs.com/miketwais/articles/mybatisgenerate_oracle.html
SpringBoot+Mybatis+mybatis generate+oracle配置方法记录,以便不时之需。
1.创建springboot项目,参见以前的文章。
File -> New -> Project -> Spring Initalizr
Next ->填写Project Metadata,其中Type选择Maven Project
Next ->按需选择依赖,如Web-Web,SQL-MyBatis
Next -> Finish
2.配置oracle和mybatis
看看配置好的pom.xml
<?xml version="1.0" encoding="UTF-8"?>4.0.0 com.example demo 0.0.1-SNAPSHOT jar demo Demo project for Spring Boot org.springframework.boot spring-boot-starter-parent 2.0.6.RELEASE UTF-8 UTF-8 1.8 org.springframework.boot spring-boot-starter-web org.mybatis.spring.boot mybatis-spring-boot-starter 1.3.2 com.oracle ojdbc6 12.1.0.1.0 org.springframework.boot spring-boot-starter-jdbc org.springframework.boot spring-boot-devtools runtime org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-maven-plugin org.mybatis.generator mybatis-generator-maven-plugin 1.3.2 com.oracle ojdbc6 12.1.0.1.0 true org.mybatis.generator mybatis-generator-maven-plugin 1.3.2 ${basedir}/src/main/resources/generatorConfig.xml true true
看看application.properties
spring.datasource.driverClassName=oracle.jdbc.driver.OracleDriver spring.datasource.url=jdbc:oracle:thin:@//101.210.212.244:1521/XE spring.datasource.username=UNI_CARD spring.datasource.password=UNI_CARD #spring.datasource.driver-class-name=com.mysql.jdbc.Driver #mybatis.config-location=classpath:mybatis-config.xml mybatis.typeAliasesPackage=com.example.demo.model mybatis.mapper-locations=classpath:mybatis.mapping/*.xml
看看generatorConfig.xml
<?xml version="1.0" encoding="UTF-8"?>
关键点就是上面的几个配置文件,然后需要建立相应的文件夹,必须对应好才不会出错!!!
关于在maven中引用oracle,因为orcale收费不允许maven引用,需要下载到本地仓库使用,具体方法参见:https://www.cnblogs.com/cnsevennight/p/6586801.html
到此就配置完成。
3.使用mybatis-generate生成相应的mapper.xml,mapper文件及实体类。
双击即可。
注意:
常见问题应答:
报错:Table configuration with catalog null错误
解决方法:需要去掉generatorConfig.xml中