SpringBoot总结
程序员文章站
2024-03-21 23:11:04
...
1 环境变量配置
1.1 JDK安装步骤
1. 找到Jdk的安装路径D:\xxx\xxx\jdk1.8.0_45\bin
2. 配置JAVA_HOME: D:\xxx\xxx\jdk1.8.0_45
3. 配置classpath, %JAVA_HOME%\bin
1.2 检查安装是否正确
java -version (出现版本号,引擎)
2 新的工作空间设置:
1 为了避免编译时耗费大量时间,关闭STS的Validation校验
2 修改新空间的字符集编码 GBK --> UTF-8
3 配置Maven
3.1 设置下载jar包时获取源码
3.2 安装新的maven
3.3 Setting 设置maven的配置文件
3.4 注意检查jdk的配置是否正确(可以使用自己安装的或者STS自己默认自带的)
SpringBoot
pom.xml说明: 坐标作用 讲项目打成 jar/war 为项目的依赖提供了支持
jar 多用于工具项目或通用项目
war 多用于web项目 项目中有页面需要展示
配置文件proprties的说明:
YML配置是有层级的,注意缩进
YML配置中key/value中间必须添加": “空格
YML配置的名称必须是application.yml
SpringBoot中属性赋值方式(三种)
1 @value赋值
先在配置文件中指定相关的key/value
当程序中使用相关属性进行赋值时通过@value(”{xxxx.xxxx}")
YML切换环境:
" — " 用来分割配置环境
spring:
profiles:
acive: prod
spring:
profiles: dev
xxxxx
spring:
profiles: prod
xxxxx
SpringBoot整合mybatis:
1 在pom.xml中添加mybatis依赖
mysql
mysql-connector-java
runtime
<!--引入druid数据源 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.12</version>
</dependency>
<!--spring整合mybatis 暂时 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
2 配置YML文件:
server:
port: 8090
servlet:
context-path: /
spring:
datasource:
#引入druid数据源
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/jtdb?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true
username: root
password: root
#如果数据库密码以0开头 使用:""包裹
mybatis:
#定义别名包 简化查询resultType配置
type-aliases-package: com.jt.pojo
#Mybatis的映射文件路径
mapper-locations: classpath:/mybatis/mappers/*.xml
#开启驼峰映射 字段 属性 对应 去除字段中的"_"之后首字母大写
configuration:
map-underscore-to-camel-case: true
上一篇: 自动化测试框架学习总结