Spring Boot2 核心功能
Spring Boot2 核心功能
1、文件类型
1、1 properties
yml
控制台输出
单引号会将\n作为字符串输出
双引号会换行输出
单引号会转义,双引号不会转义
person:
userName: "zhangsan \n 李四"
boss: true
birth: 2019/12/09
age: 21
# interests: [篮球,足球]
interests:
- 篮球
- 足球
animal: [阿猫,阿狗]
# score:
# english: 80
# math: 90
score: {english:80,math:90}
salarys:
- 99999.8
- 99999.9
pet:
name: 阿狗
weight: 99.99
allPets:
sick:
- {name: 阿狗,weight: 99.99}
- name: 阿猫
weight: 88.88
- name: 啊虫
weight: 11.11
health:
- {name: 阿花,weight: 199.99}
- {name: 阿明,weight: 199.98}
//在templates目录下的所有页面,只能通过controller来跳转
直接导入场景,导入包会报错
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
Thymeleaf语法
$@
:国际化
$:文本
@:地址
定义组件
<nav class="col-md-2 d-none d-md-block bg-light sidebar" th:fragment="sidebar">
插入组件
页面路径+哪个组件
<div th:insert="~{dashboard::sidebar}"></div>
<div class="form-group">
<label>department</label>
<select class="form-control" name="department.id">
<option th:each="department:${departments}" th:text="${department.getDepartmentName()}" th:value="${department.getId()}">1</option>
</select>
</div>
自定义Favicon
网页的ico
ctrl+shift+r:清除缓存
2022/3/28
- JDBC
- Mybatis
- Druid
- Shiro:安全
- Spring Security:安全
- 异步任务 :(邮件发送,定时任务)
- Swagger:前后端交接文档技术
- Dubbo+Zookeeper(难点)
Data
对于数据访问,无论是关系型或者非关系型数据库
Spring Boot都是采用Spring Data进行统一管理
整合MyBatis
@Mapper
@Mapper是mybatis的注解,标注在dao层接口上,可以通过动态代理生成接口的实例bean,启动类不需要添加@MapperScan包扫描
@Repository是spring的注解,也标注在dao层接口上,启动类需要加@MapperScan包扫描,生成对应的bean,加了@MapperScan就相当于给包中的接口都加上了@Mapper,同时@Repository还有消除“注入”的错误提示的作用
有错误提示的就是没加@Repository,这是因为spring的自动扫描,而@Mapper不是spring的注解,所以有无法注入的提示。但是这个影响不大,有@Mapper或@MapperScan就可以生成bean。
以前的时候是在mapper层下面有个impl要实现接口方法
如:
public List<User> findAll() throws IOException {
InputStream resourceAsStream = Resources.getResourceAsStream("sqlMapConfig.xml");
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
SqlSession sqlSession = sqlSessionFactory.openSession();
List<User> userList = sqlSession.selectList("userMapper.findAll");
return userList;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律