国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

使用springboot暴露oracle數(shù)據(jù)接口的問(wèn)題

瀏覽:62日期:2023-03-12 17:07:04

新建一個(gè)Spring Initializr項(xiàng)目

使用springboot暴露oracle數(shù)據(jù)接口的問(wèn)題

使用springboot暴露oracle數(shù)據(jù)接口的問(wèn)題

使用springboot暴露oracle數(shù)據(jù)接口的問(wèn)題

使用springboot暴露oracle數(shù)據(jù)接口的問(wèn)題

2.把pom.xml文件中的oracle依賴換成自己的oracle版本依賴:

原來(lái)的:

使用springboot暴露oracle數(shù)據(jù)接口的問(wèn)題

現(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; @Servicepublic 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; @RestControllerpublic 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)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 龙南县| 乐亭县| 怀集县| 石渠县| 吴江市| 新密市| 德惠市| 手游| 武汉市| 抚顺县| 宁德市| 同江市| 永新县| 清丰县| 柘城县| 安龙县| 金川县| 清涧县| 普定县| 施甸县| 曲周县| 卫辉市| 金寨县| 太和县| 任丘市| 衡山县| 临江市| 普宁市| 于都县| 西峡县| 金湖县| 秦安县| 林西县| 凤城市| 西盟| 佳木斯市| 车致| 龙岩市| 云林县| 天祝| 重庆市|