그런 다음 마지막 구현에서 MyBatis Query Orcale 데이터베이스를 추가하십시오.
1 단계 : 몇 가지 새로운 필수 패키지를 만들면 결과는 다음과 같습니다.
2 단계 : 서비스 패키지 아래에 새 personservice.java를 만들어 이름에 따라 개인 메소드 인터페이스를 확인합니다.
package com.example.first.service; import com.example.first.entity.person; public interface personservice {person QueryPersonByName (String Name);}3 단계 : servicempl 패키지 아래에서 새 personserviceimpl.java를 만들어 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.bean.annotation.autowireat; org.springframework.stereotyp.service; import org.springframework.transaction.annotation.transactional;@service@transactionalpublic class personerviceimpl emperservice {@autowired personmapperdao personmapperdao; @override public person QueryPersonByName (String name) {person person = personMapperDao.findbyName (이름); 귀환 담당자; }}4 단계 : Persondao 아래에 새로운 PersonMapperDao.java를 만듭니다. 사람을 쿼리하는 방법이 있습니다
package com.example.first.persondao; import com.example.first.entity.person; import org.apache.ibatis.annotations.mapper; @MapperPublic 인터페이스 PersonMapperDao {Person FindByName (String Name);}5 단계 : 리소스에서 새로운 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"> namespace = "com.example.first.persondao.personMapperDao"> <resultmap id = "findPerson"type = "com.example.first.entity.person"> <result property = "name"열 = "name"/<result property = "age"column = "age"/> </resultmap> <select id = "findbyname" "findbyname" 이름 = #{name} </select> </mapper>6 단계 : Application.Properties의 데이터 소스, Mapper 파일 경로 및 엔터티 경로 추가
spring.jpa.database = oraclespring.datasource.driver-class-name = oracle.jdbc.driver.oracledriverspring.datasource.url = jdbc : oracle :@192.168.3.177:1521/orclspring.data source.username = liguang_devspring.datasource.password = 123456spring.jpa.hibernate.ddl-auto = updatemybatis.mapperlocations = classpath :/mapper/*. xmlmybatis.typealiasespackag = com.example.first.entityspring.thymeleaf.prefix = classpath : /templates/spring.thymeleaf.suffix=.htmlspring.thymeleaf.mode=html5
7 단계 : 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.xsd"> <modeversion> 4.0.0 </modelversion> <groupid> com.example.first </groupid> <artifactid> <버전> 0.0.1-snapshot </version> <packaging> jar </packaging> <name> springboot </name> <description> 스프링 부츠를위한 데모 프로젝트 </descript> <부모> <groupid> org.spramframewort.boot </groupid> <artifactid> spring-boot-starter-parent </artifactid> <버전> <! 저장소에서 부모 조회-> </parent> <properties> <project.build.build.build.sourceencoding> utf-8 </project.build.sourceencoding> <project.reporting.outputencoding> utf-8 </project.reporting.outputencoding> <java.versition> 1.8 </java. <pectionency> <groupId> org.springframework.boot </groupid> <artifactid> 스프링-부트-스타터-web </artifactid> </fectionency> <groupid> org.springframework.boot </groupid> <artifactid> spring-boot-starter-test </artifactid> </artifactid> </artifactid> <pectionency> <groupid> org.springframework.boot </groupid> <artifactid> Spring-Boot-Starter-Thymeleaf </artifactid> </fectionency> <!-오르케일 데이터베이스 종속성-> <pelepency> <groupid> oracle </groupid> <artifactid> </artifactid> <0.0.0 .0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1. </dependency> <-mybatis 종속성-> <pectionency> <groupid> org.mybatis.spring.boot </groupid> <artifactid> mybatis-spring-boot-starter </artifactid> <버전> 1.1.1 </version> </dependency> </groupid> org.spramframwork.sboot.sboot.sboot. <Artifactid> Spring-Boot-Starter-JDBC </artifactid> </fectionency> </fectionency> <build> <flugins> <plugin> <groupid> org.springframework.boot </groupid> <artifactid> Spring-Boot-Maven-Plugin </artifactid> </build> </build> </build> </build> </build>
8 단계 : 브라우저에 http : // localhost : 8080/person/show? name = zhang을 입력하십시오
요약
위는 Spring Boot + Mybatis + Orcale 구현 단계의 예제 코드 설명입니다. 모든 사람에게 도움이되기를 바랍니다. 궁금한 점이 있으면 메시지를 남겨 주시면 편집자가 제 시간에 모든 사람에게 답장을 드리겠습니다. Wulin.com 웹 사이트를 지원해 주셔서 대단히 감사합니다!