发布时间:2026/7/12 20:39:25
SpringBoot 基础篇 SpringBoot概述概述SpringBoot时Spring提供的一个子项目用于快速构建Spring应用程序SpringBoot特性起步依赖、自动配置、其他特性起步依赖本质上就是一个Maven坐标整合完成了一个功能需要的所有坐标自动配置遵循约定大约配置的原则在boot程序启动后一些bean对象会自动注入到ioc容器不需要手动生命简化开发其他特性内嵌的Tomcat、Jettly无需部署WAR文件外部化配置不需要XML配置properties/yml配置文件properties配置文件1.application.propertiesserver.port9090 server.servlet.context-path/start2.application.yml/ application.yamlserver: port: 9191 servlet: context-path: /start2yaml配置文件 书写与获取①第三方技术配置信息②自定义配置信息email: user: 593140521qq.com code: jfejwezhcrzcbbbb host: smtp.qq.com auth: true书写· 值前面必须有空格作为分隔符· 使用空格作为缩进表示层级关系相同的层级左侧对齐获取· Value“${键名})· ConfigurationProperties(prefix 前缀)整合MyBatiscreate database if not exists mybatis; use mybatis; create table user( id int unsigned primary key auto_increment comment ID, name varchar(100) comment 姓名, age tinyint unsigned comment 年龄, gender tinyint unsigned comment 性别, 1:男, 2:女, phone varchar(11) comment 手机号 ) comment 用户表; insert into user(id, name, age, gender, phone) VALUES (null,白眉鹰王,55,1,18800000000); insert into user(id, name, age, gender, phone) VALUES (null,金毛狮王,45,1,18800000001); insert into user(id, name, age, gender, phone) VALUES (null,青翼蝠王,38,1,18800000002); insert into user(id, name, age, gender, phone) VALUES (null,紫衫龙王,42,2,18800000003); insert into user(id, name, age, gender, phone) VALUES (null,光明左使,37,1,18800000004); insert into user(id, name, age, gender, phone) VALUES (null,光明右使,48,1,18800000005);package com.itheima.mybatisquickstart.pojo; public class User { private Integer id; private String name; private Short age; private Short gender; private String phone; public User() { } public User(Integer id, String name, Short age, Short gender, String phone) { this.id id; this.name name; this.age age; this.gender gender; this.phone phone; } public Integer getId() { return id; } public void setId(Integer id) { this.id id; } public String getName() { return name; } public void setName(String name) { this.name name; } public Short getAge() { return age; } public void setAge(Short age) { this.age age; } public Short getGender() { return gender; } public void setGender(Short gender) { this.gender gender; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone phone; } Override public String toString() { return User{ id id , name name \ , age age , gender gender , phone phone \ }; } }Bean管理Bean扫描·标签 context:component-scan base-packagecom.itheima/·注解 ComponentScan(basePackages com.itheima)Bean注册*如果要注册的bean对象来自于第三方不是自定义的无法用Conponent 及衍生注解生命bean的·Bean如果要注册第三方bean建议在配置类中集中注册·Import导入 配置类导入 ImportSelector 接口实现类EnableXxxx注解封装Import注解注册条件SpringBoot提供了设置注册生效条件的注解Conditional自动配置管理自动配置原理①在主启动类上添加了SpringBootApplication注解这个注解组合了EnableAutoCongfiguration注解②EnableAutoCongfiguration注解又组合了Import注解导入了AutoCongfigurationImportSelector类③实现selectImprots方法这个方法经过层层调用最终会读取META-INF目录下的后缀名为imorts的文件自定义starter需求自定义mybatis的starter步骤·创建 dmybatis-spring-boot-autoconfigure模块提供自动配置功能并自定义配置文件META-INF/spring/xxx.imports·创建dmybatis-spring-boot-starter模块在starter中引入自动配置模块1.创建autoconfigure模块编写自动配置类Configuration public class CommonConfig { // 示例根据配置文件条件注册 Bean Bean ConditionalOnProperty(prefix country, name {name, system}) public Country country(Value(${country.name}) String name, Value(${country.system}) String system) { return new Country(name, system); } Bean public Province province() { return new Province(); } }2.创建自动配置入口类AutoConfiguration Import(CommonConfig.class) public class CommonAutoConfig { }3.配置自动配置加载文件cn.itcast.config.CommonAutoConfig4.创建starter模块引入autoconfigure依赖dependency groupIdcn.itcast/groupId artifactIddmybatis-spring-boot-autoconfigure/artifactId version1.0.0/version /dependency

相关新闻

2026/7/12 20:39:25

SegFormer技术选型指南:从理论到实践的完整决策框架

SegFormer技术选型指南:从理论到实践的完整决策框架 【免费下载链接】SegFormer Official PyTorch implementation of SegFormer 项目地址: https://gitcode.com/gh_mirrors/se/SegFormer 在语义分割领域,技术决策者面临的核心挑战是如何在精度、…

2026/7/12 20:39:25

AIGC(生成式AI)试用 52 -- Python IDLE扩展

为Python IDEL添加AI扩展。 日常Python开发,小程序居多:1)单个或多个文件;2)单个文件代码不越过1000行。 因此更多的时间开发,或者说更愿意使用Python原生的IDEL(Integrated Development and L…

2026/7/12 20:39:25

苍穹外卖day12

关于新增菜品的完整开发 逻辑首先控制层 RestController RequestMapping("/admin/dish") Api(tags"菜品相关接口") Slf4jpublic class DishController {Autowiredprivate DishService dishService;/*** 新增菜品* param dishDTO* return*/PostMappingApiO…

2026/7/12 21:59:40

如何5分钟掌握Pyvis:Python交互式网络可视化的终极指南

如何5分钟掌握Pyvis:Python交互式网络可视化的终极指南 【免费下载链接】pyvis Python package for creating and visualizing interactive network graphs. 项目地址: https://gitcode.com/gh_mirrors/py/pyvis 你是否曾经面对复杂的社交网络、知识图谱或系…

2026/7/12 21:59:40

OpenTelemetry-proto路线图解析:未来发展方向与社区规划

OpenTelemetry-proto路线图解析:未来发展方向与社区规划 【免费下载链接】opentelemetry-proto OpenTelemetry protocol (OTLP) specification and Protobuf definitions 项目地址: https://gitcode.com/gh_mirrors/op/opentelemetry-proto OpenTelemetry-pr…

2026/7/12 21:59:40

深度解析:Silent-Face-Anti-Spoofing静默活体检测实战指南

深度解析:Silent-Face-Anti-Spoofing静默活体检测实战指南 【免费下载链接】Silent-Face-Anti-Spoofing 静默活体检测(Silent-Face-Anti-Spoofing) 项目地址: https://gitcode.com/gh_mirrors/si/Silent-Face-Anti-Spoofing 在当前数字…

2026/7/12 21:59:40

超简单!led-name-badge-ls32在Linux系统的安装与配置指南

超简单!led-name-badge-ls32在Linux系统的安装与配置指南 【免费下载链接】led-name-badge-ls32 Upload tool for an led name tag with USB-HID interface 项目地址: https://gitcode.com/gh_mirrors/led/led-name-badge-ls32 led-name-badge-ls32是一款专为…

2026/7/12 21:59:40

telegram-purple开发者入门:如何为Libpurple插件贡献代码

telegram-purple开发者入门:如何为Libpurple插件贡献代码 【免费下载链接】telegram-purple Adds support for Telegram to Pidgin, Adium, Finch and other Libpurple based messengers. 项目地址: https://gitcode.com/gh_mirrors/te/telegram-purple tele…

2026/7/12 21:54:40

MediaCrawler:5分钟搭建跨平台数据采集系统的终极指南

MediaCrawler:5分钟搭建跨平台数据采集系统的终极指南 【免费下载链接】MediaCrawler 项目地址: https://gitcode.com/GitHub_Trending/mediacr/MediaCrawler 你是不是在为收集小红书、抖音、微博、B站、快手等主流社交媒体数据而烦恼?每个平台都…

2026/7/12 0:01:29

3步解锁音乐自由:ncmdumpGUI终极NCM文件解密转换指南

3步解锁音乐自由:ncmdumpGUI终极NCM文件解密转换指南 【免费下载链接】ncmdumpGUI C#版本网易云音乐ncm文件格式转换,Windows图形界面版本 项目地址: https://gitcode.com/gh_mirrors/nc/ncmdumpGUI 你是否曾在网易云音乐下载了心爱的歌曲&#…

2026/7/12 0:01:29

CANoe 19 SP3 配置 GB/T 27930-2023 A类系统:3步搭建BMS仿真测试环境

CANoe 19 SP3 配置 GB/T 27930-2023 A类系统:3步搭建BMS仿真测试环境随着新能源汽车行业的快速发展,充电通信协议的标准化和测试验证变得尤为重要。GB/T 27930-2023作为中国智能充电协议的最新版本,对充电机与电动汽车之间的通信提出了更严格…

2026/7/12 0:01:29

3步搞定RTL8852BE驱动:从零开始配置Wi-Fi 6网卡

3步搞定RTL8852BE驱动:从零开始配置Wi-Fi 6网卡 【免费下载链接】rtl8852be Realtek Linux WLAN Driver for RTL8852BE 项目地址: https://gitcode.com/gh_mirrors/rt/rtl8852be 还在为Linux系统无法识别RTL8852BE Wi-Fi 6网卡而烦恼吗?&#x1f…

2026/7/12 0:01:29

3步解锁音乐自由:ncmdumpGUI终极NCM文件解密转换指南

3步解锁音乐自由:ncmdumpGUI终极NCM文件解密转换指南 【免费下载链接】ncmdumpGUI C#版本网易云音乐ncm文件格式转换,Windows图形界面版本 项目地址: https://gitcode.com/gh_mirrors/nc/ncmdumpGUI 你是否曾在网易云音乐下载了心爱的歌曲&#…

2026/7/12 0:01:29

CANoe 19 SP3 配置 GB/T 27930-2023 A类系统:3步搭建BMS仿真测试环境

CANoe 19 SP3 配置 GB/T 27930-2023 A类系统:3步搭建BMS仿真测试环境随着新能源汽车行业的快速发展,充电通信协议的标准化和测试验证变得尤为重要。GB/T 27930-2023作为中国智能充电协议的最新版本,对充电机与电动汽车之间的通信提出了更严格…

2026/7/12 0:01:29

3步搞定RTL8852BE驱动:从零开始配置Wi-Fi 6网卡

3步搞定RTL8852BE驱动:从零开始配置Wi-Fi 6网卡 【免费下载链接】rtl8852be Realtek Linux WLAN Driver for RTL8852BE 项目地址: https://gitcode.com/gh_mirrors/rt/rtl8852be 还在为Linux系统无法识别RTL8852BE Wi-Fi 6网卡而烦恼吗?&#x1f…

2026/7/12 11:21:32

3个高效策略:快速掌握Axure中文界面配置

3个高效策略:快速掌握Axure中文界面配置 【免费下载链接】axure-cn Chinese language file for Axure RP. Axure RP 简体中文语言包。支持 Axure 11、10、9。不定期更新。 项目地址: https://gitcode.com/gh_mirrors/ax/axure-cn 还在为Axure RP的英文界面感…