abp api返回自定义结构体

abp常规返回的结构体是经过封装后,结构如下

{
    "result": {
        "ok": true,
        "msg": "sucess",
        "data": "123"
    },
    "targetUrl": null,
    "success": true,
    "error": null,
    "unAuthorizedRequest": false,
    "__abp": true
}

但有时需要 获取干净的返回,不需要什么封装。这时我可以再Controller和Action上添加[DontWrapResult],屏蔽封装。

        [HttpPost]
        [DontWrapResult]
        public async Task<dynamic> GetSNBloodSugarReturnStateAsync() {
            try
            { 
                    if (true)
                    {
                        return new { statusCode = "00", desc = "成功" };
                    }
                    else
                    {
                        return new { statusCode = "03", desc = "失败" };
                    } 

            }
            catch (Exception e)
            {
                return Json(new { statusCode = "03", desc = e.Message });
            }
            
        }

返回的结构体就是自己自定义的结构体

{
    "statusCode": "00",
    "desc": "成功"
}

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
ABP框架提供了通用的增删查改(CRUD)操作,如果需要自定义操作,可以按照以下步骤进行: 1. 定义定义服务方法 在应用服务接口中定义定义方法,例如: ```csharp public interface IStudentAppService : IApplicationService { Task<ListResultDto<StudentDto>> GetAllStudents(); Task<StudentDto> GetStudentById(int id); Task CreateStudent(CreateStudentInput input); Task UpdateStudent(UpdateStudentInput input); Task DeleteStudent(int id); Task MyCustomMethod(MyCustomMethodInput input); } ``` 其中,MyCustomMethod 为自定义方法。 2. 实现自定义服务方法 在应用服务实现类中实现自定义方法,例如: ```csharp public class StudentAppService : ApplicationService, IStudentAppService { private readonly IRepository<Student> _studentRepository; public StudentAppService(IRepository<Student> studentRepository) { _studentRepository = studentRepository; } public async Task<ListResultDto<StudentDto>> GetAllStudents() { var students = await _studentRepository.GetAllListAsync(); return new ListResultDto<StudentDto>(ObjectMapper.Map<List<StudentDto>>(students)); } public async Task<StudentDto> GetStudentById(int id) { var student = await _studentRepository.GetAsync(id); return ObjectMapper.Map<StudentDto>(student); } public async Task CreateStudent(CreateStudentInput input) { var student = ObjectMapper.Map<Student>(input); await _studentRepository.InsertAsync(student); } public async Task UpdateStudent(UpdateStudentInput input) { var student = await _studentRepository.GetAsync(input.Id); ObjectMapper.Map(input, student); } public async Task DeleteStudent(int id) { await _studentRepository.DeleteAsync(id); } public async Task MyCustomMethod(MyCustomMethodInput input) { // 实现自定义方法 } } ``` 其中,MyCustomMethod 实现自定义方法的逻辑。 3. 在前端代码中调用自定义服务方法 在前端代码中调用自定义服务方法,例如: ```javascript abp.services.app.student.myCustomMethod(input).done(function (result) { // 处理自定义方法的返回结果 }); ``` 其中,input 为传递给自定义方法的参数。 通过以上步骤,即可完成自定义增删查改操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

香煎三文鱼

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值