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

相关文章

MySQL 多表连接操作方法(INNER JOIN、LEFT JOIN、RIGHT JOIN、FULL OUTER JOIN)

《MySQL多表连接操作方法(INNERJOIN、LEFTJOIN、RIGHTJOIN、FULLOUTERJOIN)》多表连接是一种将两个或多个表中的数据组合在一起的SQL操作,通过连接,... 目录一、 什么是多表连接?二、 mysql 支持的连接类型三、 多表连接的语法四、实战示例 数据准备五、连接的性

MySQL中的分组和多表连接详解

《MySQL中的分组和多表连接详解》:本文主要介绍MySQL中的分组和多表连接的相关操作,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友一起看看吧... 目录mysql中的分组和多表连接一、MySQL的分组(group javascriptby )二、多表连接(表连接会产生大量的数据垃圾)MySQL中的

Java 实用工具类Spring 的 AnnotationUtils详解

《Java实用工具类Spring的AnnotationUtils详解》Spring框架提供了一个强大的注解工具类org.springframework.core.annotation.Annot... 目录前言一、AnnotationUtils 的常用方法二、常见应用场景三、与 JDK 原生注解 API 的

Java controller接口出入参时间序列化转换操作方法(两种)

《Javacontroller接口出入参时间序列化转换操作方法(两种)》:本文主要介绍Javacontroller接口出入参时间序列化转换操作方法,本文给大家列举两种简单方法,感兴趣的朋友一起看... 目录方式一、使用注解方式二、统一配置场景:在controller编写的接口,在前后端交互过程中一般都会涉及

Java中的StringBuilder之如何高效构建字符串

《Java中的StringBuilder之如何高效构建字符串》本文将深入浅出地介绍StringBuilder的使用方法、性能优势以及相关字符串处理技术,结合代码示例帮助读者更好地理解和应用,希望对大家... 目录关键点什么是 StringBuilder?为什么需要 StringBuilder?如何使用 St

使用Java将各种数据写入Excel表格的操作示例

《使用Java将各种数据写入Excel表格的操作示例》在数据处理与管理领域,Excel凭借其强大的功能和广泛的应用,成为了数据存储与展示的重要工具,在Java开发过程中,常常需要将不同类型的数据,本文... 目录前言安装免费Java库1. 写入文本、或数值到 Excel单元格2. 写入数组到 Excel表格

Java并发编程之如何优雅关闭钩子Shutdown Hook

《Java并发编程之如何优雅关闭钩子ShutdownHook》这篇文章主要为大家详细介绍了Java如何实现优雅关闭钩子ShutdownHook,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起... 目录关闭钩子简介关闭钩子应用场景数据库连接实战演示使用关闭钩子的注意事项开源框架中的关闭钩子机制1.

Maven中引入 springboot 相关依赖的方式(最新推荐)

《Maven中引入springboot相关依赖的方式(最新推荐)》:本文主要介绍Maven中引入springboot相关依赖的方式(最新推荐),本文给大家介绍的非常详细,对大家的学习或工作具有... 目录Maven中引入 springboot 相关依赖的方式1. 不使用版本管理(不推荐)2、使用版本管理(推

Java 中的 @SneakyThrows 注解使用方法(简化异常处理的利与弊)

《Java中的@SneakyThrows注解使用方法(简化异常处理的利与弊)》为了简化异常处理,Lombok提供了一个强大的注解@SneakyThrows,本文将详细介绍@SneakyThro... 目录1. @SneakyThrows 简介 1.1 什么是 Lombok?2. @SneakyThrows

MyBatis模糊查询报错:ParserException: not supported.pos 问题解决

《MyBatis模糊查询报错:ParserException:notsupported.pos问题解决》本文主要介绍了MyBatis模糊查询报错:ParserException:notsuppo... 目录问题描述问题根源错误SQL解析逻辑深层原因分析三种解决方案方案一:使用CONCAT函数(推荐)方案二: