网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

Springboot+mybatis+orcale怎么实现

这篇文章给大家分享的是有关Spring boot + mybatis + orcale怎么实现的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

主要从事网页设计、PC网站建设(电脑版网站建设)、wap网站建设(手机版网站建设)、自适应网站建设、程序开发、微网站、重庆小程序开发公司等,凭借多年来在互联网的打拼,我们在互联网网站建设行业积累了丰富的成都网站设计、做网站、成都外贸网站建设公司、网络营销经验,集策划、开发、设计、营销、管理等多方位专业化运作于一体,具备承接不同规模与类型的建设项目的能力。

添加 mybatis 查询 orcale 数据库

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

Spring boot + 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.0
 com.example.first
 springboot
 0.0.1-SNAPSHOT
 jar
 springboot
 Demo project for Spring Boot
 
  org.springframework.boot
  spring-boot-starter-parent
  1.5.6.RELEASE
   
 
 
  UTF-8
  UTF-8
  1.8
 
 
  
   org.springframework.boot
   spring-boot-starter-web
  
  
   org.springframework.boot
   spring-boot-starter-test
   test
  
  
   org.springframework.boot
   spring-boot-starter-thymeleaf
  
  
  
   oracle
   ojdbc7
   1.0.0.1
  
  
  
   org.mybatis.spring.boot
   mybatis-spring-boot-starter
   1.1.1
  
  
   org.springframework.boot
   spring-boot-starter-jdbc
  
 
 
  
   
    org.springframework.boot
    spring-boot-maven-plugin
   
  
 

第八步:浏览器输入http://localhost:8080/person/show?name=zhang

Spring boot + mybatis + orcale怎么实现

感谢各位的阅读!关于“Spring boot + mybatis + orcale怎么实现”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!


网页标题:Springboot+mybatis+orcale怎么实现
网站路径:http://bjjierui.cn/article/gdsgpg.html

其他资讯