ثم في التنفيذ الأخير ، أضف قاعدة بيانات orcale myBatis Query
الخطوة 1: إنشاء بعض الحزم المطلوبة الجديدة ، والنتائج هي كما يلي
الخطوة 2: إنشاء شخص جديد
package com.example.first.service ؛ استيراد com.example.first.entity.person ؛ الواجهة العامة personservice {person querypersonbyname (اسم السلسلة) ؛}الخطوة 3: إنشاء شخص جديد
package com.example.first.serviceImpl ؛ import com.example.first.persondao.personmapperdao ؛ import com.example.first.entity.person ؛ import com.example.first.service.personservice org.springframework.stereotype.service ؛ استيراد org.springframework.transaction.annotation.transactional ؛@service@transactionalpublic class personviceImpl تنفذ personvice {autowired thatmapperdao personmapperdao ؛ Override Public Person QueryPersonByname (اسم السلسلة) {person person = personMapperDao.findbyName (name) ؛ عودة الشخص }}الخطوة 4: إنشاء شخص جديد هناك طريقة للاستعلام عن شخص
package com.example.first.persondao ؛ import com.example.first.entity.person ؛ import org.apache.ibatis.annotations.mapper ؛ mapperpublp interface personmapperdao {person findbyname (name string) ؛}الخطوة 5: إنشاء شخص جديد
<؟ مساحة الاسم = "com.example.first.persondao.personmapperdao"> <resultmap id = "findperson" type = "com.example.first.entity.person من الشخص الذي name = #{name} </select> </mapper>الخطوة 6: إضافة مصدر البيانات ، مسار ملف mapper ومسار الكيان في Application.Properties
spring.jpa.database = oraclespring.datasource.driver-class-name = oracle.jdbc.driver.oracledRiverspring.datasource.url = jdbc: Oracle: Thin:@// 192.168.3.177: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
<؟ XSI: schemalocation = "http://maven.apache.org/pom/4.0.0 <soph> 0.0.1-snapshot </version> <packaging> جرة </packaging> <ame> springboot </name> <specord> عرض العرض التجريبي لـ Spring Boot </description> <Part> <roupiD> org.springframework.boot </rougiD> <SrifactId> spring-boot-parent </trodan <!-Lookup Parent from ropository-> </paret> <properties> <project.build.sourceencoding> utf-8 </project.build.sourceencoding> <project.reporting.outputencoding> utf-8 </project.reporting.utputencoding> <ependencies> <Rependency> <roupiD> org.springframework.boot </rougiD> <StifactId> Spring-boot-Starter-Web </shoseid> </reperence> <redenced> <roupid> org.springframework.boot </grouped> </reperency> <reperency> <roupiD> org.springframework.boot </rougiD> <Stifactid> Spring-Boot-Starter-ThymeLeaf </stifactid> </reperency> <!-orcale database reperence-> dependency> </groupiD> <soph> 1.0.0.1 </version> </sependency> <!-MyBatis تبعيات-> <reperency> <roupiD> org.mybatis.spring.boot </rougeid> <//////repinent <roughid> org.springframework.boot </groupId> <StifactId> Spring-boot-starter-Jdbc </shintifactid> </sependency> </repondency> <stifactid> plugin> <clupin> <roupaid> org.springframework.boot </groupiD> </sultwing> </sults> </buy> </project>
الخطوة 8: أدخل http: // localhost: 8080/person/show؟ name = Zhang in the Browser
لخص
ما سبق هو شرح رمز المثال ل spring boot + mybatis + orcale الخطوات التي قدمها المحرر. آمل أن يكون ذلك مفيدًا للجميع. إذا كان لديك أي أسئلة ، فيرجى ترك رسالة لي وسوف يرد المحرر على الجميع في الوقت المناسب. شكرا جزيلا لدعمكم لموقع wulin.com!