Spring boot + mybatis + orcale实战(干货)
废话少说,直接上步骤:
第一步:安装好IDEA(此处省略)
第二步:在IDEA新建springboot工程
第三步:在springboot工程的pom.xml添加oracle和mybait依赖
<!-- oracle -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0</version>
</dependency>
<!-- jdbc -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- mybatis -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
第四步:在resources新建文件application.yml
spring:
datasource:
driver-class-name: oracle.jdbc.OracleDriver
url: jdbc:oracle:thin:@192.168.11.162:1521:dbtest
username: li
password: li
mybatis:
mapper-locations: classpath:mapper/*.xml
第五步:新建java/Bean/XXXVO.java 模型
public class UserVO {
private Integer userid;
private Integer age;
private Integer sex;
//getter and setter
}
第六步:新建java/Mapper/XXXMapper.java 接口
@Mapper
public interface AccountMapper { void updateUserInfo(UserVO userVO); //更新用户信息 public List<UserVO> selsetUserList(); //获取用户列表 public UserVO getUserInfoById(Integer userid);//获取会员信息
}
第七步:新建java/Service/XXXService.java 服务
@Repository
@Service
public class AccountService { @Autowired
private AccountMapper accountMapper; public void updateUserInfo(UserVO userVO) {
accountMapper.updateUserInfo(userVO);
} public List<UserVO> selsetUserList(){ return accountMapper.selsetUserList();
} public UserVO getUserInfoById(Integer id){ return accountMapper.getUserInfoById(id);
}
}
第八步:新建resources/mapper上新建XXXMapper.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.cwn.springboot.Mapper.AccountMapper"> <update id="updateUserInfo" parameterType="com.cwn.springboot.bean.UserVO"> update test_users a
<set>
<if test="firstname!=null"> a.firstname =#{firstname}, </if>
<if test="lastname!=null">a.lastname =#{lastname}, </if>
<if test="sex!=null">a.sex =#{sex}, </if>
<if test="age!=null">a.age =#{age}, </if>
<if test="email!=null"> a.email =#{email}, </if>
<if test="usersigninfo!=null">a.usersigninfo =#{usersigninfo}</if>
</set>
where a.userid=#{userid}
</update> <select id="selsetUserList" resultType="com.cwn.springboot.bean.UserVO">
select a.userid,a.username,a.email from test_users a where a.status=1
</select> <select id="getUserInfoById" resultType="com.cwn.springboot.bean.UserVO">
select * from test_users where userid=#{userid}
</select>
</mapper>
第九步:在SpringbootApplicationTests上测试
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Springboot01Application.class)
public class SpringbootApplicationTests { @Autowired
private AccountService accountService; @Test
public void testSelecUser(){
UserVO users= accountService.getUserInfoById(1); System.out.println(users.getUserid());
System.out.println(users.getAge());
System.out.println(users.getSex());
} }
Spring boot + mybatis + orcale实战(干货)的更多相关文章
- Spring boot + mybatis + orcale
接着上次的实现, 添加 mybatis 查询 orcale 数据库 第一步: 新建几个必须的包, 结果如下 第二步: 在service包下新建personService.java 根据名字查perso ...
- Spring Boot Redis Cluster 实战干货
添加配置信息 spring.redis: database: 0 # Redis数据库索引(默认为0) #host: 192.168.1.8 #port: 6379 password: 123456 ...
- Spring Boot 揭秘与实战(二) 数据存储篇 - MyBatis整合
文章目录 1. 环境依赖 2. 数据源3. 脚本初始化 2.1. 方案一 使用 Spring Boot 默认配置 2.2. 方案二 手动创建 4. MyBatis整合5. 总结 4.1. 方案一 通过 ...
- Spring boot Mybatis 整合(完整版)
个人开源项目 springboot+mybatis+thymeleaf+docker构建的个人站点开源项目(集成了个人主页.个人作品.个人博客) 朋友自制的springboot接口文档组件swagge ...
- Spring boot Mybatis 整合(注解版)
之前写过一篇关于springboot 与 mybatis整合的博文,使用了一段时间spring-data-jpa,发现那种方式真的是太爽了,mybatis的xml的映射配置总觉得有点麻烦.接口定义和映 ...
- Github点赞超多的Spring Boot学习教程+实战项目推荐!
Github点赞接近 100k 的Spring Boot学习教程+实战项目推荐! 很明显的一个现象,除了一些老项目,现在 Java 后端项目基本都是基于 Spring Boot 进行开发,毕竟它这 ...
- spring boot + mybatis + druid
因为在用到spring boot + mybatis的项目时候,经常发生访问接口卡,服务器项目用了几天就很卡的甚至不能访问的情况,而我们的项目和数据库都是好了,考虑到可能时数据库连接的问题,所以我打算 ...
- Spring Boot入门教程2-1、使用Spring Boot+MyBatis访问数据库(CURD)注解版
一.前言 什么是MyBatis?MyBatis是目前Java平台最为流行的ORM框架https://baike.baidu.com/item/MyBatis/2824918 本篇开发环境1.操作系统: ...
- spring boot + mybatis + druid配置实践
最近开始搭建spring boot工程,将自身实践分享出来,本文将讲述spring boot + mybatis + druid的配置方案. pom.xml需要引入mybatis 启动依赖: < ...
随机推荐
- WPF模板(二)应用
本次内容来源于电子书,和上一篇一样. 在WPF中有三大模板ControlTemplate,ItemsPanelTemplate,DataTemplate.其中ControlTemplate和Items ...
- 并发的HashMap为什么会引起死循环?
转载:http://blog.csdn.net/zhuqiuhui/article/details/51849692 今天研读Java并发容器和框架时,看到为什么要使用ConcurrentHashMa ...
- sqlite线程模式的设置
(1)编译阶段 这几种模式可以通过参数SQLITE_THREADSAFE在编译阶段指定,可以取值0,1,2,默认是1.这三种取值的含义如下: 0:单线程模式,即内部不做mutex保护,多线程运行sql ...
- 小a与星际探索
链接:https://ac.nowcoder.com/acm/contest/317/C来源:牛客网 小a正在玩一款星际探索游戏,小a需要驾驶着飞船从11号星球出发前往nn号星球.其中每个星球有一个能 ...
- PHP操作Redis常用技巧总结
一.Redis连接与认证 //连接参数:ip.端口.连接超时时间,连接成功返回true,否则返回false $ret = $redis->connect('127.0.0.1', 6379, 3 ...
- 使用Nginx实现反向代理
一.代理服务器 1.什么是代理服务器 代理服务器,客户机在发送请求时,不会直接发送给目的主机,而是先发送给代理服务器,代理服务接受客户机请求之后,再向主机发出,并接收目的主机返回的数据,存放在代理服务 ...
- 【vue】饿了么项目的相关笔记链接
http://www.mtons.com/content/1819.htm http://www.tuicool.com/articles/F7BnaiY https://segmentfault.c ...
- robotframework使用中的一些注意事项
1.关于\的转义.使用\\ 2.关于字符串的合并 3.切换到iframe,切出iframe 4.对对象右键点击 5.对对象实现按键操作,在处理一些下拉对象时需要用到. 6.当元素定位十分困难的时候,需 ...
- centos7 搭建openvpn服务器
OpenVPN是一个开源代码的VPN应用程序,可让您在公共互联网上安全地创建和加入专用网络.相比pptp,openvpn更稳定.安全. 本篇博客主要介绍下面两点: 1. Centos 7下安装与配置O ...
- 简单使用普通用户启动tomcat
新建用户tomcat,该用户不能登录 useradd tomcat -s '/sbin/nologin' 将/usr/local/tomcat/bin/startup.sh更名 mv /usr/loc ...