{
"code":"200",
"data":{"":""},
"message":"处理成功"
}
{
"code":"300",
"data":{"":""},
"message":"没有此用户"
}
<!-- base-package 如果多个,用“,”分隔 -->
<context:component-scan base-package="com.we,cn.isuyang">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Service" />
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<!-- 打开aop 注解 -->
<aop:aspectj-autoproxy />
/**
* json返回切面
* <p>
* 用于处理json返回结果
*
* @author ZhuangJunxiang(529272571@qq.com)
* @Date 2017年4月28日
*/
@Component
@Aspect
@Order(2)
public class JsonReturnAspect {
/**
* 设置分页默认值
* <p>
* 如果分页没有设置值,则默认从系统的配置文件里读取
*
* @param pjp 切点
*/
@Around(value = "@annotation(org.springframework.web.bind.annotation.ResponseBody)")
@Order(1)
public Object warp(final ProceedingJoinPoint pjp) throws Throwable {
Object list = pjp.proceed();
if (isReturnVoid(pjp)) {
HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
.getResponse();
if (isNeedWrap(pjp)) {
response.getWriter().write(JsonUtil.toJson(success("操作成功")));
}
return list;
}
return data(list);
}
/**
* 是否需要包裹
*
* @param pjp 切点
*
* @return true表示不需要
*/
private boolean isNeedWrap(final ProceedingJoinPoint pjp) {
Method method = AspectUtil.getMethod(pjp);
return !method.isAnnotationPresent(Void.class);
}
/**
* 是否返回空
*
* @param pjp
* @return true:返回类型为void,false:返回类型不是void
*/
private boolean isReturnVoid(ProceedingJoinPoint pjp) {
Method method = AspectUtil.getMethod(pjp);
Class<?> returnType = method.getReturnType();
return "void".equals(returnType.getName());
}
/**
* 构建成功后的返回对象
* <p>
* 消息为空时,不提示,不为空则进行提示
*
* @param message 成功消息
* @return json对象
*/
public static Map<String, Object> success(final String message) {
Map<String, Object> map = MapUtil.map();
map.put("code", StatusCode.SUCCESS.key());
map.put("message", message);
map.put("data","");
return map;
}
/**
* 构建成功后的返回对象
* <p>
* 消息为空时,不提示,不为空则进行提示
*
* @param message 成功消息
* @return json对象
*/
public static Map<String, Object> data(final Object data) {
Map<String, Object> map = MapUtil.map();
map.put("code", StatusCode.SUCCESS.key());
map.put("message", message);
map.put("data",data);
return map;
}
}
{
"code":"200",
"data":"",
"message":"处理成功"
}
@RequestMapping
@ResponseBody
public void add(long matchId, Model model) {
slxSignupViewService.setAddInfo(matchId, model);
}
/**
* 空注解
* <p>
* 用于标识将controller层中的返回值原模原样的out出去
*
* @author WangSen(wangsenhehe@126.com)
* @Date 2017年8月17日
*/
@Target({ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Void {
}
/**
* 支付完成
*/
@Void
@ResponseBody
@RequestMapping
public void payFinish() throws IOException {
alipayViewService.payFinish();
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有