1.新建SpringBoot项目:
2.pom集成mybatis及其它所需要的依赖(主要看你需要哪些)
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.83</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.oracle.database.nls</groupId>
<artifactId>orai18n</artifactId>
<version>21.4.0.0.1</version>
</dependency>
</dependencies>
3.Idea连接数据库,使用MyBatis-Generator直接生成XML,DAO,SERVICE等文件。
4.配置文件
server.port=9001
server.tomcat.uri-encoding=UTF-8
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@数据库host:端口:数据库名
spring.datasource.username=***
spring.datasource.password=***
spring.redis.host=redis的host
spring.redis.port=redis的端口
spring.redis.password=redis的密码
spring.redis.database=0
spring.redis.jedis.pool.max-idle=8
spring.redis.jedis.pool.max-wait=-1
spring.redis.jedis.pool.min-idle=0
mybatis-plus.configuration.jdbc-type-for-null=null
5.主启动类
@MapperScan("com.xs.s.mapper")
@EnableTransactionManagement
@SpringBootApplication
public class SApplication {
public static void main(String[] args) {
SpringApplication.run(SApplication.class, args);
}
}
6.对有事务的service方法上加@Transactional(rollbackFor = Exception.class)
7.其它操作和mysql一样,没什么区别,就不详写了