亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Spring Boot整合MyBatis連接Oracle數(shù)據(jù)庫的步驟全紀錄

 更新時間:2018年07月31日 10:59:21   作者:♚帥  
這篇文章主要給大家介紹了關(guān)于Spring Boot整合MyBatis連接Oracle數(shù)據(jù)庫的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

前言

本文主要分享了Spring Boot整合MyBatis連接Oracle數(shù)據(jù)庫的相關(guān)內(nèi)容,下面話不多說了,直接來詳細的步驟吧。

步驟如下:

1、Spring Boot項目添加MyBatis依賴和Oracle驅(qū)動:

<dependency>
 <groupId>org.mybatis.spring.boot</groupId>
 <artifactId>mybatis-spring-boot-starter</artifactId>
 <version>1.3.2</version>
</dependency>
<dependency>
 <groupId>com.oracle</groupId>
 <artifactId>ojdbc6</artifactId>
 <version>11.2.0.1.0</version>
</dependency>

2、配置application.properties:

#spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#spring.datasource.url=jdbc:mysql://localhost:3306/ems
#spring.datasource.username=root
#spring.datasource.password=root
mybatis.mapper-locations=classpath:/com/example/demo/mapper/*.xml
server.port=9090
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@134.32.9.247:1700/mbss
spring.datasource.username=dbrtadm
spring.datasource.password=dbrtadm

3、新建實體類,注意與數(shù)據(jù)庫字段對應(yīng):

package com.example.demo.entity;
 
import lombok.Getter;
import lombok.Setter;
 
@Getter
@Setter
public class User {
 public int id;
 public String order_id;
}

4、新建mapper(xml):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.example.demo.dao.UserMapper"> 
 <select id = "listUser" resultType="com.example.demo.entity.User">
  select * from t_ps_order_qr
 </select>
</mapper>

5、新建dao接口:

package com.example.demo.dao;
import java.util.List;
 
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface UserMapper {
 public List listUser();
}

 此處應(yīng)加@Mapper注解,interface的方法名對應(yīng)xml的標簽id。

6、新建controller:

package com.example.demo.controller;
 
import java.util.List;
 
import javax.annotation.Resource;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
 
import com.example.demo.dao.UserMapper;
 
@RestController
public class TestController {
 @Resource
 UserMapper um;
  
 @GetMapping("/listu")
 public List listUser() {
  return um.listUser();
 }
}

啟動主程序,瀏覽器訪問http://localhost:9090/listu,

注意oracle驅(qū)動版本問題,版本不對可能會報錯。

需要連接MySQL只需將驅(qū)動和URL更改為MySQL的即可,其余與Oracle相同。

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。

相關(guān)文章

最新評論