Ensuite, dans la dernière implémentation, ajoutez la base de données Orcale Query MyBatis
Étape 1: Créez quelques nouveaux packages requis, les résultats sont les suivants
Étape 2: Créez un nouveau PersonService.java sous le package Service pour vérifier l'interface de la méthode de personne en fonction du nom
package com.example.first.service; import com.example.first.entity.eson; interface publique PersonService {Person QueryPersonByName (nom de chaîne);}Étape 3: Créez un nouveau PersonServiceImpl.java sous le package ServiceImpl pour implémenter l'interface PersonService.java
package com.example.first.serviceImpl; import com.example.first.persondao.personmapperdao; import com.example.first.entity.person; importer com.example.first.service.annotation.Autowired; import; org.springframework.sterreotype.service; import org.springframework.transaction.annotation.transactional; @ service @ transactionalpublic class PersonServiceImplt implémente les personnes {@Autowired personmapperdao personmapperdao; @Override Public Person QueryPersonByName (String Name) {Person Person = PersonMapperDao.FindByName (Name); personne de retour; }}Étape 4: Créez un nouveau personnage Personmapperdao.java sous Persondao. Il existe une méthode pour interroger la personne
package com.example.first.persondao; import com.example.first.entity.person; import org.apache.ibatis.annotations.mapper; @mapperpublic interface personMapperDao {personne findByName (String name);}Étape 5: Créez un nouveau personnage de personnage.xml sous ressource
<? xml version = "1.0" Encoding = "UTF-8"?> <! Doctype Mappep Public "- // Mybatis.org//dtd Mappen 3.0 // en" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace = "com.example.first.persondao.personmapperdao"> <résultatmap id = "findperson" type = "com.example.first.entity.person"> <result Property = "name" chronn = "name" /> <result Property = "Age" Column = "Age" /> </ ResultMap> <SELECT ID = "findbyname" ResultMAP = " Nom, âge de la personne où name = # {nom} </lect> </ mapper>Étape 6: Ajouter la source de données, le chemin du fichier de mappeur et le chemin d'accès à l'application.
printemps.jpa.database = oraclespring.datasource.driver-class-name = oracle.jdbc.driver.oracledriverspring.datasource.url = jdbc: oracle: mince: @ // 192.168.3.177:1521/orclspring.data source.username = liguang_devspring.datasource.password = 123456spring.jpa.hibernate.ddl-uto = updatemybatis.mapperLocations = classpath: / mapper / *. xmlmybatis.typeasespackag = com.example.first.entityspring.thymeleaf.prefix = classpath: /templates/spring.thymeleaf.suffix=.htmlspring.thymeleaf.mode=html5
Étape 7: Ajouter des dépendances dans le fichier 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.0.xsd"> <modelversion> 4.0.0 </ Modelversion> <proupId> com.example <version> 0.0.1-snapshot </ version> <packaging> jar </packaging> <name> Springboot </name> <Description> Projet de démonstration pour Spring Boot </ Description> <parent> <proupId> Org.SpringFramework.boot </prouvenid> <Artifactid> printemps-boot-starter-parent </ptetifAtid> <DERNÉRATIVE> 1.5.6.release </parent> </ptetifAtid> <DERNÉRATION> 1.5.6.Release <! - Recherche parent du référentiel -> </parent> <properties> <project.build.sourceencoding> utf-8 </project.build.sourceencoding> <project.reportting.outputending> utf-8 </project.report.outputerSice> <java.version> 1.8 </java.version> <dependency> <proupId> org.springframework.boot </proupId> <Artifactid> printemp-boot-starter-web </retifactid> </pedigency> <dependency> <prouprid> org.springframework.boot </proupId> <pteridenctid> Spring-Boot-starter-test </ artifactid> <scope> Teste> </scope> <dependency> <proupId> org.springframework.boot </proupId> <Artifactid> printemps-boot-starter-thymeleaf </ artifactid> </dendency> <! - Orcale Database Dependance -> <Dedency> <proupId> Oracle </proupId> <Artifactid> Ojdbc7 </letifactid> </Dependency> <! - MyBatis Dependances -> <Dedency> <GroupId> org.mybatis.spring.boot </proupId> <Retifactid> Mybatis-Spring-Boot-starter </ Artifactid> <ArtefactId> printemps-boot-starter-jdbc </lefactive> </dependency> </dependency> <uild> <plugins> <Glugin> <ProupId> org.springframework.boot </proncId> <eRtifActid> Spring-Boot-Maven-Plugin </ Artifactid> </Gluner> </Glugins>
Étape 8: Entrez http: // localhost: 8080 / personne / show? Name = zhang dans le navigateur
Résumer
Ce qui précède est l'exemple d'explication du code de Spring Boot + MyBatis + Stapes d'implémentation orcale introduites par l'éditeur. J'espère que ce sera utile à tout le monde. Si vous avez des questions, veuillez me laisser un message et l'éditeur répondra à tout le monde à temps. Merci beaucoup pour votre soutien au site Web Wulin.com!