From a7f235164f7beeb71ed88b2fe76ef68bba2faf34 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期四, 18 三月 2021 13:08:14 +0800 Subject: [PATCH] Merge branch 'master' of https://gitee.com/y_project/RuoYi-Vue --- ruoyi-common/src/main/java/com/ruoyi/common/core/controller/BaseController.java | 71 +++++++++++++++++++++++++++++------ 1 files changed, 58 insertions(+), 13 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/controller/BaseController.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/controller/BaseController.java index 2a31e70..ebf2376 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/controller/BaseController.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/controller/BaseController.java @@ -1,22 +1,24 @@ package com.ruoyi.common.core.controller; -import java.beans.PropertyEditorSupport; -import java.util.Date; -import java.util.List; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.web.bind.WebDataBinder; -import org.springframework.web.bind.annotation.InitBinder; +import cn.hutool.core.lang.Validator; +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpStatus; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; -import com.ruoyi.common.constant.HttpStatus; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.page.PageDomain; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.core.page.TableSupport; import com.ruoyi.common.utils.DateUtils; -import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.sql.SqlUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.bind.WebDataBinder; +import org.springframework.web.bind.annotation.InitBinder; + +import java.beans.PropertyEditorSupport; +import java.util.Date; +import java.util.List; /** * web灞傞�氱敤鏁版嵁澶勭悊 @@ -25,7 +27,7 @@ */ public class BaseController { - protected final Logger logger = LoggerFactory.getLogger(BaseController.class); + protected final Logger logger = LoggerFactory.getLogger(this.getClass()); /** * 灏嗗墠鍙颁紶閫掕繃鏉ョ殑鏃ユ湡鏍煎紡鐨勫瓧绗︿覆锛岃嚜鍔ㄨ浆鍖栦负Date绫诲瀷 @@ -52,7 +54,7 @@ PageDomain pageDomain = TableSupport.buildPageRequest(); Integer pageNum = pageDomain.getPageNum(); Integer pageSize = pageDomain.getPageSize(); - if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) + if (Validator.isNotNull(pageNum) && Validator.isNotNull(pageSize)) { String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy()); PageHelper.startPage(pageNum, pageSize, orderBy); @@ -66,7 +68,7 @@ protected TableDataInfo getDataTable(List<?> list) { TableDataInfo rspData = new TableDataInfo(); - rspData.setCode(HttpStatus.SUCCESS); + rspData.setCode(HttpStatus.HTTP_OK); rspData.setMsg("鏌ヨ鎴愬姛"); rspData.setRows(list); rspData.setTotal(new PageInfo(list).getTotal()); @@ -85,10 +87,53 @@ } /** + * 鍝嶅簲杩斿洖缁撴灉 + * + * @param result 缁撴灉 + * @return 鎿嶄綔缁撴灉 + */ + protected AjaxResult toAjax(boolean result) + { + return result ? success() : error(); + } + + /** + * 杩斿洖鎴愬姛 + */ + public AjaxResult success() + { + return AjaxResult.success(); + } + + /** + * 杩斿洖澶辫触娑堟伅 + */ + public AjaxResult error() + { + return AjaxResult.error(); + } + + /** + * 杩斿洖鎴愬姛娑堟伅 + */ + public AjaxResult success(String message) + { + return AjaxResult.success(message); + } + + /** + * 杩斿洖澶辫触娑堟伅 + */ + public AjaxResult error(String message) + { + return AjaxResult.error(message); + } + + /** * 椤甸潰璺宠浆 */ public String redirect(String url) { - return StringUtils.format("redirect:{}", url); + return StrUtil.format("redirect:{}", url); } } -- Gitblit v1.9.3