使用mybatis-plus整合springboot+oracle的使用
oracle的maven依赖:<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency> 项目完备依赖:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.10</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.20</version>
</dependency>
<!--ojdbc依赖-->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
<!--mybatis-plus整合依赖-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.0.5</version>
</dependency>
</dependencies>
(1)创建application.yml文件,修改设置:
server:
port: 8082
spring:
datasource:
url: jdbc:oracle:thin:@//自己虚拟机的IP地址:1521/xe
username: system #数据库名称
password: oracle #数据库密码
driver-class-name: oracle.jdbc.OracleDriver
logging:
level:
root: debug #日志
mybatis-plus:
mapper-locations: classpath:mapper/*Mapper.xml (2)springboot启动类,运行main即可:
@SpringBootApplication
@MapperScan("com.dk.mapper")
public class oracleAppcation {
public static void main(String[] args) {
SpringApplication.run(oracleAppcation.class);
}
}
(3)mybatis-plus三步逆向天生实体类和mapper步调:
1.连接oracle数据库,找到表右键选中
https://img-blog.csdnimg.cn/direct/6950d406616b4347bd1be514a17731b5.png
2.根据自己需求选择要放置位置和定义实体类包名
https://img-blog.csdnimg.cn/direct/3d0392ff9f994af9bfe6aab8029ddf9b.png
3.选中这些标方框的,最后点击fianish确定
https://img-blog.csdnimg.cn/direct/3991107e99df412ebf6872ee646111e4.png
(3)新建一个controller包,在controller包下新建一个EmpController.java:
@RestController
@RequestMapping("/emp")
public class EmpController {
@Autowired
private EmpService empService;
@GetMapping("/empList")
public List<Emp> empList() {
return empService.querAll();
}
} (4)创建service接口及其实现类:
public interface EmpService extends IService<Emp> {
List<Emp> querAll();
} /**
* @author 18310
* @description 针对表【EMP】的数据库操作Service实现
* @createDate 2024-05-20 20:05:14
*/
@Service
public class EmpServiceImpl extends ServiceImpl<EmpMapper, Emp>
implements EmpService{
@Autowired
private EmpMapper empMapper;
@Override
public List<Emp> querAll() {
return empMapper.selectList(null);
}
}
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页:
[1]