架构实战项目心得(七):使用SpringBoot+Dubbo+Mybatisplus+Oracle搭建后台项目框架(二)
接下来我们将整合mybatisplus+Oracle,实现一个简单的查询。(期间踩了很多坑,遇到一些问题,还好慢慢解决了。现在是通过配置文件的方式来进行dubbo服务的注册和发布,希望以后能在学习和实践中使用springboot注解方式(也有可能是因为知识还没到那个层面,无法弄懂其中的奥义
))
一、SpringBoot整合mybatisplus
1 众所周知,mybatisplus作为mybatis的一个升级版,大大地简化了大家配置mybatis的xml文件的时间,并且已经整合了很多通用的方法,包括分页的方法等,本项目不细讲mybatisplus,有兴趣的同学可以自己去学一下。本次项目使用mybatisplus作为后台数据库访问的框架。
2 mybatisplus和mybatisplus的SpringBoot依赖:
<!--mybatisplus 依赖 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>${mybatisplus.version}</version>
</dependency>
<!-- Mybatisplus SpringBoot-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatisplus-spring-boot-starter</artifactId>
<version>${mybatisplus-spring-boot-starter.version}</version>
</dependency>
具体的版本根据你的需求来定。
3 对应的实体类UserEntity:
@TableName("USER_INFO")
public class UserEntity extends Model<UserEntity> {
@TableId(value = "USER_ID",type = IdType.AUTO)
private Integer userId;
private String username;
private String password;
private Integer age;
protected Serializable pkVal() {
return userId;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
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 Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
@Override
public String toString() {
return "UserEntity{" +
"userId=" + userId +
", username='" + username + '\'' +
", password='" + password + '\'' +
", age=" + age +
'}';
}
public UserEntity(Integer userId, String username, String password, Integer age) {
this.userId = userId;
this.username = username;
this.password = password;
this.age = age;
}
public UserEntity() {
}
4 Mapper层UserMapper:
public interface UserMapper extends BaseMapper<UserEntity>{
Integer getCount();
}
5 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.laowang.mapper.UserMapper">
<resultMap id="userMap" type="com.laowang.entity.UserEntity">
<result column="USER_ID" property="userId"></result>
<result column="USERNAME" property="username"></result>
<result column="PASSWORD" property="password"></result>
<result column="AGE" property="age"></result>
</resultMap>
<select id="getCount" resultType="java.lang.Integer">
SELECT COUNT(1) FROM USER_INFO
</select>
</mapper>
6 服务接口层IUserService:
public interface IUserService extends IService<UserEntity> {
UserEntity getUserById(int id);
UserEntity findUser();
/**
* 查询总数量
* @return
*/
Integer getCount();
}
7 服务接口实现层UserServiceImpl:
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper,UserEntity> implements IUserService {
@Autowired
private UserMapper userMapper; public UserEntity getUserById(int id) {
return userMapper.selectById(id);
} public UserEntity findUser() {
return new UserEntity(20,"laowang","123456789",24);
} public Integer getCount() {
return userMapper.getCount();
}
}
8 控制层UserController:
@RestController
public class UserController {
@Autowired
private IUserService userService; @GetMapping("/getUser/{id}")
public UserEntity getUser(@PathVariable int id) {
return userService.getUserById(id);
} @GetMapping("/test")
public UserEntity findUser() {
return userService.findUser();
} @GetMapping("/getCount")
public Integer getCount() {
return userService.getCount();
}
}
9 application.yml:
# Dubbo 服务提供者配置
server:
port: 8070
spring:
application:
name: provider
datasource:
url: jdbc:oracle:thin:@127.0.0.1:1521:hadoop
username: sys as sysdba
password: 123456789
driver-class-name: oracle.jdbc.driver.OracleDriver
type: com.alibaba.druid.pool.DruidDataSource
initialSize: 5
minIdle: 5
maxActive: 20
maxWait: 60000
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
filters: stat,wall,logback
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
useGlobalDataSourceStat: true
mybatis:
mapper-locations: classpath:mapper/*Mapper.xml
#实体扫描,多个package用逗号或者分号分隔
type-aliases-package: com.laowang.entity
10 运行项目进行测试,即可得到一个简单的查询结果(由于我的项目已经分割了,所以这里暂时看不到效果,希望大家按照我的步骤去尝试,能够得到一个简答的查询)
架构实战项目心得(七):使用SpringBoot+Dubbo+Mybatisplus+Oracle搭建后台项目框架(二)的更多相关文章
- 【SSH网上商城项目实战03】使用EasyUI搭建后台页面框架
转自:https://blog.csdn.net/eson_15/article/details/51312490 前面两节,我们整合了SSH并且抽取了service和action部分的接口,可以说基 ...
- SpringBoot+thymeleaf+security+vue搭建后台框架 基础篇(一)
刚刚接触SpringBoot,说说踩过的坑,主要的还是要记录下来,供以后反省反省! 今天主要讲讲 thymeleaf+security 的搭建,SpringBoot的项目搭建应该比较简单,这里就不多说 ...
- VUE+ElementUI 搭建后台项目(一)
前言 之前有些过移动端的项目搭建的文章,感觉不写个pc端管理系统老感觉少了点什么,最近公司项目比较多,恰巧要做一个申报系统的后台管理系统,鉴于对vue技术栈比较熟悉,所以考虑还是使用vue技术栈来做: ...
- SpringBoot+Dubbo+Zookeeper整合搭建简单的分布式应用
为什么要使用分布式系统? 容错 减少延迟/提高性能 可用性 负载均衡 总而言之,其实目的只有一个,”用户体验“. 什么是分布式系统? 分布式系统是由使用分发中间件连接的自治计算机组成的网络.它们有助于 ...
- SpringBoot + Layui +Mybatis-plus实现简单后台管理系统(内置安全过滤器)
1. 简介 layui(谐音:类UI)是一款采用自身模块规范编写的前端UI框架,遵循原生HTML/CSS/JS的书写与组织形式,门槛极低,拿来即用.其外在极简,却又不失饱满的内在,体积轻盈,组件丰 ...
- Java开发学习心得(一):SSM环境搭建
目录 Java开发学习心得(一):SSM环境搭建 1 SSM框架 1.1 Spring Framework 1.2 Spring MVC Java开发学习心得(一):SSM环境搭建 有一点.NET的开 ...
- 手把手教你用vue-cli搭建vue项目
手把手教你用vue-cli搭建vue项目 本篇主要是利用vue-cli来搭建vue项目,其中前提是node和npm已经安装好,文章结尾将会简单提到一个简单的例子.使用vue-cli搭建项目最开始我也是 ...
- 利用vue-cli搭建vue项目
手把手教你用vue-cli搭建vue项目 本篇主要是利用vue-cli来搭建vue项目,其中前提是node和npm已经安装好,文章结尾将会简单提到一个简单的例子.使用vue-cli搭建项目最开始我也是 ...
- 手把手0基础项目实战(一)——教你搭建一套可自动化构建的微服务框架(SpringBoot+Dubbo+Docker+Jenkins)...
原文:手把手0基础项目实战(一)--教你搭建一套可自动化构建的微服务框架(SpringBoot+Dubbo+Docker+Jenkins)... 本文你将学到什么? 本文将以原理+实战的方式,首先对& ...
随机推荐
- Data Base Oracle 常用命令
Data Base Oracle 常用命令 1.登录:(不需要密码,属于管理员权限) conn /as sysdba; 2.查看数据库存储位置: select name from v$datafil ...
- redis 3.0 集群__配置文件详解(常用配置)
参考文档 http://www.cnblogs.com/huangjacky/p/3700473.html http://www.cnblogs.com/cxd4321/archive/2012/12 ...
- css盒子模型基础,margin-top塌陷,元素溢出
现在布局不用table,一般用盒子模型来布局,也就是通常说的div+css,一个页面就是多个盒子的拼接 一. 初识盒子模型 例子1,测试盒子各属性设置 <head> <s ...
- 使用 final 关键字修饰一个变量时,是引用不能变,还是引用的对象不能变?
使用 final 关键字修饰一个变量时,是指引用变量不能变,引用变量所指向的对象中的内容还是可以改变的.例如,对于如下语句:final StringBuffer a=new StringBuffer( ...
- git 和 repo 常用命令
一.git 1.回退到某个节点 git reset --hard f39043d1c0cd1cda45a4569556758d0c00bf329a 2.查看提交记录 git log git log - ...
- [转载] 第三篇:数据仓库系统的实现与使用(含OLAP重点讲解)
阅读目录 前言 创建数据仓库 ETL:抽取.转换.加载 OLAP/BI工具 数据立方体(Data Cube) OLAP的架构模式 小结 回到顶部 前言 上一篇重点讲解了数据仓库建模,它是数据仓库开发中 ...
- 设计模式 — 建造者(生成器)模式(Builder)
考虑这样一种业务场景,我们构建一个业务对象,但是这个业务对象及其复杂.为了代码的根号的可读性,我们会把这个对象的构建过程根据精密联系的程度来拆分成几个类来完成.最后再放到一起使用来生成复杂对象.这个业 ...
- Vue页面加载时,触发某个函数的方法
需要在加载页面的时候调用生成验证码的click事件函数 解决方法如下,利用Vue中的mounted mounted:function(){ this.createcode();//需要触发的函数 } ...
- 高阶篇:4.1.2.3)产品零件级别的QFDII
本章目的:介绍产品零件级别的QFDII编写方法. 1.前言 这章接前面部件级别的QFDII. 产品零件级别的QFDII,其实就是将零件QFDII所得到的设计要求,进一步分配零件的特征(Part Cha ...
- LOJ6500. 「雅礼集训 2018 Day2」操作(哈希+差分)
题目链接 https://loj.ac/problem/6500 题解 区间取反 \(01\) 串的经典套路是差分.我们令 \(b_i = a_i\ {\rm xor}\ a_{i - 1}\)(\( ...