1、spring boot 中静态资源配置默认路径如下。如果需要扩展只需要子后面加上对应的classpath:/template/之类

 spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/
 

2、nohup java -jar xx.jar & 开启守护现场,防止在idea中使用ctrol+c退出控制台,当前服务进程中断

3、jar 包解压目录

    BOOT-INF
          classes
                  xx.properties
                com.zsq.controller/service/dao...
          lib
                  一系列依赖的jar文件
    
    META-INF(存放了当前服务所用的环境的文件MANIFEST.MF)
                Manifest-Version: 1.0
                Implementation-Title: test-unicom
                Implementation-Version: 1.0-SNAPSHOT
                Start-Class: com.unicom.Application
                Spring-Boot-Classes: BOOT-INF/classes/
                Spring-Boot-Lib: BOOT-INF/lib/
                Build-Jdk-Spec: 1.8
                Spring-Boot-Version: 2.2.2.RELEASE
                Created-By: Maven Archiver 3.4.0
                Main-Class: org.springframework.boot.loader.JarLauncher
    org
    
    

4、json序列化目前jackson相对goson和fastjson好一些,稳定一些。常用注解如下

    @JsonIgnore 返回json串的时候不显示当前字段
    @JsonInclude(JsonInclude.Include.NON_NULL) 如果是空就不显示当前字段
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",locale = "zh",timezone = "GMT-8") 格式换当前时间显示
    @JsonProperty(value = "t") 对显示的字段起别名
    

5、请求参数相关内容。如果请求体是json格式的多参数,建议搭配@RequestBody使用 User user POSTMAN中 选raw ,文本格式选JSON {"title","课程1"},普通的请求例如表单等只需要注意字段名和抽象的实体对象属性保持一致即可

6、常用定一个类为ben的注解方式用@Component\@Configuration

7、开启热部署

pom.xml文件中加入如下:
<!--开启热部署 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional><!--热部署的时候必须加 -->
    </dependency>
    
    <build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <fork>true</fork><!--热部署的时候必须加 -->
            </configuration>
        </plugin>
    </plugins>

</build>
-----------
还需要在idea中打开 compiler.aotuomake.allow.when.app.running  还有compiler.xxx   之后只需要重启idea初始化一下即可生效

8、自定义一个可以在xx.yml中配置常量的实体类所需要的注解

@PropertySource(value = {"classpath:wx.properties"})
@Component
@ConfigurationProperties(prefix = "wx")

如果需要在业务里面使用只需要注入即可;@Autowired WXdomain wxdomian;

9、配置启动类的最优先选择是跟自定义包同级别目录。在类上面加上@SpringBootApplication(他是个组合注解)


it爱吃肉
2 声望0 粉丝