springboot+mysql+mybatis+Mybatis-Generator+druid 项目demo
1.使用idea新建项目

2.使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
3.配置application.yml文件
server:
port: 8080 spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/day01?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
username: root
password: ......
# 使用druid数据源
type: com.alibaba.druid.pool.DruidDataSource mybatis:
type-aliases-package: com.example.duowei.mapper
mapper-locations: classpath:mapper/*.xml
4.项目结构

5.各个部分的内容
1.AccountController
package com.example.test.controller; import com.example.test.Service.AccountService;
import com.example.test.entity.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import java.util.List; @RestController
@RequestMapping("")
public class AccountController {
@Autowired
private AccountService accountService; @GetMapping("/select/list")
public List<Account> selectUserList() {
return this.accountService.selectAccountList();
}
}
2.AccountService
package com.example.test.Service; import com.example.test.dao.AccountMapper;
import com.example.test.entity.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import java.util.List; @Service
public class AccountService {
@Autowired
private AccountMapper accountMapper;
public List<Account> selectAccountList() {
return accountMapper.selectAccountList();
}
}
3.AccountMapper
package com.example.test.dao; import com.example.test.entity.Account;
import java.util.List; import org.apache.ibatis.annotations.*; @Mapper
public interface AccountMapper {
/**
* 查詢所有的賬戶信息
* @return
*/
public List<Account> selectAccountList();
}
4.AccountMapper.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.example.test.dao.AccountMapper">
<resultMap id="BaseResultMap" type="com.example.test.entity.Account">
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<constructor>
<idArg column="id" javaType="java.lang.Integer" jdbcType="INTEGER" />
<arg column="USERNAME" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="MONEY" javaType="java.lang.Integer" jdbcType="INTEGER" />
</constructor>
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
-->
id, USERNAME, MONEY
</sql> <select id="selectAccountList" resultMap="BaseResultMap" >
SELECT
<include refid="Base_Column_List" />
FROM `account`
</select>
</mapper>
ok 启动验证

数据库部分比较简单,随便建立一张表就可以。
另外项目已经上传至github,附上链接 https://github.com/Eric-chenjy/springboot-mysql-mybatis-Mybatis-Generator-druid-demo.git
springboot+mysql+mybatis+Mybatis-Generator+druid 项目demo的更多相关文章
- (二、下) springBoot 、maven 、mysql、 mybatis、 通用Mapper、lombok 简单搭建例子 《附项目源码》
接着上篇文章中 继续前进. 一.在maven 的pom.xm中添加组件依赖, mybatis通用Mapper,及分页插件 1.mybatis通用Mapper <!-- mybatis通用Mapp ...
- springBoot+mysql+mybatis demo [基本配置] [遇到的问题]
springBoot+mysql+mybatis的基本配置: 多环境 application.properties spring.profiles.active=dev spring.applicat ...
- 转-spring-boot 注解配置mybatis+druid(新手上路)-http://blog.csdn.net/sinat_36203615/article/details/53759935
spring-boot 注解配置mybatis+druid(新手上路) 转载 2016年12月20日 10:17:17 标签: sprinb-boot / mybatis / druid 10475 ...
- 基于SpringBoot + Mybatis实现SpringMVC Web项目
一.热身 一个现实的场景是:当我们开发一个Web工程时,架构师和开发工程师可能更关心项目技术结构上的设计.而几乎所有结构良好的软件(项目)都使用了分层设计.分层设计是将项目按技术职能分为几个内聚的部分 ...
- SpringBoot系列七:SpringBoot 整合 MyBatis(配置 druid 数据源、配置 MyBatis、事务控制、druid 监控)
1.概念:SpringBoot 整合 MyBatis 2.背景 SpringBoot 得到最终效果是一个简化到极致的 WEB 开发,但是只要牵扯到 WEB 开发,就绝对不可能缺少数据层操作,所有的开发 ...
- SpringBoot + MySQL + MyBatis 整合 Redis 实现缓存操作
本地安装 Redis Redis 安装:https://www.cnblogs.com/oukele/p/11373052.html 项目结构: SpringBootRedis 工程项目结构如下: ...
- 项目脚手架 - 《Spring Boot + MyBatis + MyBatis Generator》
前言 最近启动了一个新的项目发现,每当一个新项目的启动往往需要从头搭建一个"框架",其中虽然很多基础代码可以Copy,但也会浪费不少时间. 基于这个情况,我打算在GitHub上创建 ...
- 【优雅写代码系统】springboot+mybatis+pagehelper+mybatisplus+druid教你如何优雅写代码
目录 spring基本搭建 整合mybatis pom配置 mybatis配置 设置数据源 设置sqlsessionfactory 设置扫描 设置开启事务 资源放行 测试 结果 思考&& ...
- SpringBoot+MySQL,如何整合并使用MyBatis框架
概述 MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集. MyBatis 可以使用简单的 ...
随机推荐
- Nmon实时监控并生成HTML监控报告
前面的博客介绍了服务端监控工具:Nmon使用方法,最近在github找到了一个nmon自动监控并生成HTML格式报告的工具:easyNmon,使用体验蛮不错的,这里介绍下它的安装及使用方法. 一.关于 ...
- 基于jQuery实现简单的js模块化
在多人合作完成网页,经常遇到大家的js代码相互影响的问题.现在有许多模块化的前端框架,应该是可以解决这个问题.但本人并非前端开发人员,那些框架都没用过,只对jQuery相对熟悉,就想用jQuery来解 ...
- 【憩园】C#并发编程之异步编程(一)
写在前面 C#5.0中,对异步编程进行了一次革命性的重构,引入了async和await这两个关键字,使得开发人员在不需要深刻了解异步编程的底层原理,就可以写出十分优美而又代码量极少的代码.如果使用得当 ...
- 借助FreeHttp任意篡改http报文 (使用·实现)
引言 FreeHttp是一个Fiddler插件借助FreeHttp您可按照您自己的设定修改请求或响应报文,这对测试及调试都非常有用 比如您发现线上页面js文件错误,直接使用规则替换新的js文件您可以在 ...
- ExcelPower_Helper插件功能简述与演示
部分功能演示简述: 1.文件目录浏览功能 此功能主要利用了ribbon的dynamicmenu控件,动态呈现自定义目录下的文件列表信息,支持点击打开,查看文件所在目录.功能来源于大神li ...
- 001 java简介
JavaSE(Java Standard Edition):标准版本,定位在个人计算机上的应用.(失败) JavaEE(Java Enterprise Edition):企业版,定位在服务器端的应用. ...
- sonar 匿名内部类写法不推荐
今天sonar扫出一个问题, 是这样说的. 我觉得有点牵强吧. 有点个人情绪在的样子. 那Java设计这种方式干嘛?
- 基于Vue cli生成的Vue项目的webpack4升级
前面的话 本文将详细介绍从webpack3到webpack4的升级过程 概述 相比于webpack3,webpack4可以零配置运行,打包速度比之前提高了90%,可以直接到ES6的代码进行无用代码剔除 ...
- vscode的插件收集
转:https://zhuanlan.zhihu.com/p/27905838 转:https://segmentfault.com/a/1190000006697219
- Python_001_开始学习的一些准备
从Hello World!开始,希望你能坚持一下,然后每一天有一点收获. ♥ 安装了pip和setuotools库: pip用于安装管理Python扩展包,setuptools用于分布Python ...