您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關怎么使用springboot暴露oracle數據接口的問題的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
springboot一種全新的編程規范,其設計目的是用來簡化新Spring應用的初始搭建以及開發過程,SpringBoot也是一個服務于框架的框架,服務范圍是簡化配置文件。
新建一個Spring Initializr項目
2.把pom.xml文件中的oracle依賴換成自己的oracle版本依賴:
原來的:
現在的:
<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.創建實例類——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; } }
創建接口類——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); }
創建服務類——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); } }
創建控制層類——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); } }
運行此類(MyspboracleApplication.java),在瀏覽器中輸入"http://localhost:8080/all"或者"http://localhost:8080/same?name=l"即可看到想要的結果。
感謝各位的閱讀!關于“怎么使用springboot暴露oracle數據接口的問題”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。