SpringBoot-整合MyBatis

news/2024/10/17 16:27:27/

依赖

<!--mybatis-->
<dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.1.1</version>
</dependency>
<!--jdbc-->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--数据库驱动-->
<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><scope>runtime</scope>
</dependency>

application.yml

spring:datasource:driver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTCusername: rootpassword: root
# 整合 mybatis
mybatis:# 别名配置type-aliases-package: org.example.pojo# 映射文件绑定(classpath 代表 java 或 resources 目录)mapper-locations: classpath:mybatis/mapper/*.xml

UserMapper.java

// 声明为 mybatis 的 mapper
@Mapper
// 或者在启动类上使用注解扫描 mapper 包
// @MapperScan("org.example.mapper")
public interface UserMapper {List<User> selectUserList();
}

controller

@RestController
public class UserController {@Autowiredprivate UserMapper userMapper;@GetMapping("/userList")public List<User> getUserList(){return userMapper.selectUserList();}
}

http://www.ppmy.cn/news/1283247.html

相关文章

推特(Twitter)蓝V

点击个人订阅 这里需要一张visa卡才可以订阅&#xff0c;点击获取 订阅成功

rosdep init/update失败(转载)

sudo rosdep init rosdep update 如果你直接成功了&#xff0c;可直接跳过当我没说&#xff08;不过90%的几率你都会失败的啦&#xff09; 由于http://raw.githubusercontent.com这个网址墙的很厉害&#xff0c;大概率你是成功不了的&#xff0c;这里推荐一种本地化安装的方法…

模型树实操

很多时候&#xff0c;数据都是有层级和分类的&#xff0c;使用laravel的Dcat框架&#xff0c;可以快速搭建一个结构清晰、且可以鼠标拖拽排序的后台&#xff1b;先上例子更直观&#xff1a; 这里是Dcat的模型树使用文档&#xff0c;戳一下&#xff1b; 重点注意事项有&#x…

Docker 创建容器

1、创建MySQL5.7 拉取镜像&#xff1a;docker pull mysql:5.7创建容器&#xff1a;docker run -d --name mysql57001 -p 3306:3306 -v D:\DockerImage\QhData\MySql57:/var/lib/mysql -e MYSQL_ROOT_PASSWORD123456 mysql:5.7进入容器&#xff1a;docker exec -it mysql57001 …

为什么市场称SoBit 是铭文跨链赛道真正的龙头?

跨链桥赛道将是铭文市场长期的发展的刚需 在比特币网络中&#xff0c;Ordinals 铭文铸造的铭文总量已经超过了 5100 万枚&#xff0c;并累计费用收入超 5028 BTC。同时&#xff0c;仅 BRC-20 叙事方向的市值&#xff0c;就已经超过了 30 亿美元&#xff0c;并且随着铭文资产种类…

Linux下安装Flume

1 下载Flume Welcome to Apache Flume — Apache Flume 下载1.9.0版本 2 上传服务器并解压安装 3 删除lib目录下的guava-11.0.2.jar &#xff08;如同服务器安装了hadoop&#xff0c;则删除&#xff0c;如没有安装hadoop则保留这个文件&#xff0c;否则无法启动flume&#…

深入了解 Spring Boot 核心特性、注解和 Bean 作用域

Spring Boot 是什么&#xff1f; Spring Boot 是基于 Spring Framework 构建应用程序的框架&#xff0c;Spring Framework 是一个广泛使用的用于构建基于 Java 的企业应用程序的开源框架。Spring Boot 旨在使创建独立的、生产级别的 Spring 应用程序变得容易&#xff0c;您可以…

【FPGA】分享一些FPGA视频图像处理相关的书籍

在做FPGA工程师的这些年&#xff0c;买过好多书&#xff0c;也看过好多书&#xff0c;分享一下。 后续会慢慢的补充书评。 【FPGA】分享一些FPGA入门学习的书籍【FPGA】分享一些FPGA协同MATLAB开发的书籍 【FPGA】分享一些FPGA视频图像处理相关的书籍 【FPGA】分享一些FPGA高速…