SpringBoot+mybatis连接oracle数据库Web开发⼊门实例        各位看官⼤家好,本⼈⼩⽩⼀枚,最近才开始接触研究⽐较⽕热的SpringBoot框架,并⾃⼰做了⼀些简单的整合:
SpringBoot+mybatis连接oracle数据库,并整合Echarts显⽰数据,在此与⼤家分享⼀下在此过程中遇到的问题,最后附上完整的实例代码,废话不多说直接上图贴代码:
1. 使⽤Eclipse创建Maven项⽬(创建过程不再赘述),pom⽂件导⼊相关依赖:
<project xmlns="/POM/4.0.0" xmlns:xsi="/2001/XMLSchema-instance"
xsi:schemaLocation="/POM/4.0.0 /maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>springboot</groupId>
<artifactId>com.springboot-mybatis2</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>com.springboot-mybatis2 Maven Webapp</name>
<url></url>
<!-- 核⼼依赖: -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<!-- ⽀持常规的测试依赖,包括JUnit、Hamcrest、Mockito以及spring-test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<!-- <version>1.5.2</version>
<scope>test</scope> -->
</dependency>
<!-- Web依赖: -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 热部署 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional> <!-- 这个需要为 true 热部署才有效 -->
</dependency>
<dependency>
<groupId&batis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<!-- oracle驱动:ojdbc7依赖 -->
<dependency>
<groupId&acle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.2</version>
</dependency>
<!-- json -->
<dependency>
<groupId>net.sf.json-lib</groupId>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
<!-- 导⼊JSP相关依赖 -->
<!-- servlet依赖. -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- 使⽤jsp引擎,springboot内置tomcat没有此依赖 -->
<dependency>
<groupId>at.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- 引⼊前端框架:echarts和jquery -->
<dependency>
<groupId>org.webjars.bower</groupId>
<artifactId>echarts</artifactId>
<version>4.0.4</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.3.1</version>
</dependency>
</dependencies>
<build>
<finalName>com.springboot-mybatis2</finalName>
</build>
</project>
注:导⼊orale相关依赖步骤:
先复制oracle连接的jar包在电脑某个路径下,如:E:\ojdbc7.jar
在DOS窗⼝下执⾏以下命令,窗⼝提⽰:BUILD SUCESS表⽰成功,再引⼊oracle依赖即可;mvn install:install-file -acle -DartifactId=ojdbc7 -Dversion=12.1.0.2 -Dpackaging=jar -Dfile=E:\ojdbc7.jar 项⽬结构树如下所⽰:
2. 在com.springboot包下新建entity包,在entity包下新建⼀个实体类:student,快捷键Alt+Shift+S,然后选择Generate Getter and Setter
public class student {
private String name;
private String math;
private String chinese;
private String language;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMath() {
return math;
}
public void setMath(String math) {
this.math = math;
}
public String getChinese() {
return chinese;
}
public void setChinese(String chinese) {
this.chinese = chinese;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
@Override
public String toString() {
return "student [name=" + name + ", math=" + math + ", chinese=" + chinese + ",
language=" + language + "]";
安卓开发实例入门}
}
3.在com.springboot包下新建mapper包,在mapper包下新建studentMapper接⼝(注意接⼝下⾯的⽅法名必须与后⾯配置的mapper ⽂件的SQL下⾯的id保持⼀致):
package com.springboot.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import ity.student;
@Mapper
public interface studentMapper {
public List<student> getStudentInfo();
}
4.在com.springboo包下新建Service包,在Service包下新建:studentSerice接⼝:
import java.util.List;
import ity.student;
public interface studentService {
public List<student> getStudentInfo();
}
5.在Service包下新建Imp包,并在Impl包下新建:studentServiceImpl类(相关注解不可少):package com.springboot.service.Impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ity.student;
import com.springboot.mapper.studentMapper;
import com.springboot.service.studentService;
@Service
public class studentServiceImpl implements studentService {
@Autowired
studentMapper stuMapper;
public List<student> getStudentInfo() {
StudentInfo();
}
}
6.在com.springboot包下新建Controller包,并新建studentController类:

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。