Springboot+mybatis+orcale怎么實(shí)現(xiàn)

這篇文章給大家分享的是有關(guān)Spring boot + mybatis + orcale怎么實(shí)現(xiàn)的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。

主要從事網(wǎng)頁(yè)設(shè)計(jì)、PC網(wǎng)站建設(shè)(電腦版網(wǎng)站建設(shè))、wap網(wǎng)站建設(shè)(手機(jī)版網(wǎng)站建設(shè))、自適應(yīng)網(wǎng)站建設(shè)、程序開(kāi)發(fā)、微網(wǎng)站、重慶小程序開(kāi)發(fā)公司等,憑借多年來(lái)在互聯(lián)網(wǎng)的打拼,我們?cè)诨ヂ?lián)網(wǎng)網(wǎng)站建設(shè)行業(yè)積累了豐富的成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站、成都外貿(mào)網(wǎng)站建設(shè)公司、網(wǎng)絡(luò)營(yíng)銷經(jīng)驗(yàn),集策劃、開(kāi)發(fā)、設(shè)計(jì)、營(yíng)銷、管理等多方位專業(yè)化運(yùn)作于一體,具備承接不同規(guī)模與類型的建設(shè)項(xiàng)目的能力。

添加 mybatis 查詢 orcale 數(shù)據(jù)庫(kù)

第一步: 新建幾個(gè)必須的包, 結(jié)果如下

Spring boot + mybatis + orcale怎么實(shí)現(xiàn)

第二步: 在service包下新建personService.java 根據(jù)名字查person方法接口

package com.example.first.service;
import com.example.first.entity.Person;
public interface personService {
 Person queryPersonByName(String name);
}

第三步: 在serviceImpl包下新建personServiceImpl.java 實(shí)現(xiàn)personService.java接口

package com.example.first.serviceImpl;
import com.example.first.personDao.personMapperDao;
import com.example.first.entity.Person;
import com.example.first.service.personService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional
public class personServiceImpl implements personService {
 @Autowired
 personMapperDao personMapperDao;
 @Override
 public Person queryPersonByName(String name) {
  Person person = personMapperDao.findByName(name);
  return person;
 }
}

第四步: personDao下新建personMapperDao.java  有一個(gè)查詢person的方法

package com.example.first.personDao;
import com.example.first.entity.Person;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface personMapperDao {
 Person findByName(String name);
}

第五步: 在resource下新建personMapper.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.first.personDao.personMapperDao">
 <resultMap id="findPerson" type="com.example.first.entity.Person">
  <result property="name" column="name"/>
  <result property="age" column="age"/>
 </resultMap>
 <select id="findByName" resultMap="findPerson">
  select name,age from person where name = #{name}
 </select>
</mapper>

第六步: 在application.properties 中添加數(shù)據(jù)源 , mapper文件路徑 和實(shí)體路徑

spring.jpa.database=oracle
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@//192.168.3.177:1521/orcl
spring.datasource.username=liguang_dev
spring.datasource.password=123456
spring.jpa.hibernate.ddl-auto=update
mybatis.mapperLocations=classpath:/mapper/*.xml
mybatis.typeAliasesPackag= com.example.first.entity
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode = HTML5

第七步: 在pom文件中添加依賴

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.example.first</groupId>
 <artifactId>springboot</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <packaging>jar</packaging>
 <name>springboot</name>
 <description>Demo project for Spring Boot</description>
 <parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>1.5.6.RELEASE</version>
  <relativePath/> <!-- lookup parent from repository -->
 </parent>
 <properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  <java.version>1.8</java.version>
 </properties>
 <dependencies>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-test</artifactId>
   <scope>test</scope>
  </dependency>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-thymeleaf</artifactId>
  </dependency>
  <!--orcale數(shù)據(jù)庫(kù)依賴-->
  <dependency>
   <groupId>oracle</groupId>
   <artifactId>ojdbc7</artifactId>
   <version>1.0.0.1</version>
  </dependency>
  <!--mybatis依賴-->
  <dependency>
   <groupId>org.mybatis.spring.boot</groupId>
   <artifactId>mybatis-spring-boot-starter</artifactId>
   <version>1.1.1</version>
  </dependency>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-jdbc</artifactId>
  </dependency>
 </dependencies>
 <build>
  <plugins>
   <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
   </plugin>
  </plugins>
 </build>
</project>

第八步:瀏覽器輸入http://localhost:8080/person/show?name=zhang

Spring boot + mybatis + orcale怎么實(shí)現(xiàn)

感謝各位的閱讀!關(guān)于“Spring boot + mybatis + orcale怎么實(shí)現(xiàn)”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!

網(wǎng)頁(yè)標(biāo)題:Springboot+mybatis+orcale怎么實(shí)現(xiàn)
瀏覽地址:http://muchs.cn/article36/gdsgpg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管、網(wǎng)站制作響應(yīng)式網(wǎng)站、自適應(yīng)網(wǎng)站、全網(wǎng)營(yíng)銷推廣營(yíng)銷型網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

微信小程序開(kāi)發(fā)