封装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 ...
随机推荐
- Python环境——安装扩展库
一.修改easy_install源 在操作用户家目录添加一个文件 cat >> ~/.pydistutils.cfg <<EOF [easy_install] index-ur ...
- Xamarin.Forms FlexLayout 布局扩展+ 模板扩展+弹性换行
Binding a FlexLayout to a Collection In May we published a doc on the new FlexLayout control that’ ...
- cmd中查看MySQL数据库表数据及结构
0. 1 .cmd进入mysql安装的bin目录(C:\Program Files\XXXXXX\MySQL Server 5.6\bin) mysql -hlocalhost -uroot -p 回 ...
- Maven 学习笔记-maven属性
Maven有六类属性: 1)内置属性 主要有两个常用内置属性 ${basedir}:表示项目根目录,即包含pom.xml文件的目录: ${version}:表示项目版本: 2)POM属性 ${M2_H ...
- 一个比较难忘的BUG
本学期开设了软件测试课程,在课上有讨论到bug,想到bug,真是很令人头疼的东西,相信每个程序都多多少少会有几个头疼的bug. 初学java时写过一个字符串判断的循环,之前学的C++字符类型用“==” ...
- 修改hostname
修改hostname步骤 1. 修改/etc/sysconfig/network中的hostname选项 2. 在/etc/hosts中添加hostname对应的ip地址 3.执行命令:hostnam ...
- hibernate一级缓存及对象的状态
hibernate中实体类对象的状态 在hibernate中实体类对象有三种状态 (1)瞬时态(临时态) 瞬时态:即我们自己创建一个对象,还没有保存到数据库就叫临时态,其实也可以说是对像没有id值,跟 ...
- react16实战总结
实战总结 react实战基础 遇到的一些坑 li里要带key值否则会警告,这个问题在vue中也存在, 考虑到虚拟DOM中diff,所以不要用index作为key值,而要用item. 2.immutab ...
- android 开发设计模式---Builder模式
我们通过一个例子来引出Builder模式.假设有一个Person类,我们通过该Person类来构建一大批人,这个Person类里有很多属性,最常见的比如name,age,weight,height等等 ...
- 淘宝客订单api处理优化
首选我们看看api定义: http://open.taobao.com/api.htm?docId=38078&docType=2&scopeId=14474 注意下span这个参数 ...