使用springboot暴露oracle數(shù)據(jù)接口的問(wèn)題
新建一個(gè)Spring Initializr項(xiàng)目
2.把pom.xml文件中的oracle依賴換成自己的oracle版本依賴:
原來(lái)的:
現(xiàn)在的:
<dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc6</artifactId> <version>11.2.0.1.0</version> </dependency>
3.編輯application.yml
spring: datasource: driver-class-name: oracle.jdbc.driver.OracleDriver url: jdbc:oracle:thin:@192.168.21.200:1521:orcl username: alisa password: alisa
4.創(chuàng)建實(shí)例類——Userinfos.java:
package cn.alisa.myspboracle.entity; import java.util.Date; public class Userinfos { private int userid; private String username; private Date birthyear; private float userhight; public int getUserid() { return userid; } public void setUserid(int userid) { this.userid = userid; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public Date getBirthyear() { return birthyear; } public void setBirthyear(Date birthyear) { this.birthyear = birthyear; } public float getUserhight() { return userhight; } public void setUserhight(float userhight) { this.userhight = userhight; } }
創(chuàng)建接口類——UserinfosDAO.java
package cn.alisa.myspboracle.dao; import cn.alisa.myspboracle.entity.Userinfos; import org.apache.ibatis.annotations.Select; import java.util.List; public interface UserinfosDAO { @Select("select userid,username,birthyear,userhight from userinfos") public List<Userinfos>findAll(); @Select("select userid,username,birthyear,userhight from userinfos where username like '%${name}%'") public List<Userinfos>findUserSameName(String name); }
創(chuàng)建服務(wù)類——UserinfosService.java
package cn.alisa.myspboracle.service; import cn.alisa.myspboracle.dao.UserinfosDAO; import cn.alisa.myspboracle.entity.Userinfos; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service public class UserinfosService { @Autowired private UserinfosDAO udao; public List<Userinfos>searchAll(){ return udao.findAll(); } public List<Userinfos>sameName(String name){ return udao.findUserSameName(name); } }
創(chuàng)建控制層類——InitCtrl.java:
package cn.alisa.myspboracle.ctrl; import cn.alisa.myspboracle.entity.Userinfos; import cn.alisa.myspboracle.service.UserinfosService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List; @RestController public class InitCtrl { @Autowired private UserinfosService userinfosService; @RequestMapping("/all") public List<Userinfos>init(){ return userinfosService.searchAll(); } @RequestMapping("/same") public List<Userinfos>same(String name){ return userinfosService.sameName(name); } }
編輯MyspboracleApplication.java類:
package cn.alisa.myspboracle; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication @MapperScan("cn.alisa.myspboracle.dao") public class MyspboracleApplication { public static void main(String[] args) { SpringApplication.run(MyspboracleApplication.class, args); } }
運(yùn)行此類(MyspboracleApplication.java),在瀏覽器中輸入"http://localhost:8080/all"或者"http://localhost:8080/same?name=l"即可看到想要的結(jié)果。
到此這篇關(guān)于使用springboot暴露oracle數(shù)據(jù)接口的文章就介紹到這了,更多相關(guān)springboot oracle數(shù)據(jù)接口內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 教你利用springboot集成swagger并生成接口文檔
- Vue+Springboot實(shí)現(xiàn)接口簽名的示例代碼
- Springboot添加支付接口
- SpringBoot集成Spring security JWT實(shí)現(xiàn)接口權(quán)限認(rèn)證
- SpringBoot使用Feign調(diào)用其他服務(wù)接口
- springboot運(yùn)行時(shí)新增/更新外部接口的實(shí)現(xiàn)方法
- 基于注解實(shí)現(xiàn) SpringBoot 接口防刷的方法
- SpringBoot 防止接口惡意多次請(qǐng)求的操作
- 使用SpringBoot跨系統(tǒng)調(diào)用接口的方案
- SpringBoot同一接口多個(gè)實(shí)現(xiàn)類配置的實(shí)例詳解
- SpringBoot可視化接口開(kāi)發(fā)工具magic-api的簡(jiǎn)單使用教程
相關(guān)文章
Oracle數(shù)據(jù)庫(kù)中RETURNING子句的使用
RETURNING子句允許您檢索插入、刪除或更新所修改的列的值,本文主要介紹了Oracle數(shù)據(jù)庫(kù)中RETURNING子句的使用,感興趣的可以了解一下2024-08-08Oracle數(shù)據(jù)庫(kù)實(shí)現(xiàn)遠(yuǎn)程訪問(wèn)方法
Oracle數(shù)據(jù)庫(kù)的遠(yuǎn)程連接可以通過(guò)多種方式來(lái)實(shí)現(xiàn),下面這篇文章主要給大家介紹了關(guān)于Oracle數(shù)據(jù)庫(kù)實(shí)現(xiàn)遠(yuǎn)程訪問(wèn)的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-06-06Linux一鍵部署oracle安裝環(huán)境腳本(推薦)
這篇文章主要介紹了Linux一鍵部署oracle安裝環(huán)境腳本,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-01-01ORA-01578、ORA-01110:數(shù)據(jù)塊被損壞,此時(shí)無(wú)法讀取文件問(wèn)題修復(fù)方案
這篇文章主要給大家介紹了關(guān)于ORA-01578、ORA-01110:數(shù)據(jù)塊被損壞,此時(shí)無(wú)法讀取文件問(wèn)題的修復(fù)方案,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用數(shù)據(jù)庫(kù)具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2024-03-03oracle ORA-00988 missing or invalid password 錯(cuò)誤
在設(shè)置數(shù)據(jù)庫(kù)實(shí)例的密碼時(shí),注意不要以數(shù)字開(kāi)頭,否則您將會(huì)遇到 ORA-00988 missing or invalid password (口令缺失或無(wú)效) 錯(cuò)誤2015-01-01Oracle數(shù)據(jù)庫(kù)常用命令整理(實(shí)用方法)
這篇文章主要介紹了Oracle數(shù)據(jù)庫(kù)常用命令整理(實(shí)用方法),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-06-06Oracle 插入超4000字節(jié)的CLOB字段的處理方法
我們可以通過(guò)創(chuàng)建單獨(dú)的OracleCommand來(lái)進(jìn)行指定的插入,即可獲得成功,這里僅介紹插入clob類型的數(shù)據(jù),blob與此類似,這里就不介紹了,下面介紹兩種辦法2009-07-07