抛异常给前端的方式

摘要:
1publicclassContentController{@AutowiredprivateContentServicecontentService;@RequestMapping(“/list/{contentCategoryId}”)@ResponseBodypublicTaotaoResultgetContentList(@PathVariableLongcontentCategoryId

1

public class ContentController {

    @Autowired
    private ContentService contentService;
    
    @RequestMapping("/list/{contentCategoryId}")
    @ResponseBody
    public TaotaoResult getContentList(@PathVariable Long contentCategoryId) {
        try {
            List<TbContent> list = contentService.getContentList(contentCategoryId);
            return TaotaoResult.ok(list);
        } catch (Exception e) {
            e.printStackTrace();
            return TaotaoResult.build(500, ExceptionUtil.getStackTrace(e));
        }
    }
}
package com.taotao.common.utils;

import java.io.PrintWriter;
import java.io.StringWriter;

public class ExceptionUtil {

    /**
     * 获取异常的堆栈信息
     * 
     * @param t
     * @return
     */
    public static String getStackTrace(Throwable t) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);

        try {
            t.printStackTrace(pw);
            return sw.toString();
        } finally {
            pw.close();
        }
    }
}

免责声明:文章转载自《抛异常给前端的方式》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇jquery 的 ajax 传输 数组 ,但后台无法获取的 原因 与 解决 办法MySQL 当前时间,今日时间,前日时间 详解下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

storm实时计算实例(socket实时接入)

介绍 实现了一个简单的从实时日志文件监听,写入socket服务器,再接入Storm计算的一个流程。 源码 日志监听实时写入socket服务器   [java] view plain copy  package socket;      import java.io.BufferedReader;   import java.io.File;...

将 java 改写成 beanshell 的经验之谈

下面经验仅仅针对 bsh for android 而谈, PC 上 beanshell 无需这样改。 public class TimeTest  改写为闭包: TimeTest()  闭包末尾添加语句 return this; public static void main(String[] args) 改写为: run() 最后添加 timet...

MongoDB基础入门003--使用官方驱动操作mongo,C#

本篇先简单介绍一下,使用官方驱动来操作MongoDB。至于MongoDB原生的增删改查语句,且等以后再慢慢学习。 一、操作MongoDB的驱动主要有两个   1.官方驱动:https://github.com/mongodb/mongo-csharp-driver/downloads,更新的还是比较及时的,目前已经支持大部门linq语法。   2.samu...

java 基本理论知识点

http://www.cnblogs.com/hellokitty1/p/4491808.html 1、main方法是怎么写的        public static void main(String [] args){}//最习惯的      public static void main(String  args[]){}      static p...

java socket 实现多个一对一聊天

此程序能够实现同一网络下多个一对一聊天,必须服务器先启动 ,然后客户端启动并且服务器ip要填正确,并且每个客户端的自身编号必须唯一。 服务器端: packagecn.com.test09; importjava.io.DataInputStream; importjava.io.DataOutputStream; importjava.io.IOExce...

Android 播放视频并获取指定时间的帧画面

最近做的项目要求既能播放视频(类似于视频播放器),又能每隔1s左右获取一帧视频画面,然后对图片进行处理,调查了一周,也被折磨了一周,总算找到了大致符合要求的方法。首先对调查过程中涉及到的方法进行简单介绍,再重点介绍最终所采用的方法,话不多说,进入正题。 一.MediaMetadataRetriever 播放视频并取得画面的一帧,大家最先想到应该都是这个,我...