新建-项目-spring Initializer 如果出现没有启动按钮 右键项目 make directory as -> sources root 如果启动项目直接停止 org.springframework.boot spring-boot-starter-tomcat去掉scope provided
static:保存所有静态资源 如:js、css、images templates:保存所有的模板页面 (spring boot默认jar包 使用嵌入式的tomcat 默认不支持jsp 可以使用模板引擎) application.properties:springboot 默认的配置文件
右键 输入
双击 终端中打开target 执行jar java -jar rx4-0.0.1-SNAPSHOT.jar
compile,缺省值,适用于所有阶段,会打包进项目。 provided,类似compile,期望JDK、容器或使用者会提供这个依赖。 runtime,只在运行时使用,如JDBC驱动,适用运行和测试阶段。 test,只在测试时使用,用于编译和运行测试代码。不会随项目发布。 system,类似provided,需要显式提供包含依赖的jar,Maven不会在Repository中查找它。
使用idea导出war包,在pom.xml中将 war,将spring-boot-starter-tomcat provided 一定设置为provided 将导出的war放到webapps文件夹下面,访问路径加上war包名字
在宝塔中找到终端,cd www 找到jar包所在位置, java -jar rx4-0.0.1-SNAPSHOT.jar --server.port=10086 运行并指定端口号,访问时要指定端口号
k:空格 v 双引号内部不会转义 “hhh\nhhh” 特殊字符保持原来的意思 会换行 单引号内部会转义 特殊字符以普通字符串显示 不会换行
friends: name: zs age: 12 行内写法: friends: {name: xxxx,age: 12}
数组: 用-值表示数组中的一个元素 pets: -cat -dog -pig 行内写法 pets: [cat,dog,pig]
@Component @ConfigurationProperties(prefix = “person”) 添加到类上面
添加依赖
step1:添加依赖 org.mybatis.spring.boot mybatis-spring-boot-starter 2.1.1 mysql mysql-connector-java runtime step2:配置数据库相关信息 spring.datasource.url=jdbc:mysql://localhost:3306/Rx?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai spring.datasource.username=name spring.datasource.password=password
#指定映射路径 mybatis.mapper-locations=classpath:mappers/*.xml step3:设置扫描路径 @MapperScan(“cn.rxxj.rx4.sys.mapper”)//指定扫描路径 放在启动类上 step4:测试 @Autowired DataSource ds; @Test public void testCon() throws Exception{ System.err.println(ds.getConnection()); }//看到连接信息说明成功
法1、将注解@Autowired 改为(@Autowired(required = false)) 法2、file --》seting --》Editor --》Inspections–》spring —》spring core --》code–》Autowiring for Bean Class 的Severity 有Error 改为 Warning 问题解决
1、添加依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency>2、在setting/compiler下勾选Build project automatically 3、ctrl + shift + alt + /,选择Registry,勾选勾上 Compiler autoMake allow when app running