DemoController.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using Newtonsoft.Json;
  2. using Sers.SersLoader;
  3. using Vit.Core.Util.ComponentModel.Api;
  4. using Vit.Core.Util.ComponentModel.Data;
  5. using Vit.Core.Util.ComponentModel.Model;
  6. namespace Did.SersLoader.HelloWorld.Controllers
  7. {
  8. //站点名称,可多个。若不指定,则从 配置文件中LocalApiService中的"apiStationNames"获取
  9. [SsStationName("demo")]
  10. //路由前缀,可不指定
  11. [SsRoutePrefix("v1")]
  12. public class DemoController : IApiController
  13. {
  14. /// <summary>
  15. /// Demo1-注释
  16. /// </summary>
  17. /// <param name="arg1">arg1注释</param>
  18. /// <returns>ArgModelDesc-returns</returns>
  19. [SsRoute("demo/1")]
  20. //[SsCallerSource(ECallerSource.Internal)]
  21. public ApiReturn<string> Demo1(ArgModel arg1)
  22. {
  23. return new ApiReturn<string>() { data= arg1?.Name };
  24. }
  25. /// <summary>
  26. /// Demo2-注释
  27. /// </summary>
  28. /// <param name="arg1">arg1注释</param>
  29. /// <param name="arg2">arg2注释</param>
  30. /// <returns>是否成功</returns>
  31. [SsRoute("demo/2")]
  32. public ApiReturn Demo2(
  33. [SsExample("example1"), SsDefaultValue("default1")]string arg1,
  34. [SsExample("6"), SsDefaultValue("1")]int arg2)
  35. {
  36. return new ApiReturn();
  37. }
  38. public class ArgModel
  39. {
  40. /// <summary>
  41. /// 用户名
  42. /// </summary>
  43. [SsExample("张三"), SsDefaultValue("未指定")]
  44. [JsonProperty("name")]
  45. public string Name { get; set; }
  46. /// <summary>
  47. /// 年龄
  48. /// </summary>
  49. [SsExample("12"), SsDefaultValue("")]
  50. [JsonProperty("age")]
  51. public int Age { get; set; }
  52. }
  53. }
  54. }