springboot整合mybatis连接oracle

pom.xml:
<!-- 链接:https://pan.baidu.com/s/1agHs5vWeXf90r3OEeVGniw 提取码:wsgm -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc8</artifactId>
<version>12.2.0.1</version>
</dependency> <dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency> <dependency>
<groupId>cn.easyproject</groupId>
<artifactId>orai18n</artifactId>
<version>12.1.0.2.0</version>
</dependency>
User:
/**
* Copyright (c) 2020, All Rights Reserved.
*
*/ package com.demo.server.mybatis; import java.io.Serializable; /**
* 此处应有类说明<br/>
*
* @author chong.zuo
* @Date 2020年2月22日 下午7:40:28
* @since 1.0.0
*
*/
public class User implements Serializable{
/**
* serialVersionUID:
*/
private static final long serialVersionUID = 1L;
private int id;
private String username;
private String password;
private String danWeiTID; @Override
public String toString() {
return "User [danWeiTID=" + danWeiTID + ", id=" + id + ", password="
+ password + ", username=" + username + "]";
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getDanWeiTID() {
return danWeiTID;
}
public void setDanWeiTID(String danWeiTID) {
this.danWeiTID = danWeiTID;
} }
UserController:
/**
* Copyright (c) 2020, All Rights Reserved.
*
*/ package com.demo.server.mybatis; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.demo.server.utils.JsonUtil; /**
* 此处应有类说明<br/>
*
* @author chong.zuo
* @Date 2020年2月22日 下午7:38:32
* @since 1.0.0
*
*/
@RestController
public class UserController { @Autowired
private UserMapper userMapper; @RequestMapping("/getAllUser")
public String getUsers() {
User users = userMapper.findAllUser();
if(users != null) {
return JsonUtil.toJson(users);
}
return "err";
}
}
UserMapper:
/**
* Copyright (c) 2020, All Rights Reserved.
*
*/ package com.demo.server.mybatis; import org.apache.ibatis.annotations.Mapper;
/**
* 此处应有类说明<br/>
*
* @author chong.zuo
* @Date 2020年2月22日 下午7:40:01
* @since 1.0.0
*
*/
@Mapper //添加此注解,便可以被扫描到
public interface UserMapper {
/**
* 返回所有用户列表
* @return
*/
public User findAllUser();
}
UserMapper.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.demo.server.mybatis.UserMapper"> <resultMap id="resultMap" type="com.demo.server.mybatis.User">
<result column="id" jdbcType="VARCHAR" property="id"/>
<result column="user_name" jdbcType="VARCHAR" property="username"/>
<result column="pass_word" jdbcType="VARCHAR" property="password"/>
<result column="danweit_id" jdbcType="VARCHAR" property="danWeiTID"/>
</resultMap> <select id="findAllUser" resultMap="resultMap">
select * from sys_user
</select> </mapper>
application.yml:
server:
port: 7070
session-timeout: 0
context-path: / spring:
datasource:
url: jdbc:oracle:thin:@192.168.5.105:1521:orcl
username: tom
password: tom123
driver-class-name: oracle.jdbc.driver.OracleDriver
max-idle: 10
max-wait: 10000
min-idle: 5
initial-size: 5 mybatis:
mapper-locations: classpath:mapper/*Mapper.xml
type-aliases-package: com.demo.server.mybatis
建表sql:
-- Create table
create table SYS_USER
(
id VARCHAR2(20) not null,
user_name VARCHAR2(20) not null,
pass_word VARCHAR2(20) not null,
danweit_id VARCHAR2(20)
)
tablespace TOMSPACE
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 64K
next 1M
minextents 1
maxextents unlimited
);
-- Add comments to the table
comment on table SYS_USER
is '用户表';
Application:
/**
* Copyright (c) 2020, All Rights Reserved.
*
*/ package com.demo; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; /**
*
* 此处应有类说明<br/>
*
* @author chong.zuo
* @Date 2020年2月20日 下午10:07:09
* @since 1.0.0
*
*/
@SpringBootApplication
public class Application {
private static final Logger LOG = LoggerFactory.getLogger(Application.class); public static void main(String[] args) {
SpringApplication app = new SpringApplication(Application.class);
app.setBannerMode(Banner.Mode.OFF);
app.setWebEnvironment(true);
app.run(args);
LOG.info("**************** Startup Success ****************");
} }


springboot与mybatis整合成功
springboot整合mybatis连接oracle的更多相关文章
- springboot整合mybatis连接mysql数据库出现SQLException异常
在springboot整合mybatis连接数据库的时候,项目中遇到一个SQLException,我检查了properties配置文件,看数据源有没有配错,检查有没有打错字,在数据库中把sql语句查询 ...
- SpringBoot 整合 Mybatis + Mysql——XML配置方式
一.介绍 SpringBoot有两种方法与数据库建立连接,一种是集成Mybatis,另一种用JdbcTemplate,本文主要讨论集成Mybatis方式. SpringBoot整合Mybatis也有两 ...
- SpringBoot整合MyBatis,HiKari、Druid连接池的使用
SpringBoot整合MyBatis 1.创建项目时勾选mybatis.数据库驱动. mysql驱动默认是8.x的版本,如果要使用5.x的版本,创建后到pom.xml中改. 也可以手动添加依赖 ...
- SpringBoot从入门到精通二(SpringBoot整合myBatis的两种方式)
前言 通过上一章的学习,我们已经对SpringBoot有简单的入门,接下来我们深入学习一下SpringBoot,我们知道任何一个网站的数据大多数都是动态的,也就是说数据是从数据库提取出来的,而非静态数 ...
- SpringBoot整合Mybatis之项目结构、数据源
已经有好些日子没有总结了,不是变懒了,而是我一直在奋力学习springboot的路上,现在也算是完成了第一阶段的学习,今天给各位总结总结. 之前在网上找过不少关于springboot的教程,都是一些比 ...
- springboot学习随笔(四):Springboot整合mybatis(含generator自动生成代码)
这章我们将通过springboot整合mybatis来操作数据库 以下内容分为两部分,一部分主要介绍generator自动生成代码,生成model.dao层接口.dao接口对应的sql配置文件 第一部 ...
- SpringBoot系列七:SpringBoot 整合 MyBatis(配置 druid 数据源、配置 MyBatis、事务控制、druid 监控)
1.概念:SpringBoot 整合 MyBatis 2.背景 SpringBoot 得到最终效果是一个简化到极致的 WEB 开发,但是只要牵扯到 WEB 开发,就绝对不可能缺少数据层操作,所有的开发 ...
- 【SpringBoot系列1】SpringBoot整合MyBatis
前言: 一直看网上说SpringBoot是解锁你的配置烦恼,一种超级快速开发的框架.一直挺想学的,正好最近也有时间,就学了下 这个是SpringBoot整合MyBatis的一个教程,用了阿里的drui ...
- SpringBoot整合Mybatis之进门篇
已经有好些日子没有总结了,不是变懒了,而是我一直在奋力学习springboot的路上,现在也算是完成了第一阶段的学习,今天给各位总结总结. 之前在网上找过不少关于springboot的教程,都是一些比 ...
随机推荐
- markdwon编辑公式入门
上标与下标 上标和下标分别使用^ 与_ ,例如\(x_i^2\)表示的是:. 默认情况下,上.下标符号仅仅对下一个组起作用.一个组即单个字符或者使用{..} 包裹起来的内容.如果使用\(10^ ...
- Android_侧滑菜单的实现
1.创建侧滑菜单Fragment package com.example.didida_corder; import android.os.Bundle; import android.view.La ...
- 解决jquery.pjax加载后的异常滚动
个人博客 地址:http://www.wenhaofan.com/article/20181106154356 在使用jquery.pjax的时候发现每次加载完成后都会将滚动条滚动至顶部,用户体验极不 ...
- Hive学习笔记二
目录 Hive常见属性配置 将本地库文件导入Hive案例 Hive常用交互命令 Hive其他命令操作 参数配置方式 Hive常见属性配置 1.Hive数据仓库位置配置 1)Default数据仓库的最原 ...
- SpringBoot学习- 8、整合Shiro
SpringBoot学习足迹 Shiro是什么,引自百度百科:Apache Shiro是一个强大且易用的Java安全框架,执行身份验证.授权.密码和会话管理.使用Shiro的易于理解的API,您可以快 ...
- vue自定义日期选择,类似美团日期选择,日历控件,vue日历区间选择
一个日历的控件,基于vue的,可以日历区间选择,可用于酒店日历区间筛选,动手能力强,可以修改成小程序版本的,先上效果图 里面的颜色样式都是可以修改的 选择范围效果 话不多说,直接上干货,代码可以直接复 ...
- git add 时忽略某些文件或者文件夹
1.git bash 新建 .gitignore文件 touch .gitignore 2.修改.gitignore文件,如下 target/ !.mvn/wrapper/maven-wrapper ...
- SequoiaDB报告创建线程失败的解决办法
1.问题背景 对于分布式数据库和分布式环境,高并发和高性能压力的情况下,出现线程创建失败等等问题也是十分常见的,这时候就十分考虑数据库管理员的经验,需要能快速的定位到问题和瓶颈所在,快速解决.本文也是 ...
- Python2安装MySQLdb
在http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python下载对应的包版本,如果是win7 64位2.7版本的python,就下载 MySQL_p ...
- Linux - Shell - 算术表达式 - 算数运算
概述 shell 中基于 $(()) 的 算数运算 背景 复习 shell 脚本 凑数吧 准备 环境 os centos7 1. 算数运算 代码 #!/bin/bash # $(()) 的数学运算, ...