封装json输出
/**
* 输出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输出的更多相关文章
- Jackson如何使JSON输出变得优雅?
本篇文章翻译自:How to enable pretty print JSON output (Jackson) 在这篇文章中,我们将教你如何利用Jackson Library在控制台或者JSP页面优 ...
- 使用Map List 封装json数据
<dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib</art ...
- Springmvc 配置json输出的几种方式
Spring MVC 3.0 返回JSON数据的几种方法: 1. 直接 PrintWriter 输出 2. 使用 JSP 视图 3. 使用Spring内置的支持 // Spring MVC 配置 &l ...
- 编写JsonResult封装JSON返回值(模板参阅)
编写JsonResult封装JSON返回值 package cn.tedu.note.util; import java.io.Serializable; import cn.tedu.note.se ...
- FastJson/spring boot: json输出方法二
1.引入FastJson依赖包 <!-- FastJson --> <dependency> <groupId>com.alibaba</groupId> ...
- FastJson/spring boot: json输出
1.引入FastJson依赖包 <!-- FastJson --> <dependency> <groupId>com.alibaba</groupId> ...
- SpringBoot之封装json对象返回json数据
/** * @description:封装json对象,所有返回结果都使用它 **/ public class Result<T> { private int code;// 业务自定义状 ...
- jquey ajax 将变量值封装json传入JAVA action获取解析
最近在做一个小小的功能模块,前台有很多的数据需要传入到后台,前台页面设计如下: 看起来不是很清楚,总之表单中的数据都要提交到后台进行处理,然后插入到数据库,而且是一起提交到后台的,实现的方法大致有两种 ...
- python 格式化 json输出
利用python格式化json 字符串输出. $ echo '{"json":"obj"}' | python -m json.tool 利用python -m ...
随机推荐
- C++ 赋值构造函数的返回值到底有什么用?且返回值是否为引用类型有什么区别吗?
首先定义类Person class Person{ public: string name; Person()=default; //默认构造函数 Person(string nam):name(na ...
- apache----------在apache环境下安装https支持
1.安装mod_ssl yum install mod_ssl2.修改阿帕奇的配置文件开启3.防火墙要开启443端口4.要把三个证书上传到阿帕奇配置文件下.5.更新 httpd.conf 配置文件 ...
- react使用create-react-app创建的项目部署
一.在所有的项目代码编写完成后,react项目直接部署是无法正常访问的 1.问题一 网页无法正常的浏览器刷新,刷新会报404错,路由找不到页面 2.问题二 路由跳转后,浏览器后退按钮点击后,页面不刷新 ...
- GIT学习总结--从git上拉取代码到本地
步骤: 1.输入公司的git地址https://git5b.XXXXX.com,回车: 2.在登录框中输入用户名和密码: 3.选取需要的文件下的代码 4.复制该项目的地址 5.在本地的windows命 ...
- c++ 单元测试框架 gmock 深度剖析
c++ 单元测试框架 gmock 深度剖析 随着微服务和CI的流行,在目前的软件工程领域中单元测试可以说是必不可少的一个环节,在TDD中,单元测试更是被提高到了一个新的高度.但是很多公司由于很多不同的 ...
- Tensorflow --BeamSearch
github:https://github.com/zle1992/Seq2Seq-Chatbot 1. 注意在infer阶段,需要需要reuse, 2.If you are using the Be ...
- Vue学习2:模板语法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 利用airbase-ng建立Soft AP
利用airbase-ng建立Soft AP,再利用一些常见工具进行嗅探,或对抓包进行分析是出现比较早的一种MITM攻击方法.网上有很多关于手动实现的文章,也有一些自动实现脚本.这些脚本通常分两类,一类 ...
- 2018-2019-3 网络对抗技术 20165305 Exp3 免杀原理与实践
1.实验内容及步骤 1.1 正确使用msf编码器,msfvenom生成如jar之类的其他文件,veil-evasion,加壳工具,使用shellcode编程 将做实验二时生成的后门文件用virusto ...
- ts --基础类型
声明js的基本类型1.数字let a: number = 2; 2.字符串let aa: string = "22" 3.数组 (1) 数组元素: let b: number[] ...