public JsonResult SubmitOrderHandledPump(int orderHandledId, int recordId, DateTime dataDt, int pumpId) { try { OrderHandledMgr .GetOrderHandled(orderHandledId) .SaveTubeRecord(recordId, dataDt, CurrentUser.Username, pumpId); } catch (Exception ex) { Log.AddLog($"SubmitOrderHandledPump({orderHandledId},{dataDt},{pumpId})", $"{ex.Message}", LogType.Error); return Json(new { status = false, msg = "保存医嘱绑定泵次记录失败" }); } return Json(new { status = true, msg = "" }); }
时间: 2024-02-14 18:32:29 浏览: 24
这段代码是一个C#的控制器方法,通过JSON格式返回一个`JsonResult`对象。该方法名为`SubmitOrderHandledPump`,接受四个参数:`orderHandledId`(订单处理ID),`recordId`(记录ID),`dataDt`(日期时间),以及`pumpId`(泵次ID)。
在方法体内,它首先尝试通过`OrderHandledMgr.GetOrderHandled(orderHandledId)`获取一个订单处理对象,并调用其`SaveTubeRecord(recordId, dataDt, CurrentUser.Username, pumpId)`方法。这个方法可能会抛出异常,如果发生异常,它会将异常信息记录到日志中,并返回一个包含`status`为`false`和`msg`为"保存医嘱绑定泵次记录失败"的匿名对象作为JSON结果。
如果没有发生异常,它将返回一个包含`status`为`true`和空字符串的匿名对象作为JSON结果。
相关问题
public JsonResult Save([FromBody] DianzibingliDbModel entity) { try { Random rd = new Random(); int i = rd.Next(0, 1000000000); entity.Id = DateTime.Now.Ticks / 100000 + i; if (_bll.BaseInsert(entity) > 0) { return Json(new { Code = 0, Msg = "添加成功!" }); } return Json(new { Code = -1, Msg = "添加失败!" }); } catch (Exception ex) { return Json(new { Code = 500, Msg = ex.Message }); } }
这段代码看起来是一个ASP.NET的Web API的控制器方法,接收一个DianzibingliDbModel类型的参数,将其插入到数据库中,并返回一个JsonResult表示操作的结果。其中,Id字段是通过当前时间的Ticks加上一个随机数生成的。如果插入成功,返回Code为0,Msg为"添加成功!",否则返回Code为-1,Msg为"添加失败!"。如果出现异常,返回Code为500,Msg为异常信息。
public JsonResult<String> uploadPicture(@RequestParam("file") MultipartFile multipartFile) throws IOException { String pictureUrl = uploadPictureService.uploadPicture(multipartFile); return new JsonResult<String>(pictureUrl,"200","success"); } } 的JsonResult类怎么写
JsonResult 是一个泛型类,它通常用于返回 JSON 数据格式的响应。在上面的代码片段中,JsonResult 返回一个 String 类型的数据,同时还包括状态码和消息。以下是一个简单的 JsonResult 类的实现:
```java
public class JsonResult<T> {
private int code;
private String message;
private T data;
public JsonResult(T data, int code, String message) {
this.data = data;
this.code = code;
this.message = message;
}
// Getter and Setter methods
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
}
```
这个类有三个属性:code 表示状态码,message 表示消息内容,data 表示返回的数据对象。它还有一个带参数的构造方法,用于设置这三个属性的值。除此之外,还有相应的 getter 和 setter 方法,用于获取和设置属性的值。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)