/**
* 输出json
* @param $msg
* @param int $errno
*/
protected function printOutError($msg,$errno = 10099) {
$this->json->setErr($errno, $msg);
$this->json->Send();
} /**
* 输出json
* @param array $out_data
* @param string $msg
*/
protected function printOutSuccess($out_data = [],$msg='操作成功') {
$this->json->setErr(0, $msg);
if ($out_data) {
$this->json->setAttr('data', $out_data);
}
$this->json->Send();
}

具体使用

/**
* 删除订单,已完成的可以删除
*/
public function delOrder() {
if (!$uid = $_POST['uid']) {
$this->printOutError('缺少用户id',10001);
} if (!$order_id = $_POST['order_id']) {
$this->printOutError('缺少订单id',10001);
} $order = M('order');
$order_info = $order->where(['id'=>$order_id,'is_user_del'=>0,'status'=>['gt',0]])->find();
if (!$order_info) {
$this->printOutError('订单不存在,或已删除/取消',10002);
} if ((int)$order_info['status'] !== 4) {
$this->printOutError('订单状态不可删除',10003);
} $edit_data = [
'is_user_del'=> 1
];
$edit_flag = $order->where(['id'=>$order_id])->save($edit_data);
if (!$edit_flag) {
$this->printOutError('操作失败,请重试');
} else {
$this->printOutSuccess();
}
}

清晰明了。

封装json输出的更多相关文章

  1. Jackson如何使JSON输出变得优雅?

    本篇文章翻译自:How to enable pretty print JSON output (Jackson) 在这篇文章中,我们将教你如何利用Jackson Library在控制台或者JSP页面优 ...

  2. 使用Map List 封装json数据

    <dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib</art ...

  3. Springmvc 配置json输出的几种方式

    Spring MVC 3.0 返回JSON数据的几种方法: 1. 直接 PrintWriter 输出 2. 使用 JSP 视图 3. 使用Spring内置的支持 // Spring MVC 配置 &l ...

  4. 编写JsonResult封装JSON返回值(模板参阅)

    编写JsonResult封装JSON返回值 package cn.tedu.note.util; import java.io.Serializable; import cn.tedu.note.se ...

  5. FastJson/spring boot: json输出方法二

    1.引入FastJson依赖包 <!-- FastJson --> <dependency> <groupId>com.alibaba</groupId> ...

  6. FastJson/spring boot: json输出

    1.引入FastJson依赖包 <!-- FastJson --> <dependency> <groupId>com.alibaba</groupId> ...

  7. SpringBoot之封装json对象返回json数据

    /** * @description:封装json对象,所有返回结果都使用它 **/ public class Result<T> { private int code;// 业务自定义状 ...

  8. jquey ajax 将变量值封装json传入JAVA action获取解析

    最近在做一个小小的功能模块,前台有很多的数据需要传入到后台,前台页面设计如下: 看起来不是很清楚,总之表单中的数据都要提交到后台进行处理,然后插入到数据库,而且是一起提交到后台的,实现的方法大致有两种 ...

  9. python 格式化 json输出

    利用python格式化json 字符串输出. $ echo '{"json":"obj"}' | python -m json.tool 利用python -m ...

随机推荐

  1. 3.3.1 MyBatis框架介绍

    MyBatis框架介绍 1. 什么是框架 (1) 框架是偷懒的程序员将代码进行封装, 之后进行重复使用的过程. (2) 框架其实是一个半成品, 以连接数据库为例, 连接数据库使用的驱动, url, 用 ...

  2. linux云计算面试知识汇总,文件共享--vsftpd秘籍

    随着天气的升温快要步入夏天,紧随着面试季来喽,想知道Linux运维面试时都会被问到哪些问题吗?特整理出这些资料给大家参考学习,据说知道全部答案的人,月薪能过万,还不快快码下,以备后用! 今天小编将继续 ...

  3. #WEB安全基础 : HTTP协议 | 0x10 请求和响应报文重点结构及常见头部

    你需要认识一些常见的头部以及了解报文的详细结构 请求报文的请求行 GET/HTTP/1.1 响应报文的响应行 HTTP/1.1 200 OK 想必这些大家都知道了 请求 我访问一个页面 Host // ...

  4. js某一元素在数组中的索引

    第一种:数组遍历 function search(arr,dst){ var i = arr.length; while(i-=1){ if (arr[i] == dst){ return i; } ...

  5. JDK8 BigDecimal API-创建BigDecimal源码浅析三

    第三篇 先介绍以BigInteger为构造参数的构造器 public BigDecimal(BigInteger val) {// 根据BigInteger创建BigDecimal对象 scale = ...

  6. windows 下安装weblogic

    下载weblogic安装文件 https://www.oracle.com/technetwork/middleware/weblogic/downloads/index.html 在目录下, 下载后 ...

  7. C#的抽象类和接口,区别与相似

        一.抽象类:抽象类是特殊的类,只是不能被实例化:除此以外,具有类的其他特性:重要的是抽象类可以包括抽象方法,这是普通类所不能的.抽象方法只能声明于抽象类中,且不包含任何实现,派生类必须覆盖它们 ...

  8. node多人聊天室搭建

    1.采用websocket: 为什么不用ajax的http:在用HTTP发送消息时,必须用一个新的TCP/IP连接.打开和关闭连接需要时间.此 外,因为每次请求都要发送HTTP头,所以传输的数据量也比 ...

  9. luogu P1003 铺地毯

    水题 #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; t ...

  10. [批处理]使用IncrediBuilder加速自动化测试过程

    背景 1.目前单机全部跑完一次测试的时间大概是5个小时 2.7个虚拟机进行分布式执行的时间大概为3.5小时(包含复制.收集日志的时间) 预期 期望通过IncrediBuilder的虚拟进程的功能在单机 ...