封装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 ...
随机推荐
- windows下复制文件报错“文件名对目标文件夹可能过长 。您可以缩短文件名并重试,或者......”
我将一个路径下文件夹复制到另一个路径下时,出现了报错,报错图片如下: 然后查资料发现: 1.文件名长度最大为255个英文字符,其中包括文件扩展名在内.一个汉字相当于两个英文字符.2.文件的全路径名长度 ...
- 关于UR=A的测试
当数据库在nomount,mount或者restricted这类特殊状态下,同时动态监听显示状态为BLOCKED,客户端无法直接连接到实例,此时可通过配置UR=A进行连接.最常见的场景就是10g版本的 ...
- springMVC--XML解析
一 springMVC 入口 web.xml; DispatcherServlet二 初始化过程 1.寻找init(); 查看DispatcherServlet时候时,继承自servlet,肯定有初始 ...
- spring boot 整合 百度ueditor富文本
百度的富文本没有提供Java版本的,只给提供了jsp版本,但是呢spring boot 如果是使用内置tomcat启动的话整合jsp是非常困难得,今天小编给大家带来spring boot整合百度富文本 ...
- WPF线程中获取控件的值和给控件赋值
WPF中使用线程操作控件,按平常的操作方法操作的话会报异常:调用线程无法访问此对象,因为另一个线程拥有该对象.所以我们要使用Dispatcher类的BeginInvoke()与Invoke()方法.B ...
- 安装Oracle Grid的过程中用到的几个小技巧
1.利用文件来模拟块设备 在grid的安装教程中有一步是 provision the disk devices for use with ASM Filter Driver.但是如果我们没有多个磁盘怎 ...
- REST framework---基于类的视图
一.程序设计 1.路由设计 from django.conf.urls import url from django.contrib import admin from app import view ...
- 用一句sql语句更新两个表并可更新对应的字段的值
ACCESS 例子: insert into products (ProNumber,CASNumber,Cnname,Price,Enname,Baozhuang,Pinpai) select Pr ...
- 详解PHP中foreach
foreach有两种语法: 第一种:遍历给定的 数组语句 array_expression 数组.每次循环中,当前单元的值被赋给 $value 并且数组内部的指针向前移一步(因此下一次循环中将会得到下 ...
- BELLMEN-FORD普通
#include <iostream> using namespace std; int m, n, u[100010], v[100010], w[100010];int check;i ...