springboot+mysql+mybatis+Mybatis-Generator+druid 项目demo

本文主要是介绍springboot+mysql+mybatis+Mybatis-Generator+druid 项目demo,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

springboot+mysql+mybatis+Mybatis-Generator+druid 项目demo

1.使用idea新建项目

2.使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
3.配置application.yml文件
server:port: 8080spring:datasource:driver-class-name: com.mysql.jdbc.Driverurl: jdbc:mysql://127.0.0.1:3306/day01?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTCusername: rootpassword: ......# 使用druid数据源type: com.alibaba.druid.pool.DruidDataSourcemybatis:type-aliases-package: com.example.duowei.mappermapper-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 {@Autowiredprivate 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 {@Autowiredprivate 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 - @mbggeneratedThis 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 - @mbggeneratedThis 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

 

posted @ 2019-04-10 14:40 酸奶加绿茶 阅读( ...) 评论( ...) 编辑 收藏

这篇关于springboot+mysql+mybatis+Mybatis-Generator+druid 项目demo的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1121574

相关文章

Spring Boot 整合 SSE的高级实践(Server-Sent Events)

《SpringBoot整合SSE的高级实践(Server-SentEvents)》SSE(Server-SentEvents)是一种基于HTTP协议的单向通信机制,允许服务器向浏览器持续发送实... 目录1、简述2、Spring Boot 中的SSE实现2.1 添加依赖2.2 实现后端接口2.3 配置超时时

解决Maven项目idea找不到本地仓库jar包问题以及使用mvn install:install-file

《解决Maven项目idea找不到本地仓库jar包问题以及使用mvninstall:install-file》:本文主要介绍解决Maven项目idea找不到本地仓库jar包问题以及使用mvnin... 目录Maven项目idea找不到本地仓库jar包以及使用mvn install:install-file基

Windows 上如果忘记了 MySQL 密码 重置密码的两种方法

《Windows上如果忘记了MySQL密码重置密码的两种方法》:本文主要介绍Windows上如果忘记了MySQL密码重置密码的两种方法,本文通过两种方法结合实例代码给大家介绍的非常详细,感... 目录方法 1:以跳过权限验证模式启动 mysql 并重置密码方法 2:使用 my.ini 文件的临时配置在 Wi

Spring Boot读取配置文件的五种方式小结

《SpringBoot读取配置文件的五种方式小结》SpringBoot提供了灵活多样的方式来读取配置文件,这篇文章为大家介绍了5种常见的读取方式,文中的示例代码简洁易懂,大家可以根据自己的需要进... 目录1. 配置文件位置与加载顺序2. 读取配置文件的方式汇总方式一:使用 @Value 注解读取配置方式二

一文详解Java异常处理你都了解哪些知识

《一文详解Java异常处理你都了解哪些知识》:本文主要介绍Java异常处理的相关资料,包括异常的分类、捕获和处理异常的语法、常见的异常类型以及自定义异常的实现,文中通过代码介绍的非常详细,需要的朋... 目录前言一、什么是异常二、异常的分类2.1 受检异常2.2 非受检异常三、异常处理的语法3.1 try-

Java中的@SneakyThrows注解用法详解

《Java中的@SneakyThrows注解用法详解》:本文主要介绍Java中的@SneakyThrows注解用法的相关资料,Lombok的@SneakyThrows注解简化了Java方法中的异常... 目录前言一、@SneakyThrows 简介1.1 什么是 Lombok?二、@SneakyThrows

Java中字符串转时间与时间转字符串的操作详解

《Java中字符串转时间与时间转字符串的操作详解》Java的java.time包提供了强大的日期和时间处理功能,通过DateTimeFormatter可以轻松地在日期时间对象和字符串之间进行转换,下面... 目录一、字符串转时间(一)使用预定义格式(二)自定义格式二、时间转字符串(一)使用预定义格式(二)自

MySQL重复数据处理的七种高效方法

《MySQL重复数据处理的七种高效方法》你是不是也曾遇到过这样的烦恼:明明系统测试时一切正常,上线后却频频出现重复数据,大批量导数据时,总有那么几条不听话的记录导致整个事务莫名回滚,今天,我就跟大家分... 目录1. 重复数据插入问题分析1.1 问题本质1.2 常见场景图2. 基础解决方案:使用异常捕获3.

Spring 请求之传递 JSON 数据的操作方法

《Spring请求之传递JSON数据的操作方法》JSON就是一种数据格式,有自己的格式和语法,使用文本表示一个对象或数组的信息,因此JSON本质是字符串,主要负责在不同的语言中数据传递和交换,这... 目录jsON 概念JSON 语法JSON 的语法JSON 的两种结构JSON 字符串和 Java 对象互转

SQL中redo log 刷⼊磁盘的常见方法

《SQL中redolog刷⼊磁盘的常见方法》本文主要介绍了SQL中redolog刷⼊磁盘的常见方法,将redolog刷入磁盘的方法确保了数据的持久性和一致性,下面就来具体介绍一下,感兴趣的可以了解... 目录Redo Log 刷入磁盘的方法Redo Log 刷入磁盘的过程代码示例(伪代码)在数据库系统中,r