• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Spring boot + mybatis + orcale实现步骤实例代码讲解

java 搞代码 4年前 (2022-01-05) 26次浏览 已收录 0个评论

这篇文章主要介绍了Spring boot + mybatis + orcale的实现步骤实例代码讲解,需要的朋友可以参考下

接着上次的实现, 添加 mybatis 查询 orcale 数据库

第一步: 新建几个必须的包, 结果如下

第二步: 在service包下新建personService.java 根据名字查person方法接口

 package com.example.first.service; import com.example.first.entity.Person; public interface personService { Person queryPersonByName(String name); }

第三步: 在serviceImpl包下新建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.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service @Transactional public class personServiceImpl implements personService { @Autowired personMapperDao personMapperDao; @Override public Person queryPersonByName(String name) { Person person = personMapperDao.findByName(name); return person; } }

第四步: personDao下新建personMapperDao.java  有一个查询person的方法

 package com.example.first.personDao; import com.example.first.entity.Person; import org.apache.ibatis.annotations.Mapper; @Mapper public interface personMapperDao { Person findByName(String name); }

第五步: 在resource下新建personMapper.xml

     select name,age from person where name = #{name} 

第六步: 在application.properties 中添加数据源 , mapper文件路径 和实体路径

 spring.jpa.database=oracle spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver spring.datasource.url=jdbc:oracle:thin:@//192.168.3.177:1521/orcl spring.datasource.username=liguang_dev spring.datasource.password=123456 spring.jpa.hibernate.ddl-auto=update mybatis.mapperLocations=classpath:/mapper/*.xml mybatis.typeAliasesPackag= com.example.first.entity spring.thymeleaf.prefix=classpath:/templates/ spring.thymeleaf.suffix=.html spring.thymeleaf.mode = HTML5

第七步: 在pom文件中添加依赖

   4.0.0com.example.firstspringboot0.0.1-SNAPSHOTjarspringbootDemo project for Spring Boot org.springframework.bootspring-boot-starter-parent1.5.6.RELEASE<!-- lookup parent from repository --><strong style="color:transparent">来源gaodai#ma#com搞@代~码网</strong> UTF-8UTF-81.8  org.springframework.bootspring-boot-starter-web org.springframework.bootspring-boot-starter-testtest org.springframework.bootspring-boot-starter-thymeleaf<!--orcale数据库依赖--> oracleojdbc71.0.0.1<!--mybatis依赖--> org.mybatis.spring.bootmybatis-spring-boot-starter1.1.1 org.springframework.bootspring-boot-starter-jdbc   org.springframework.bootspring-boot-maven-plugin

第八步:浏览器输入

总结

以上就是Spring boot + mybatis + orcale实现步骤实例代码讲解的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Spring boot + mybatis + orcale实现步骤实例代码讲解

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址