欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

前言

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

步驟如下:

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

<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í)體類,注意與數(shù)據(jù)庫(kù)字段對(duì)應(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的方法名對(duì)應(yīng)xml的標(biāo)簽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();
 }
}

啟動(dòng)主程序,瀏覽器訪問http://localhost:9090/listu,

注意oracle驅(qū)動(dòng)版本問題,版本不對(duì)可能會(huì)報(bào)錯(cuò)。

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

總結(jié)

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

相關(guān)文章

最新評(píng)論