zoukankan      html  css  js  c++  java
  • WebApi关于配置全局返回Json数据格式时间以及命名小写

    1.直接在Global文件中配置:

    复制代码
      1 var formatters = GlobalConfiguration.Configuration.Formatters;
      2 var jsonFormatter = formatters.JsonFormatter;
      3 var settings = jsonFormatter.SerializerSettings;
      4 settings.Formatting = Newtonsoft.Json.Formatting.Indented;
      5 settings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
      6 settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
    复制代码
    View Code

    image

    image

    2.配置任意的返回格式json和xml

      1config.Formatters.JsonFormatter.MediaTypeMappings.Add(new QueryStringMapping("format", "json", "application/json"));
      2config.Formatters.XmlFormatter.MediaTypeMappings.Add(new QueryStringMapping("format", "xml", "application/xml"));
    View Code

    image

    3.使用Cors跨域框架配置跨域

    image

    3.1在webapi控制器下的配置

    image

  • 相关阅读:
    mybatis plus 执行sql
    springboot 打印 mybatisplus 的sql
    easyexcel 简单使用
    springboot ehcache
    easyexcel 时间转换
    springboot stopwatch
    c# 开机自动启动
    sqlHelper
    DirectX录音
    c# 发邮件
  • 原文地址:https://www.cnblogs.com/shiyh/p/8979099.html
Copyright © 2011-2022 走看看