Springboot连接Oracle数据库

pom文件

  <dependencies>
        <!--用的是2.3.12.RELEASE版本-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.4.2</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.oracle.database.nls/orai18n -->
        <!--oracle 必备 , 用于处理oracle中文乱码 , 可以删除试试代码运行情况,-->
        <dependency>
            <groupId>com.oracle.database.nls</groupId>
            <artifactId>orai18n</artifactId>
            <version>19.7.0.0</version>
        </dependency>


        <!--        <dependency>-->
        <!--            <groupId>com.baomidou</groupId>-->
        <!--            <artifactId>mybatis-plus-generator</artifactId>-->
        <!--            <version>${mybatis-plus-generator.version}</version>-->
        <!--            <scope>test</scope>-->
        <!--        </dependency>-->

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>com.oracle.database.jdbc</groupId>
            <artifactId>ojdbc8</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>


    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

application.yml文件

server:
  port: 8080
spring:
  datasource:
    driverClassName: oracle.jdbc.driver.OracleDriver
    url: jdbc:oracle:thin:@192.168.2.13:1521:orcl #orcl为sid
    username: cjk
    password: admin#6966
mybatis:
  mapper-locations: classpath:mapper/*.xml
  type-aliases-package: com.example.demo.entity
  configuration:
    map-underscore-to-camel-case: true

mapper层

@Repository
public interface  MedicineMapper extends BaseMapper<Medicine>{
 @Select("select HH,PM,BM,CD,DWBH from yw_kck where HH=#{HH}")
    Medicine selectOne(String HH);
}

url:

http://localhost:8080/getOne?HH=80004

Controller层接收参数:

@RestController
public class MedicineController {
    @Autowired
    private MedicineService medicineService;

   @RequestMapping("/getOne")
    public Medicine getOne( String HH){

       return  medicineService.getOne(HH);

    }
    
}

文章来源地址https://www.uudwc.com/A/GdEbD/

原文地址:https://blog.csdn.net/qq_53906512/article/details/131508859

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请联系站长进行投诉反馈,一经查实,立即删除!

h
上一篇 2023年09月26日 16:23
下一篇 2023年09月26日 16:24