次に、最後の実装で、MyBatisクエリORCALEデータベースを追加します
ステップ1:いくつかの新しい必要なパッケージを作成すると、結果は次のとおりです
ステップ2:サービスパッケージの下に新しいpersonservice.javaを作成して、名前に従ってperson methodインターフェイスを確認する
パッケージcom.example.first.service;インポートcom.example.first.entity.person; public interface personservice {person querypersonbyname(string name);}ステップ3:serviceimplパッケージの下に新しいpersonserviceimpl.javaを作成して、personservice.javaインターフェイスを実装する
パッケージcom.example.first.serviceimpl; Import com.example.first.persondao.personmapperdao; Import com.example.first.entity.person; Import com.example.serservice; org.springframework.stereotype.service; Import org.springframework.transaction.annotation.transactional;@service@transactionalpublic class personserviceimplはpersonservice {@autowired personmapperdao personmapperdao; @Override Public Person QueryPersonByname(string name){person person = personmapperdao.findbyname(name);返品者; }}ステップ4:PersonDaoの下で新しいPersonMapperdao.javaを作成します。人を照会する方法があります
パッケージcom.example.first.persondao;インポートcom.example.first.entity.person; import org.apache.ibatis.annotations.mapper; @mapperpublic interface 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"> <resportプロパティ= "name =" name "/> <result property =" age "column =" age "名前=#{name} </select> </mapper>ステップ6:application.propertiesにデータソース、マッパーファイルパス、エンティティパスを追加
spring.jpa.database = oraclespring.datasource.datasource.datasourclass-name = oracle.jdbc.driver.oracledriverspring.datasource.url = jdbc:oracle:shin:@// 192.168.3.17:1521/orclspring.data source.username = liguang_devspring.datasource.password = 123456spring.jpa.hibernate.ddl-auto = updatemybatis.mapperlocations = classpath:/mapper/* 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 <http://www.w3.org/2001 xsi:schemalocation = "http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.0.sdsd"> <modeleversion> 4.0.0 </modelversion> <グループ> com.example.first </groupid> <artifactid> springboot </artifactid> <バージョン> 0.0.1-snapshot </version> <packaging> jar </packaging> <name> springboot </name> <説明> spring boot </description> <parent> org.springframework.boot < <バージョン> 1.5.6.Release </version> <RecationPath/> <! - リポジトリからの外観親 - > </parent> <Properties> <Project.Build.SourceEncoding> UTF-8 </Project.Build.SourceEncoding> <Project.Reporting.Outputencoding> <Java.version> 1.8 </java.version> </properties> <dependencies> <dependency> springframework.boot </groupid> <artifactid> spring-boot-starter-web </artifactid> </dependency> <dependency> <グループ< <artifactid> spring-boot-starter-test </artifactid> <scope> test </scope> </dependency> <seplency> <groupid> org.springframework.boot </groupid> <artifactid> spring-boot-starter-thymeleaf </artifactid> <GroupId> oracle </groupId> <artifactid> ojdbc7 </artifactid> <version> 1.0.0.1 </version> </dependency> <! - mybatis依存関係 - > <依存> <groupid> <バージョン> 1.1.1 </version> </dependency> <dependency> groupid> org.springframework.boot </groupid> <artifactid> spring-boot-starter-jdbc </artifactid> </dependency <artifactid> spring-boot-maven-plugin </artifactid> </plugin> </plugins> </build> </project>
ステップ8:http:// localhost:8080/person/show?name = Zhangをブラウザに入力します
要約します
上記は、編集者によって導入されたSpring Boot + MyBatis + Orcale実装の手順の例の説明です。私はそれが誰にでも役立つことを願っています。ご質問がある場合は、メッセージを残してください。編集者は、すべての人に時間内に返信します。 wulin.comのウェブサイトへのご支援ありがとうございます!