封装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 ...
随机推荐
- 详解iBaits中SqlMapClientTemplate的使用
Apache iBatis(现已迁至Google Code下发展,更名为MyBatis)是当前IT项目中使用很广泛的一个半自动ORM框架,区别于Hibernate之类的全自动框架,iBatis对数据库 ...
- CDI services--Event(事件)
Cdi中的event事件,是整个CDI的精华所在之一.其有点类似设计模式中的观察者模式.但也有不同的地方.如下3点: 不仅是生产者(producers)从观察者(observers)解耦.观察者也从生 ...
- spider随机请求头和ip
#创建爬虫 scrapy genspider randomIp_spider "taobao.com" #把需要请求的url放到一个混淆的url请求list中去,避免被监测到总是访 ...
- qt 画多边形(实现鼠标拖动节点)
---恢复内容开始--- 2018-01-06 这个小例子实现了移动鼠标,鼠标的坐标信息跟随鼠标移动,多边形的实现,鼠标点击可以拖动多边形点的位置,(其中有个问题?我在QMainWindow下,用mo ...
- PHP菜鸟如何开始学习PHP语言
把我自己学习PHP的经验分享出来,既给想学习PHP的朋友提供一个思路,也算是整理一下自己的思路,好给后续的教程开个头吧~ 学习其实也是有方法的,举个例子:在您上学期间,班里一定有学霸,也有学渣,也有普 ...
- Json数据产生树形结构
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...
- h5页面实战——与andriod和ios的交互
首先需要我们h5页面需要做一些匹配.比如:如何判断当前手机是andriod还是ios, andriod攻城狮和ios工程师,一般会定义事件的方法.我们套用他们方法就可以了. 那么为什么我要写这个随笔呢 ...
- DataGridView 列排序 内存表查找
DataRow[] drow = dt.Select("列名 = 列名的值" ); 就这句话,dt是一个datatable 且断点调试时能看到里面有trade这个列,可为什么执行到 ...
- 如何在linux上查看tomcat的端口号
1.先到tomcat配置文件查看tomcat的端口是什么,配置文件一般是:$CATALINA_HOME/conf/server这个文件,查找<Connector port="8080& ...
- 简单快速部署nexus3私服
本文适用范围:用户规模不大,不需要考虑maven仓库负载均衡的群体. 为何部署nexus3 之前由于懒某些原因,所有开发人员自己定义.m2的settings,大多使用ali提供的maven仓库,但是最 ...