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

济南做设计公司网站长春网站建设

济南做设计公司网站,长春网站建设,网站搭建公司排行榜,江苏省城乡和住房建设厅网站文章目录 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.khdw.cn/news/4858.html

相关文章:

  • 手机app制作pdfseo技术网
  • 网络科技公司骗术360优化大师官方下载手机
  • 手机销售网站建设项目书营销一体化平台
  • 泰州网站设计公司百度竞价在哪里开户
  • 高质量网站内容建设标准郑州新闻发布
  • 宁海县高质量营销型网站建设数据网站有哪些
  • 哈尔滨网站制作公司哪家好梅州seo
  • 做外贸网站哪里好互联网营销师培训费用是多少
  • 如何做一元购网站关键词网站排名软件
  • 接项目做的网站seo关键词
  • wordpress收不到网站学计算机哪个培训机构好
  • 做网站如何与腾讯合作线上推广产品
  • 海城网站制作百度seo优化培训
  • 中国建设银行预约网站首页百度浏览器网页
  • 电脑上做免费网站教程视频微信销售平台
  • 软件工程师就业前景福州seo招聘
  • 瑞金网站建设黑帽友情链接
  • 对一个网站怎么做攻击测试搜狗竞价推广效果怎么样
  • 大型公司为什么做网站seo专员工资一般多少
  • 我想找个郑州做网站的电工培训
  • 淘宝请人做网站靠谱吗安徽seo推广公司
  • 网页设计报告结束语seo技术服务外包公司
  • 做网站 空间还是服务器广州网络推广平台
  • 奎屯网站制作惠州大亚湾经济技术开发区
  • 会员中心网站模板营销型公司网站建设
  • 网站访客抓取长沙网络营销顾问
  • 免费1级做爰片动漫在线观看网站百度快照怎么使用
  • 濮阳市网站怎么做宣传互联网网络推广公司
  • 怎么做动态网站页面广告公司网上接单平台
  • 网站空间测试合肥seo优化公司