spring boot + mybatis+ mysql环境搭建

2023-05-16

最近在尝试从0开始搭建框架,结果在mybatis这块就踩了很多坑。于是就决定写篇文章记录一下。

要求

尽可能的简单,减少依赖。

实战

新建spring boot项目

基于spring boot 的,所以第一步要创建一下spring boot的项目。创建过程比较简单,网上相关教程也比较多,我就不重点写了。有需要的朋友可以参考我之前写过的文章:
《2020入门教程macOS 使用Intellj IDEA 创建spring boot项目》
https://blog.csdn.net/lxyoucan/article/details/111128415

我的信息如下,随便写一写,仅供参考:
在这里插入图片描述

在这里插入图片描述
项目创建完成以后,启动一下测试一下是否可以正常启动。

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.7.2)

2022-08-08 18:15:58.955  INFO 65101 --- [           main] c.y.s.SpringBootMybatisMysqlApplication  : Starting SpringBootMybatisMysqlApplication using Java 1.8.0_331 on vivobook with PID 65101 (/home/itkey/wisdom/spring-boot-mybatis-mysql/target/classes started by itkey in /home/itkey/wisdom/spring-boot-mybatis-mysql)
2022-08-08 18:15:58.956  INFO 65101 --- [           main] c.y.s.SpringBootMybatisMysqlApplication  : No active profile set, falling back to 1 default profile: "default"
2022-08-08 18:15:59.598  INFO 65101 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2022-08-08 18:15:59.606  INFO 65101 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-08-08 18:15:59.606  INFO 65101 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.65]
2022-08-08 18:15:59.643  INFO 65101 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-08-08 18:15:59.643  INFO 65101 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 651 ms
2022-08-08 18:15:59.867  INFO 65101 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2022-08-08 18:15:59.874  INFO 65101 --- [           main] c.y.s.SpringBootMybatisMysqlApplication  : Started SpringBootMybatisMysqlApplication in 1.247 seconds (JVM running for 6.184)

我这样子的就说明成功启动了。这样我们的基础就搭建好了。

创建mysql数据库

既然研究mybatis,那么怎么能少的了数据库呢?其他数据库也是类似的,这里以mysql为例。

安装mysql数据库

首先你要先安装一下mysql,安装mysql网上教程也不少,本文就不重点说了。
如果供是学习与开发测试,个人比较推荐在docker中安装mysql,安装非常的简单。
以下内容供参考:

  • 《CentOS7安装mysql8笔记》
    https://blog.csdn.net/lxyoucan/article/details/116854446
  • 《CentOS7使用docker跑mysql8笔记》
    https://blog.csdn.net/lxyoucan/article/details/116864619
  • 《alpine linux中docker mysql踩坑记录》
    https://blog.csdn.net/lxyoucan/article/details/123906102

创建数据库

#1. 创建数据库
CREATE DATABASE `ry-vue` CHARACTER SET UTF8;
#2. 选择数据库
use ry-vue;
#3. 设置utf8编码,防止中文乱码(没有中文乱码可以忽略)
set character_set_client=utf8;
set character_set_connection=utf8;
set character_set_database=utf8;
set character_set_results=utf8;

创建表

create table qa_category
(
    category_id bigint auto_increment comment '分类ID'
        primary key,
    title       varchar(200)           not null comment '标题',
    sort        int(5)                 null comment '排序',
    create_by   varchar(64) default '' null comment '创建者',
    create_time datetime               null comment '创建时间',
    update_by   varchar(64) default '' null comment '更新者',
    update_time datetime               null comment '更新时间'
)
    comment '提问分类';

初始化测试数据

INSERT INTO qa_category (title, sort, create_by, create_time, update_by, update_time) VALUES ('Java', 1, 'itkey', '2022-05-09 17:18:50', '', '2022-05-09 17:27:35');
INSERT INTO qa_category (title, sort, create_by, create_time, update_by, update_time) VALUES ('Vue', 2, 'itkey', '2022-05-09 17:19:09', '', '2022-05-09 17:27:35');
INSERT INTO qa_category (title, sort, create_by, create_time, update_by, update_time) VALUES ('React', 3, 'itkey', '2022-05-10 10:46:28', '', '2022-05-10 11:05:27');
INSERT INTO qa_category (title, sort, create_by, create_time, update_by, update_time) VALUES ('mysql', 4, 'itkey', '2022-05-11 14:51:48', '', '2022-05-11 14:51:59');
INSERT INTO qa_category (title, sort, create_by, create_time, update_by, update_time) VALUES ('MacOS', 5, 'itkey', '2022-05-11 14:53:18', '', '2022-05-11 14:53:24');

导此我们的mysql数据库就准备好了。

src目录文件结构

开始之前,先把目录结构放出来,方便理解。
spring-boot-mybatis-mysql/src 文件结构如下:

├── java
│   └── cn
│       └── ycmit
│           └── sbmm
│               ├── controller
│               │   └── TestController.java  //控制类演示
│               ├── domain
│               │   └── QaCategory.java    //实体类 与 qa_category表映射
│               ├── mapper
│               │   └── QaCategoryMapper.java  //mapper类
│               └── SpringBootMybatisMysqlApplication.java //主程序
└── resources
    ├── application.yml    //配置文件
    ├── mapper
    │   └── itkey
    │       └── QaCategoryMapper.xml   //sql配置文件
    ├── mybatis
    │   └── mybatis-config.xml      //全局配置文件
    ├── static
    └── templates

Maven依赖

在spring-boot-mybatis-mysql/pom.xml中增加以下依赖。

     <!-- mybatis -->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.2.2</version>
        </dependency>

        <!-- Mysql驱动包 -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>

如果是其他的数据库,把mysql驱动包修改成你使用的数据库即可。
修改完成以后,一定要不忘记刷新一下。

在这里插入图片描述

application.yml配置

我更喜欢yml配置文件,所以
spring-boot-mybatis-mysql/src/main/resources/application.properties重命名为application.yml

spring:
  #数据源信息
  datasource:
    driverClassName: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&allowMultiQueries=true
    username: root
    password: itkey123456
# MyBatis配置
mybatis:
  # 搜索指定包别名
  typeAliasesPackage: cn.ycmit.**.domain
  # 配置mapper的扫描,找到所有的mapper.xml映射文件
  mapperLocations: classpath*:mapper/**/*Mapper.xml
  # 加载全局的配置文件
  configLocation: classpath:mybatis/mybatis-config.xml

主要就是一个数据源的配置和mybatis的配置。具体意思参考注释的部分。

mybatis-config.xml

创建文件spring-boot-mybatis-mysql/src/main/resources/mybatis/mybatis-config.xml文件的内容如下:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <!-- 全局参数 -->
    <settings>
        <!-- 使全局的映射器启用或禁用缓存 -->
        <setting name="cacheEnabled"             value="true"   />
        <!-- 允许JDBC 支持自动生成主键 -->
        <setting name="useGeneratedKeys"         value="true"   />
        <!-- 配置默认的执行器.SIMPLE就是普通执行器;REUSE执行器会重用预处理语句(prepared statements);BATCH执行器将重用语句并执行批量更新 -->
        <setting name="defaultExecutorType"      value="SIMPLE" />
		<!-- 指定 MyBatis 所用日志的具体实现 -->
        <setting name="logImpl"                  value="SLF4J"  />
        <!-- 使用驼峰命名法转换字段 -->
		<!-- <setting name="mapUnderscoreToCamelCase" value="true"/> -->
	</settings>	
</configuration>

这个文件就是yml中指定的全局的配置文件。

# MyBatis配置
mybatis:
  # 加载全局的配置文件
  configLocation: classpath:mybatis/mybatis-config.xml

实体类

这里以上面的qa_category表为例,创建一个实体类:

spring-boot-mybatis-mysql/src/main/java/cn/ycmit/sbmm/domain/QaCategory.java

内容如下:

package cn.ycmit.sbmm.domain;



import java.util.Date;

/**
 * 问答分类对象 qa_category
 *
 * @author ycmit
 * @date 2022-05-09
 */
public class QaCategory
{
    private static final long serialVersionUID = 1L;

    /** 分类ID */
    private Long categoryId;

    /** 标题 */
    private String title;

    /** 排序 */
    private Integer sort;

    /**
     * 创建者
     */
    private String createBy;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新者
     */
    private String updateBy;

    /**
     * 更新时间
     */
    private Date updateTime;

    public void setCategoryId(Long categoryId)
    {
        this.categoryId = categoryId;
    }

    public Long getCategoryId()
    {
        return categoryId;
    }
    public void setTitle(String title)
    {
        this.title = title;
    }

    public String getTitle()
    {
        return title;
    }
    public void setSort(Integer sort)
    {
        this.sort = sort;
    }

    public Integer getSort()
    {
        return sort;
    }

    public String getCreateBy() {
        return createBy;
    }

    public void setCreateBy(String createBy) {
        this.createBy = createBy;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(String updateBy) {
        this.updateBy = updateBy;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    @Override
    public String toString() {
        return "QaCategory{" +
                "categoryId=" + categoryId +
                ", title='" + title + '\'' +
                ", sort=" + sort +
                ", createBy='" + createBy + '\'' +
                ", createTime=" + createTime +
                ", updateBy='" + updateBy + '\'' +
                ", updateTime=" + updateTime +
                '}';
    }
}

mapper类

创建文件spring-boot-mybatis-mysql/src/main/java/cn/ycmit/sbmm/mapper/QaCategoryMapper.java
内容如下:

package cn.ycmit.sbmm.mapper;

import cn.ycmit.sbmm.domain.QaCategory;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 问答分类Mapper接口
 *
 * @author ycmit
 * @date 2022-05-09
 */
@Mapper
public interface QaCategoryMapper
{
    /**
     * 查询问答分类
     *
     * @param categoryId 问答分类主键
     * @return 问答分类
     */
    public QaCategory selectQaCategoryByCategoryId(Long categoryId);

    /**
     * 查询问答分类列表
     *
     * @param qaCategory 问答分类
     * @return 问答分类集合
     */
    public List<QaCategory> selectQaCategoryList(QaCategory qaCategory);

    /**
     * 新增问答分类
     *
     * @param qaCategory 问答分类
     * @return 结果
     */
    public int insertQaCategory(QaCategory qaCategory);

    /**
     * 修改问答分类
     *
     * @param qaCategory 问答分类
     * @return 结果
     */
    public int updateQaCategory(QaCategory qaCategory);

    /**
     * 删除问答分类
     *
     * @param categoryId 问答分类主键
     * @return 结果
     */
    public int deleteQaCategoryByCategoryId(Long categoryId);

    /**
     * 批量删除问答分类
     *
     * @param categoryIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteQaCategoryByCategoryIds(Long[] categoryIds);
}

这里常用的方法都有了。

mapper配置文件xml

创建文件spring-boot-mybatis-mysql/src/main/resources/mapper/itkey/QaCategoryMapper.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="cn.ycmit.sbmm.mapper.QaCategoryMapper">

    <resultMap type="cn.ycmit.sbmm.domain.QaCategory" id="QaCategoryResult">
        <result property="categoryId"    column="category_id"    />
        <result property="title"    column="title"    />
        <result property="sort"    column="sort"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectQaCategoryVo">
        select category_id, title, sort, create_by, create_time, update_by, update_time from qa_category
    </sql>

    <select id="selectQaCategoryList" parameterType="cn.ycmit.sbmm.domain.QaCategory" resultMap="QaCategoryResult">
        <include refid="selectQaCategoryVo"/>
        <where>
            <if test="title != null  and title != ''"> and title like concat('%', #{title}, '%')</if>
            <if test="sort != null "> and sort = #{sort}</if>
        </where>
    </select>

    <select id="selectQaCategoryByCategoryId" parameterType="Long" resultMap="QaCategoryResult">
        <include refid="selectQaCategoryVo"/>
        where category_id = #{categoryId}
    </select>

    <insert id="insertQaCategory" parameterType="cn.ycmit.sbmm.domain.QaCategory" useGeneratedKeys="true" keyProperty="categoryId">
        insert into qa_category
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="title != null and title != ''">title,</if>
            <if test="sort != null">sort,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="title != null and title != ''">#{title},</if>
            <if test="sort != null">#{sort},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateQaCategory" parameterType="cn.ycmit.sbmm.domain.QaCategory">
        update qa_category
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null and title != ''">title = #{title},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where category_id = #{categoryId}
    </update>

    <delete id="deleteQaCategoryByCategoryId" parameterType="Long">
        delete from qa_category where category_id = #{categoryId}
    </delete>

    <delete id="deleteQaCategoryByCategoryIds" parameterType="String">
        delete from qa_category where category_id in
        <foreach item="categoryId" collection="array" open="(" separator="," close=")">
            #{categoryId}
        </foreach>
    </delete>
</mapper>

这样我们的mybatis版本的CRUD就基本做好了。

查询测试

这里我用一个controller做查询测试。
新建文件spring-boot-mybatis-mysql/src/main/java/cn/ycmit/sbmm/controller/TestController.java
内容如下:

package cn.ycmit.sbmm.controller;

import cn.ycmit.sbmm.domain.QaCategory;
import cn.ycmit.sbmm.mapper.QaCategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class TestController {

    @Autowired
    QaCategoryMapper qaCategoryMapper;

    /**
     * 查询测试
     * @return
     */
    @RequestMapping("/test")
    public List<QaCategory> test()
    {
        QaCategory query = new QaCategory();
        List<QaCategory> result = qaCategoryMapper.selectQaCategoryList(query);
        return result;
    }
}

访问http://localhost:8080/test
返回结果如下:

[{"categoryId":1,"title":"Java","sort":1,"createBy":"itkey","createTime":"2022-05-09T09:18:50.000+00:00","updateBy":"","updateTime":"2022-05-09T09:27:35.000+00:00"},{"categoryId":2,"title":"Vue","sort":2,"createBy":"itkey","createTime":"2022-05-09T09:19:09.000+00:00","updateBy":"","updateTime":"2022-05-09T09:27:35.000+00:00"},{"categoryId":3,"title":"React","sort":3,"createBy":"itkey","createTime":"2022-05-10T02:46:28.000+00:00","updateBy":"","updateTime":"2022-05-10T03:05:27.000+00:00"},{"categoryId":4,"title":"mysql","sort":4,"createBy":"itkey","createTime":"2022-05-11T06:51:48.000+00:00","updateBy":"","updateTime":"2022-05-11T06:51:59.000+00:00"},{"categoryId":5,"title":"MacOS","sort":5,"createBy":"itkey","createTime":"2022-05-11T06:53:18.000+00:00","updateBy":"","updateTime":"2022-05-11T06:53:24.000+00:00"}]

这里我只做了一个查询的测试,其他的操作update delete insert也很简单,用过mybatis的小伙伴已经很熟悉了,本文就不赘述了。

源代码下载

https://download.csdn.net/download/lxyoucan/86353644

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

spring boot + mybatis+ mysql环境搭建 的相关文章

  • ASUS Vivobook安装linux

    使用ASUS Vivobook安装linux 会有一个小坑 如果你的linux启动不起来 xff0c 或者本来可以启动更新固件以后就不行了 这篇文章可能会给你一点帮助 BIOS设置 如果你想在这台电脑上安装linux 则Secure Boo
  • 修复grub启动 因调整分区导致linux无法启动解决过程

    linux调整分区后 xff0c 开机重启时会出现 error unknow filesystem grub rescue gt 我是windows11 43 archlinux双系统使用 这段时间用下来 xff0c 感觉使用linux更多
  • linux 扩容 新增分区

    一开始我只是尝试使用archlinux做为主要办公系统 xff0c 给系统分配的空间并不多 渐渐的也适应了archlinux感觉挺好 于是就把windows中占用的一些空间分配给archlinux用了 记录一下些过程吧 我把windows的
  • VirtualBox调整分分辨率

    以前在windows或者macOS基本都是使用vmware来玩虚拟机的 到linux环境 xff0c 想体验一下VirtualBox 结果用的时间发现分辨率都是调不出来 记录一下我的操作方法 环境 宿主机 xff1a archlinux 4
  • VirtualBox宿主机复制粘贴时有时无

    现象 首先我已经安装了增强功能 xff0c 共享剪切板选择的也是双向 虚拟机刚开机剪切板功能是正常的 可以双向复制 但是用了一段时间以后 xff0c 就会发现从宿主机得到到虚拟机就不行了 但是可以从虚拟机复制到宿主机 环境 我的宿主机是 a
  • HBuilderX运行微信小程序不报错也打不开

    我主用的是linux操作系统 xff0c 因为要开发微信小程序 所以在虚拟机中安装了一个windows7系统 环境 虚拟机中的windows7 HbuilderX 43 微信开发者工具 现象 使用HbuilderX开发uni app并想在微
  • Virtualbox虚拟机与主机相互访问

    刚从vmware切换到Virtualbox有些地方还是不太熟悉 网络连接这块就被卡了一下 xff0c 后来发现其实很简单 xff0c 是我想多了 环境 主机 xff1a archlinux 虚拟机 xff1a windows 10 软件版本
  • maven打包报内存不足,配置maven vm options

    服务器上内存所剩余不多了 xff0c 用mvn打包报内存不足 解决办法就要把vm options中内存设置小一些 mvn jvm config文件 xff1a 从 Maven 3 3 1 43 开始 xff0c 您可以通过 maven pr
  • archlinux滚动更新导致virtualbox虚拟机无法启动

    今天遇到一个奇怪的问题 xff0c 滚动更新以后 xff0c pacman Syyu 虚拟机无法正常启动了 虚拟机启动以后一直显示Starting virtual machine 并且卡在20 不动了 原因分析 我怀疑是更新系统后 xff0
  • 设计模式之【工厂模式】,创建对象原来有这么多玩法

    文章目录 一 什么是工厂模式1 工厂模式的意义2 什么时候应该用工厂模式 二 简单工厂模式1 实例 xff08 1 xff09 使用简单工厂进行优化 xff08 2 xff09 静态工厂 xff08 3 xff09 使用map来去除if x
  • archlinux安装node.js长期支持版本

    默认archlinux安装的node js版本是18 我今天在遇到项目时报错了 xff0c 项目中用到一个组件不支持18 那么如果安装 低版本的Node呢 xff1f 先在软件仓库中搜索一下 xff1a pacman Ss span cla
  • windows开机启动目录

    设置windows开机启动有很多种方法 xff0c 最简单的方法恐怕就是把快捷方式放到启动目录吧 windows开机启动目录 按下 win 43 R 打开运行输入 xff1a shell span class token operator
  • linux 灰度显示grayscale

    之前我在使用macOS的时候 xff0c 非常喜欢使用灰度显示界面 到底是什么原因让我有这么 变态 的需求 下面听听我的故事 xff0c 当时不重要 xff0c 可以跳过 是这样的 xff0c 因为我是程序员 xff0c 算上电脑 43 手
  • charles iOS手机抓包

    iOS手机如何抓包 下载charles https www charlesproxy com latest release download do 注册码 Registered Name span class token builtin c
  • redis cli笔记

    此篇为人个笔记 xff0c 基本是个人常用命令 xff0c 仅供参考 基础操作 redis cli redis span class token number 127 0 span 0 1 637 span class token oper
  • Jsoup通过curl Request设置header

    使用Charles时发现它有一个功能非常的方便 Copy cURL Request菜单 可以把请求中的header信息自动拼接成curl的参数 其实有很多的软件都具备这样的功能 那么如何把这些header信息直接 放到Jsoup的heade
  • 【Java题】用户数据中的身高体重收集

    题目要求 用户数据中的身高体重收集 应用程序中用户数据收集 xff0c 非常重要 xff0c 是大数据重要来源之一 在某APP场景中收集用户的身高体重数据 xff0c 身高单位 米 xff0c 体重单位kg xff0c 要求用户输入的任何数
  • archlinux i3wm通知管理

    通知管理 Dunst 是大多数桌面环境提供的通知守护程序的轻量级替代品 它非常可定制 xff0c 不依赖于任何工具包 xff0c 因此适合那些我们都喜欢定制到完美的以窗口管理器为中心的设置 官网如下 xff1a https dunst pr
  • i3wm 获取window class

    在i3wm中如果你想让一个程序固定在某个workspace中打开可以如下设置 span class token comment 打开virtual box直接进入第10个桌面 span assign span class token pun
  • xrandr修改分辨率与刷新率

    查询当前显示器信息 直接运行xrandr即可 我的执行结果如下 xff0c 信息过多 xff0c 我则把关键部分放出来 xff1a itkey 64 vivobook screenlayout xrandr span class token

随机推荐

  • 设计模式之【适配器模式】,两个人之间确实需要月老的搭线~

    文章目录 一 什么是适配器模式1 适配器模式使用场景2 代理 桥接 装饰器 适配器 4 种设计模式的区别3 适配器模式结构 二 类适配器1 实例 三 对象适配器1 实例 四 接口适配器1 实例 五 源码中的应用 一 什么是适配器模式 适配器
  • linux黑客帝国cmatrix

    装X神器 xff0c 黑客帝国 xff01 xff01 xff01 安装方法 我这里以archlinux为例 span class token function sudo span pacman S cmatrix 效果演示
  • mysql字段userid逗号分开保存按userid查询

    我的sql水平一般 xff0c 仅是一个笔记 无法保存是最优解 仅供参考 场景 有一张消息表 xff0c 其中有一个收信人字段中把多个用户以 分隔保存信息 我需要根据userid来查询信息 为了方便理解 xff0c 我减化一下表结构 我的表
  • windows11 + linux 蓝牙连接问题

    我主要使用Linux办公 xff0c 因为一些特殊情况需要到windows系统下测试 这时就会发现蓝牙键盘就需要重新连接 xff0c 只要切一次系统就要重新连接一次非常的麻烦 今天要多次往返这两个系统 xff0c 所以我决定解决一下这个问题
  • archlinux音量管理

    我用的i3wm 平时音量调整 xff0c 我是直接使用键盘自带的多媒体键实现的 xff0c 所以一直也懒得折腾 多媒体键盘调整音量的缺点就是无法细力度调整 xff0c 导致使用耳机听歌时 xff0c 要么声音听不到 xff0c 要么就是听不
  • git 命令行版本初始化

    假设你已经在网页上创建了一个如下的版本库 http git ycmit cn r manuli api git 然后我们需要把本地已经有的文件上传到版本库 xff0c 执行以下命令即可 span class token function g
  • mysql转SQL Server

    使用工具 Navicat 点击 工具 61 数据传输 即可完成
  • jdbc SQLServer Error: “The server selected protocol version TLS10

    最近在尝试在SQL Server 环境下开发新项目 xff0c 遇到了一些坑 xff0c 记录一下 报错信息 com span class token punctuation span microsoft span class token
  • windows11右键菜单变回windows10风格

    windows11的右键菜单会折叠一部分 xff0c 虽然美观了不少 但是总感觉效率反而更低了 xff0c 能不能设置回windows10风格的呢 xff1f 操作 Windows 43 R xff0c 输入 regedit 并按 Ente
  • C# winform使用SQLite

    本文仅是一个笔记 xff0c 仅供参考 SQLite SQLite是遵守ACID的关系数据库管理系统 xff0c 它包含在一个相对小的C程序库中 与许多其它数据库管理系统不同 xff0c SQLite不是一个客户端 服务器结构的数据库引擎
  • C# SQLite Database Locked exception

    现象 在查询时没有问题 xff0c 但是在Insert时会报数据库被锁定 原因分析 可能是代码某个地方连接着数据库 xff0c 忘记关闭了 解决办法 原理我还没有完全搞懂 xff0c 不过根据下面的写法确实解决了问题 在某个地方 xff0c
  • 设计模式之【桥接模式】,多用组合少用继承

    文章目录 一 什么是桥接模式1 使用场景2 代理 桥接 装饰器 适配器 4 种设计模式的区别3 桥接模式的优缺点4 桥接模式的四种角色 二 实例桥接模式优化代码 三 源码中使用的桥接模式1 桥接模式在JDBC中的应用 一 什么是桥接模式 桥
  • C# 无操作则退出登陆

    span class token keyword using span span class token namespace System span span class token punctuation span span class
  • C#调用explorer.exe打开指定目录

    需求 C 程序上有一个按钮 xff0c 点击打开电脑上对应的目录即可 代码 span class token comment 打开帮助文档 span System span class token punctuation span Diag
  • windows中ncdu替代者TreeSize

    平时开发大部分时间使用linux或者macOS系统 xff0c 近期因为要开发C 程序不得不使用windows系统 在linux或者macOS常用的ncdu来查看文件目录体积大小 到windows中无法使用 xff0c 很不习惯 就想找一个
  • Visual Studio中vim模拟器

    简介 Vim 仿真 这是 Visual Studio 2015 及更高版本的 Vim 仿真层 它将 Vim 熟悉的键绑定体验直接集成到 Visual Studio 的编辑器中 细节 GitHub 上提供了该项目和问题跟踪的完整源代码 htt
  • mybatis小示例

    一般使用mybatis的环境 xff0c 大多都是别人已经配置好的 直接用就好了 xff0c 如何自己搭建呢 xff1f 其实很简单 看官方的文档就可以解决了 主要为了学习mybatis最基础的配置 我文章中的方法不基于spring 一般很
  • spring boot集成mybatis报错 java.lang.IllegalStateException: No supported DataSource type found

    背景 我参考MyBatis Spring的文档搭建环境 https mybatis org spring zh getting started html 完全按文档上操作 xff0c 还是报以下错误 报错信息 Error starting
  • Spring boot mybatis 简单示例

    我在Spring boot中集成mybatis竟然花了不少时间 xff0c 真没想到 对着官网的文档做 xff0c 竟然还花了这么多时间 所以我把过程尽可能的详细记录下来 xff0c 给有需要的朋友 需求 在spring boot 中使用m
  • spring boot + mybatis+ mysql环境搭建

    最近在尝试从0开始搭建框架 xff0c 结果在mybatis这块就踩了很多坑 于是就决定写篇文章记录一下 要求 尽可能的简单 xff0c 减少依赖 实战 新建spring boot项目 基于spring boot 的 xff0c 所以第一步