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

相关文章

springboot控制bean的创建顺序

《springboot控制bean的创建顺序》本文主要介绍了spring-boot控制bean的创建顺序,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随... 目录1、order注解(不一定有效)2、dependsOn注解(有效)3、提前将bean注册为Bea

Java中的ConcurrentBitSet使用小结

《Java中的ConcurrentBitSet使用小结》本文主要介绍了Java中的ConcurrentBitSet使用小结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,... 目录一、核心澄清:Java标准库无内置ConcurrentBitSet二、推荐方案:Eclipse

java中的Supplier接口解析

《java中的Supplier接口解析》Java8引入的Supplier接口是一个无参数函数式接口,通过get()方法延迟计算结果,它适用于按需生成场景,下面就来介绍一下如何使用,感兴趣的可以了解一下... 目录1. 接口定义与核心方法2. 典型使用场景场景1:延迟初始化(Lazy Initializati

Java中ScopeValue的使用小结

《Java中ScopeValue的使用小结》Java21引入的ScopedValue是一种作用域内共享不可变数据的预览API,本文就来详细介绍一下Java中ScopeValue的使用小结,感兴趣的可以... 目录一、Java ScopedValue(作用域值)详解1. 定义与背景2. 核心特性3. 使用方法

spring中Interceptor的使用小结

《spring中Interceptor的使用小结》SpringInterceptor是SpringMVC提供的一种机制,用于在请求处理的不同阶段插入自定义逻辑,通过实现HandlerIntercept... 目录一、Interceptor 的核心概念二、Interceptor 的创建与配置三、拦截器的执行顺

Java中Map的五种遍历方式实现与对比

《Java中Map的五种遍历方式实现与对比》其实Map遍历藏着多种玩法,有的优雅简洁,有的性能拉满,今天咱们盘一盘这些进阶偏基础的遍历方式,告别重复又臃肿的代码,感兴趣的小伙伴可以了解下... 目录一、先搞懂:Map遍历的核心目标二、几种遍历方式的对比1. 传统EntrySet遍历(最通用)2. Lambd

Django调用外部Python程序的完整项目实战

《Django调用外部Python程序的完整项目实战》Django是一个强大的PythonWeb框架,它的设计理念简洁优雅,:本文主要介绍Django调用外部Python程序的完整项目实战,文中通... 目录一、为什么 Django 需要调用外部 python 程序二、三种常见的调用方式方式 1:直接 im

SQL Server 中的表进行行转列场景示例

《SQLServer中的表进行行转列场景示例》本文详细介绍了SQLServer行转列(Pivot)的三种常用写法,包括固定列名、条件聚合和动态列名,文章还提供了实际示例、动态列数处理、性能优化建议... 目录一、常见场景示例二、写法 1:PIVOT(固定列名)三、写法 2:条件聚合(CASE WHEN)四、

Spring Boot 中 RestTemplate 的核心用法指南

《SpringBoot中RestTemplate的核心用法指南》本文详细介绍了RestTemplate的使用,包括基础用法、进阶配置技巧、实战案例以及最佳实践建议,通过一个腾讯地图路线规划的案... 目录一、环境准备二、基础用法全解析1. GET 请求的三种姿势2. POST 请求深度实践三、进阶配置技巧1

springboot+redis实现订单过期(超时取消)功能的方法详解

《springboot+redis实现订单过期(超时取消)功能的方法详解》在SpringBoot中使用Redis实现订单过期(超时取消)功能,有多种成熟方案,本文为大家整理了几个详细方法,文中的示例代... 目录一、Redis键过期回调方案(推荐)1. 配置Redis监听器2. 监听键过期事件3. Redi