8月27日 小程序调用接口 | nginx 配置文件上传 | 前后端分离跨域 | 求平均数保留小数

一、Error: Hostname/IP doesn't match certificate's altnames 

https协议是不可以使用ip的,换成域名

二、在使用nginx 在上传文件的时候遇到413 错误 :Request Entity Too Large

原因是nginx限制了上传文件的大小,在nginx中可以配置最大允许的文件大小:

 

打开nginx主配置文件nginx.conf,找到http{},添加
client_max_body_size 50m;

三、Date类型显示时间格式

实体类中加日期格式化注解
@JsonFormat(pattern="yyyy-MM-dd HH:mm")private Date receiveAppTime;

四、前后端分离跨域

   /**
     * 项目可以进行跨域请求。
     * @return
     */
    @Bean
    public WebMvcConfigurer webMvcConfigurer() {
        return new WebMvcConfigurerAdapter() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**").allowedOrigins("*").allowedMethods("*");
            }
        };
    }

五、求平均数保留小数

    private String getAvgScore(List<TopicRating> ratingList){
        int sum = 0 ;
        for (TopicRating topicRating : ratingList) {
            sum = sum + topicRating.getScore();
        }
        
        double r = (double)sum/ratingList.size();
        String str = r+"";
        return str.substring(0, str.indexOf(".")+2);
    }
10
3.3333333333333335
1
3.3

结果就是3.3

原文地址:https://www.cnblogs.com/lyon91/p/9541099.html