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的更多相关文章

  1. (二、下) springBoot 、maven 、mysql、 mybatis、 通用Mapper、lombok 简单搭建例子 《附项目源码》

    接着上篇文章中 继续前进. 一.在maven 的pom.xm中添加组件依赖, mybatis通用Mapper,及分页插件 1.mybatis通用Mapper <!-- mybatis通用Mapp ...

  2. springBoot+mysql+mybatis demo [基本配置] [遇到的问题]

    springBoot+mysql+mybatis的基本配置: 多环境 application.properties spring.profiles.active=dev spring.applicat ...

  3. 转-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 ...

  4. 基于SpringBoot + Mybatis实现SpringMVC Web项目

    一.热身 一个现实的场景是:当我们开发一个Web工程时,架构师和开发工程师可能更关心项目技术结构上的设计.而几乎所有结构良好的软件(项目)都使用了分层设计.分层设计是将项目按技术职能分为几个内聚的部分 ...

  5. SpringBoot系列七:SpringBoot 整合 MyBatis(配置 druid 数据源、配置 MyBatis、事务控制、druid 监控)

    1.概念:SpringBoot 整合 MyBatis 2.背景 SpringBoot 得到最终效果是一个简化到极致的 WEB 开发,但是只要牵扯到 WEB 开发,就绝对不可能缺少数据层操作,所有的开发 ...

  6. SpringBoot + MySQL + MyBatis 整合 Redis 实现缓存操作

    本地安装 Redis Redis 安装:https://www.cnblogs.com/oukele/p/11373052.html 项目结构:  SpringBootRedis 工程项目结构如下: ...

  7. 项目脚手架 - 《Spring Boot + MyBatis + MyBatis Generator》

    前言 最近启动了一个新的项目发现,每当一个新项目的启动往往需要从头搭建一个"框架",其中虽然很多基础代码可以Copy,但也会浪费不少时间. 基于这个情况,我打算在GitHub上创建 ...

  8. 【优雅写代码系统】springboot+mybatis+pagehelper+mybatisplus+druid教你如何优雅写代码

    目录 spring基本搭建 整合mybatis pom配置 mybatis配置 设置数据源 设置sqlsessionfactory 设置扫描 设置开启事务 资源放行 测试 结果 思考&& ...

  9. SpringBoot+MySQL,如何整合并使用MyBatis框架

    概述 MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集. MyBatis 可以使用简单的 ...

随机推荐

  1. Login Verification CodeForces - 928A (实现)

    When registering in a social network, users are allowed to create their own convenient login to make ...

  2. 开发日记:JsonCSharpHelp

    using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Newtonsoft.Json.Converters; public static c ...

  3. [转帖]EXPDP dumpfile和parallel的关系

    http://blog.itpub.net/28602568/viewspace-2133375/ 转帖 EXPDP 里面 parallel 与 dumpfile 里面的文件数的关系. 但是我这里有一 ...

  4. Linux(Ubunt)使用日记------常用软件汇总(不定时更新)

    整理总结日常Ubuntu中使用的一些软件,事实证明使用Linux真的会让人的欲望变小有个能用的就不错啦,不要调三捡四 解压类 Unzip | unzip -O CP936 files Unrar ra ...

  5. windows常用快捷键和指令

    快捷键: Ctrl+鼠标滚轮:更改图标大小(桌面).缩放(开始屏幕) Ctrl+A:选择所有 Ctrl+C:复制 Ctrl+E:选择搜索框(资源管理器) Ctrl+N:新窗口(资源管理器) Ctrl+ ...

  6. Delphi 获取DataSet传入参数后的SQL命令

    ClientDataSet1.CommandText := sSQL;   ClientDataSet1.Params.Clear; ClientDataSet1.CommandText :='SEL ...

  7. StringBuilder的常用方法

    转自:https://www.cnblogs.com/jack-Leo/p/6684447.html 在程序开发过程中,我们常常碰到字符串连接的情况,方便和直接的方式是通过"+"符 ...

  8. ASP.NET Core OData now Available

    It looks great! https://devblogs.microsoft.com/odata/asp-net-core-odata-now-available/

  9. 北京2018网络赛A题

    题意:给你一个迷宫,迷宫有开始节点和结束节点,问你从开始走到结束的最小时间,其中,#代表这个点有毒气,身上必须带着氧气瓶才行,B代表每次进入这个点可以带一个氧气瓶,最多身上带五个,P代表进入这个点加速 ...

  10. [BZOJ 3227] [SDOI 2008] 红黑树(tree)

    Description 红黑树是一类特殊的二叉搜索树,其中每个结点被染成红色或黑色.若将二叉搜索树结点中的空指针看作是指向一个空结点,则称这类空结点为二叉搜索树的前端结点.并规定所有前端结点的高度为- ...