标签:默认 ica addm form 杂类 for hello bsp color
要啥自行车,直接看手表
//返回基元类型 public string Get() { return "hello world"; }
//返回复杂类型 public Person Get() { return new Person {Id = 1, Name = "refuge"}; }
//控制器需要继承 Controller 类 public IActionResult Get() { return Ok("hello world"); }
//控制器需要继承 Controller 类 public IActionResult Get() { return BadRequest("hello world"); }
//控制器需要继承 Controller 类 public IActionResult Get() { return NotFound("什么也没有"); }
ASP.NET Core 默认返回 JSON 格式,但同时也提供了 XML 格式.
//方法一 services.AddMvc().AddXmlSerializerFormatters(); //方法二 //services.AddMvc(options => //{ // options.OutputFormatters.Add(new XmlSerializerOutputFormatter()); //}); //方法三 //services.AddMvc(options => //{ // options.OutputFormatters.Add(new XmlDataContractSerializerOutputFormatter()); //});
官方说这样就可以了,但是不行!!!!!
测试:
public Person Get() { var person = new Person { Id = 1, Name = "refuge" }; return person; }
图就不上了.
必须要打上 [Produces("application/cml")] 才行
[Produces("application/xml")] public Person Get() { var person = new Person { Id = 1, Name = "refuge" }; return person; }
[Produces(...)] 特性可在 Action , Controller 或全局范围内应用.
ASP.NET Core 2.2 基础知识(十四) WebAPI Action返回类型(未完待续)
标签:默认 ica addm form 杂类 for hello bsp color
原文地址:https://www.cnblogs.com/refuge/p/10234781.html