举例: A,B类
public class A { public int id {get;set;} public string name {get;set;} public string phone {get;set;} } public class B { public int age {get;set;} public string sex {get;set;} } public class AB { public A a {get;set;} public B b {get;set;} public AB(A _a, B _b) { a = _a; b = _b; } } //在controller控制器里面 [HttpGet] public AB Get() { AB ab = new AB("假设这里传入a的数据","假设这里传入b的数据") return ab; }
如果swagger 报错,如下修改
[HttpGet] public IActionResult Get() { AB ab = new AB("假设这里是a的数据","假设这里是b的数据") return new JsonResult(ab ); } //如果你自定义封装了一套返回结果规范 "MyResponseResultOk" [HttpGet] public IActionResult Get() { AB ab = new AB("假设这里是a的数据","假设这里是b的数据") return new JsonResult(MyResponseResultOk(ab)); }
标签:webapi,core,asp,get,set,new,ab,public,AB From: https://www.cnblogs.com/tlfe/p/18427499