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

网友投稿 445 2023-03-05


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

<!DOCTYPhttp://E mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >

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=updaoFuajte

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文件中添加依赖

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

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

oFuaj

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

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

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

oFuaj

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实现步骤实例代码讲解,希望对大家有所帮助,如果大家有任何疑问请给我留言,会及时回复大家的。在此也非常感谢大家对我们网站的支持!


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:接口 设计(接口设计怎么写)
下一篇:api接口状态码文档(api接口代码)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~