• SpringBoot2.+restful风格请求方式设置以及表单中日期格式设置


    ​ 1)、SpringBoot在自动配置很多组件的时候,先看容器中有没有用户自己配置的(@Bean、@Component)如果有就用用户配置的,如果没有,才自动配置;如果有些组件可以有多个(ViewResolver)将用户配置的和自己默认的组合起来;

    ​ 2)、在SpringBoot中会有非常多的xxxConfigurer帮助我们进行扩展配置,会有很多的xxxCustomizer帮助我们进行定制配置


    SpringBoot2.0+默认不支持restful请求,需要在application.properties/yml中设值对应的属性将他打开。

    # 打开put delete请求方式
    spring.mvc.hiddenmethod.filter.enabled=true
    

    打开后还需要在form表单中添加一个input框,对应设置的属性有所要求才能被识别

       <form id="deleteEmpForm" method="post">
              <input type="hidden" value="delete" name="_method">
       </form>
    
    <!--发送put请求springmvc步骤
    1. 配置HideMethodFilter 默认SpringBoot从1.0+就帮我们配置好了
    2. 页面创建post请求方式表单
    3. 创建input name=_method value=put / delete
    -->
    

    因为HideMethodFilter过滤器中已经这样规定了

    public class HiddenHttpMethodFilter extends OncePerRequestFilter {
        private static final List<String> ALLOWED_METHODS;
        public static final String DEFAULT_METHOD_PARAM = "_method";
        private String methodParam = "_method";
    

    如果在提交表单的时候,表单中有日期的格式,需要提前规定

    在SpringBoot配置文件中设置对应日期的格式,才能被识别

    默认SpringBoot的日期格式是 yyyy/MM/dd

    # 设置添加员工的日期格式 默认情况下是yyyy/MM/dd
    spring.mvc.date-format=yyyy-MM-dd
    
    # 禁用缓存
    spring.thymeleaf.cache=false
    
    禁用缓存的操作算是开发中的一种习惯,可以修改页面后直接ctrl+f9 重新编译,然后修改后的结果就会显示,不用再重启服务器
    
  • 相关阅读:
    leetcode Super Ugly Number
    leetcode Find Median from Data Stream
    leetcode Remove Invalid Parentheses
    leetcode Range Sum Query
    leetcode Range Sum Query
    leetcode Minimum Height Trees
    hdu 3836 Equivalent Sets
    hdu 1269 迷宫城堡
    hud 2586 How far away ?
    poj 1330 Nearest Common Ancestors
  • 原文地址:https://www.cnblogs.com/itjiangpo/p/14181424.html
Copyright © 2020-2023  润新知