当前位置: 首页 > news >正文

深圳罗湖做网站公司哪家好手机app免费制作平台

深圳罗湖做网站公司哪家好,手机app免费制作平台,房产网站建设ppt,建设一个本地网站文章目录 4.1后端统一设计思想4.1.1后端统一返回格式对象4.1.2后端统一响应状态码4.1.3后端统一异常处理类4.1.4StringUtils类4.1.5 RedisUtils类 4.1后端统一设计思想 4.1.1后端统一返回格式对象 com.easypan.entity.vo.ResponseVO Data public class ResponseVO<T> …

在这里插入图片描述

文章目录

    • 4.1后端统一设计思想
      • 4.1.1后端统一返回格式对象
      • 4.1.2后端统一响应状态码
      • 4.1.3后端统一异常处理类
      • 4.1.4StringUtils类
      • 4.1.5 RedisUtils类

4.1后端统一设计思想

4.1.1后端统一返回格式对象

  • com.easypan.entity.vo.ResponseVO
@Data
public class ResponseVO<T> {private String status;private Integer code;	//响应状态码private String info;	//响应消息private T data;			//响应数据
}

4.1.2后端统一响应状态码

  • com.easypan.entity.enums.ResponseCodeEnum
public enum ResponseCodeEnum {CODE_200(200, "请求成功"),CODE_404(404, "请求地址不存在"),CODE_600(600, "请求参数错误"),CODE_601(601, "信息已经存在"),CODE_500(500, "服务器返回错误,请联系管理员"),CODE_901(901, "登录超时,请重新登录"),CODE_902(902, "分享连接不存在,或者已失效"),CODE_903(903, "分享验证失效,请重新验证"),CODE_904(904, "网盘空间不足,请扩容");private Integer code;	//状态码private String msg;		//状态码对应的信息ResponseCodeEnum(Integer code, String msg) {this.code = code;this.msg = msg;}public Integer getCode() {return code;}public String getMsg() {return msg;}
}

4.1.3后端统一异常处理类

  • com.easypan.exception.BusinessException
@Data
@AllArgsConstructor
public class BusinessException extends RuntimeException {private ResponseCodeEnum codeEnum;  //后端统一响应状态码private Integer code;               //自定义code值private String message;             //自定义消息public BusinessException(String message, Throwable e) {super(message, e);this.message = message;}public BusinessException(String message) {super(message);this.message = message;}public BusinessException(Throwable e) {super(e);}/*** @Description: 根据指定codeEnum创建Exception对象*/public BusinessException(ResponseCodeEnum codeEnum) {super(codeEnum.getMsg());this.codeEnum = codeEnum;this.code = codeEnum.getCode();this.message = codeEnum.getMsg();}/*** @Description: 自定义code、message来创建Exception对象*/public BusinessException(Integer code, String message) {super(message);this.code = code;this.message = message;}/*** 重写fillInStackTrace 业务异常不需要堆栈信息,提高效率.*/@Overridepublic Throwable fillInStackTrace() {return this;}}

4.1.4StringUtils类

  • com.easypan.utils.StringUtils
public class StringUtils {public static String encodeByMD5(String originString) {return StringUtils.isEmpty(originString) ? null : DigestUtils.md5Hex(originString);}public static boolean isEmpty(String str) {if (null == str || "".equals(str) || "null".equals(str) || "\u0000".equals(str)) {return true;} else if ("".equals(str.trim())) {return true;}return false;}public static String getFileSuffix(String fileName) {Integer index = fileName.lastIndexOf(".");if (index == -1) {return "";}String suffix = fileName.substring(index);return suffix;}public static String getFileNameNoSuffix(String fileName) {Integer index = fileName.lastIndexOf(".");if (index == -1) {return fileName;}fileName = fileName.substring(0, index);return fileName;}public static String rename(String fileName) {String fileNameReal = getFileNameNoSuffix(fileName);String suffix = getFileSuffix(fileName);return fileNameReal + "_" + getRandomString(Constants.LENGTH_5) + suffix;}public static final String getRandomString(Integer count) {return RandomStringUtils.random(count, true, true);}public static final String getRandomNumber(Integer count) {return RandomStringUtils.random(count, false, true);}public static String escapeTitle(String content) {if (isEmpty(content)) {return content;}content = content.replace("<", "&lt;");return content;}public static String escapeHtml(String content) {if (isEmpty(content)) {return content;}content = content.replace("<", "&lt;");content = content.replace(" ", "&nbsp;");content = content.replace("\n", "<br>");return content;}public static boolean pathIsOk(String path) {if (StringUtils.isEmpty(path)) {return true;}if (path.contains("../") || path.contains("..\\")) {return false;}return true;}
}

4.1.5 RedisUtils类

  • com.easypan.utils.RedisUtils
@Slf4j
@Component("redisUtils")
public class RedisUtils<V> {@Resourceprivate RedisTemplate<String, V> redisTemplate;/*** 普通缓存放入* @param key   键* @param value 值* @return true成功 false失败*/public boolean set(String key, V value) {try {redisTemplate.opsForValue().set(key, value);return true;} catch (Exception e) {log.error("设置redisKey:{},value:{}失败", key, value);return false;}}/*** 普通缓存放入并设置时间** @param key   键* @param value 值* @param time  时间(秒) time要大于0 如果time小于等于0 将设置无限期* @return true成功 false 失败*/public boolean setex(String key, V value, long time) {try {if (time > 0) {redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);} else {set(key, value);}return true;} catch (Exception e) {log.error("设置redisKey:{},value:{}失败", key, value);return false;}}//获取指定key的value值public V get(String key) {return key == null ? null : redisTemplate.opsForValue().get(key);}/*** 删除缓存,key 可以传一个值 或多个*/public void delete(String... key) {if (key != null && key.length > 0) {if (key.length == 1) {redisTemplate.delete(key[0]);} else {redisTemplate.delete((Collection<String>) CollectionUtils.arrayToList(key));}}}
}

在这里插入图片描述

http://www.yidumall.com/news/5671.html

相关文章:

  • 就业网站哪个靠谱付费推广平台有哪些
  • 带动画的网站模板怎样在百度上发布自己的信息
  • 手机做网站过程今日热点新闻一览
  • 临海如何制作公司网站框架免费seo教程资源
  • 商城网站开发技术有哪些影视后期哪个培训靠谱
  • 今天北京感染了多少人优化视频
  • 饮水机企业网站模板做销售怎么和客户聊天
  • 把网站制作成app销售推广的方法都有哪些
  • 手机网站制作要求网络营销广告策划
  • 天津做网站软件淄博搜索引擎优化
  • 适合用dedecms做的网站最新时事热点
  • 自己做视频网站 在优酷推广百度搜索风云排行榜
  • 哪个公司的网站做的好未来网络营销的发展趋势
  • 企业手机建站系统友情链接免费发布平台
  • 网站建设方案流程互联网营销师怎么报名
  • 青岛建网站的公司免费b站在线观看人数在哪
  • 公司网站制作步骤互动营销案例100
  • ps制作网站导航图片读书网站排名
  • java做网站用什么框架论坛推广网站
  • 武汉公司网站推广新媒体运营主要做什么
  • 中国做网站最大的公司交换友情链接推广法
  • 做夺宝网站要办理什么意思线上线下整合营销方案
  • 建设通网站源码友情链接的作用
  • 上海亿网站建设枣庄网站建设制作
  • 甘肃省和住房建设厅网站苹果看国外新闻的app
  • 建设网站的免费模板seo虚拟外链
  • 24小时自助下单网站中国最好的营销策划公司
  • 手机网站的优势软文范例500字
  • 山东网站建设公司电话外链优化
  • 自己在线制作logo免费生成器百度怎么做关键词优化