|
@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.yihu.jw.restmodel.web.*;
|
|
import com.yihu.jw.restmodel.web.*;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.dao.DataAccessException;
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
@ -16,6 +17,7 @@ import javax.servlet.http.HttpServletResponse;
|
|
import java.beans.PropertyDescriptor;
|
|
import java.beans.PropertyDescriptor;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.lang.reflect.Method;
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.sql.SQLException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
@ -28,7 +30,7 @@ import java.util.*;
|
|
*
|
|
*
|
|
* @author Progr1mmer
|
|
* @author Progr1mmer
|
|
*/
|
|
*/
|
|
public abstract class EnvelopRestEndpoint {
|
|
|
|
|
|
public abstract class EnvelopRestEndpoint extends Exception {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
protected ObjectMapper objectMapper;
|
|
protected ObjectMapper objectMapper;
|
|
@ -196,6 +198,67 @@ public abstract class EnvelopRestEndpoint {
|
|
return failed(message, -10000);
|
|
return failed(message, -10000);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
protected Envelop failedException(Exception e){
|
|
|
|
if (e.getClass().equals(DataAccessException.class))
|
|
|
|
{
|
|
|
|
e.printStackTrace();//数据库操作失败
|
|
|
|
return null;
|
|
|
|
} else if (e.getClass().toString().equals(
|
|
|
|
NullPointerException.class.toString()))
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
//调用了未经初始化的对象或者是不存在的对象!
|
|
|
|
return failed("空指针",170004);
|
|
|
|
} else if (e.getClass().equals(IOException.class))
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
//IO异常!
|
|
|
|
return null;
|
|
|
|
} else if (e.getClass().equals(ClassNotFoundException.class))
|
|
|
|
{
|
|
|
|
e.printStackTrace();//指定的类不存在!
|
|
|
|
return null;
|
|
|
|
} else if (e.getClass().equals(ArithmeticException.class))
|
|
|
|
{
|
|
|
|
e.printStackTrace();//数学运算异常!
|
|
|
|
return null;
|
|
|
|
} else if (e.getClass().equals(ArrayIndexOutOfBoundsException.class))
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
//数组下标越界!
|
|
|
|
return null;
|
|
|
|
} else if (e.getClass().equals(IllegalArgumentException.class))
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
//方法的参数错误!
|
|
|
|
return null;
|
|
|
|
} else if (e.getClass().equals(ClassCastException.class))
|
|
|
|
{
|
|
|
|
e.printStackTrace();//类型强制转换错误!
|
|
|
|
return null;
|
|
|
|
} else if (e.getClass().equals(SecurityException.class))
|
|
|
|
{
|
|
|
|
e.printStackTrace();//违背安全原则异常!
|
|
|
|
return null;
|
|
|
|
} else if (e.getClass().equals(SQLException.class))
|
|
|
|
{
|
|
|
|
e.printStackTrace();//操作数据库异常!
|
|
|
|
return null;
|
|
|
|
} else if (e.getClass().equals(NoSuchMethodError.class))
|
|
|
|
{
|
|
|
|
e.printStackTrace();//方法末找到异常!
|
|
|
|
return null;
|
|
|
|
} else if (e.getClass().equals(InternalError.class))
|
|
|
|
{
|
|
|
|
e.printStackTrace();//Java虚拟机发生了内部错误
|
|
|
|
return null;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
e.printStackTrace();//程序内部错误,操作失败!
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
protected Envelop failed (String message, int status) {
|
|
protected Envelop failed (String message, int status) {
|
|
Envelop envelop = new Envelop();
|
|
Envelop envelop = new Envelop();
|
|
envelop.setMessage(message);
|
|
envelop.setMessage(message);
|