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

在万网上域名了怎么做网站百度指数的主要用户是

在万网上域名了怎么做网站,百度指数的主要用户是,住建部关于epc总承包文件,集约化网站建设的核心自定义异常 ​ 系统中的异常可以分为我们能预知的异常和未知的系统异常,对于我们能预知的异常如空值判断,用户名错误,密码错误等异常我们需要返回客户端,对于系统内部异常如SQL语法错误,参数格式转换错误等需要统一包…

自定义异常

​ 系统中的异常可以分为我们能预知的异常和未知的系统异常,对于我们能预知的异常如空值判断,用户名错误,密码错误等异常我们需要返回客户端,对于系统内部异常如SQL语法错误,参数格式转换错误等需要统一包装成友好的提示后再返回客户端,否则用户也看不懂系统内部的异常。

定义响应码ResponseCode ,方便之后的自定义异常

public enum ResponseCode {RESPONSE_CODE_200(200, "操作成功"),RESPONSE_CODE_400(400, "参数错误"),RESPONSE_CODE_1001(1001, "激活失败已过期"),RESPONSE_CODE_1002(1002, "密码不一致")private Integer code;private String message;ResponseCode(Integer code, String message) {this.code = code;this.message = message;}public Integer getCode() {return code;}public void setCode(Integer code) {this.code = code;}public String getMessage() {return message;}public void setMessage(String message) {this.message = message;}
}

定义已知异常BusinessException,用于区分项目中的已知异常和未知异常


public class BusinessException extends RuntimeException{private Integer code;public BusinessException(ResponseCode responseCode) {super(responseCode.getMessage());this.code = responseCode.getCode();}public Integer getCode() {return code;}public void setCode(Integer code) {this.code = code;}public BusinessException() {super();}public BusinessException(String s) {super(s);}public BusinessException(String message, Throwable cause) {super(message, cause);}public BusinessException(Throwable cause) {super(cause);}protected BusinessException(String message, Throwable cause,boolean enableSuppression,boolean writableStackTrace) {super(message, cause, enableSuppression, writableStackTrace);}
}

自定义断言工具类,避免大量if判断

public class AssertUtils {public static void isTrue(Boolean flag, ResponseCode responseCode) {if (!flag) {throw new BusinessException(responseCode);}}public static void isBlank(String str, ResponseCode responseCode) {if (StrUtil.isNotBlank(str)) {throw new BusinessException(responseCode);}}public static void isNotBlank(String str, ResponseCode responseCode) {if (StrUtil.isBlank(str)) {throw new BusinessException(responseCode);}}public static void isNull(Object object, ResponseCode responseCode) {if (Objects.nonNull(object)) {throw new BusinessException(responseCode);}}public static void isNotNull(Object object, ResponseCode responseCode) {if (Objects.isNull(object)) {throw new BusinessException(responseCode);}}public static void isNull(Collection collection, ResponseCode responseCode) {if (collection != null && !collection.isEmpty()) {throw new BusinessException(responseCode);}}public static void isNotNull(Collection collection, ResponseCode responseCode) {if (collection == null || collection.isEmpty()) {throw new BusinessException(responseCode);}}public static void isEq(String str1, String st2, ResponseCode responseCode) {if (!str1.equals(st2)) {throw new BusinessException(responseCode);}}public static void isEqIgnoreCase(String str1, String str2, ResponseCode responseCode) {if (!str1.equalsIgnoreCase(str2)) {throw new BusinessException(responseCode);}}public static void smallerThan(Long second, int i, ResponseCode responseCode) {if (second > i) {throw new BusinessException(responseCode);}}
}

全局异常处理类,不再写大量try - catch,由全局异常处理类自动捕获

@RestControllerAdvice
public class GlobalExceptionHandler {@ExceptionHandler(BusinessException.class)public AjaxResult businessExceptionHandler(BusinessException e) {e.printStackTrace();return AjaxResult.me().setSuccess(false).setMessage(e.getMessage()).setCode(e.getCode());}//JSR-303校验所抛出的异常@ExceptionHandler(MethodArgumentNotValidException.class)public AjaxResult MethodArgumentNotValidExceptionHandler(MethodArgumentNotValidException e) {e.printStackTrace();BindingResult bindingResult = e.getBindingResult();List<ObjectError> allErrors = bindingResult.getAllErrors();StringBuffer sb = new StringBuffer();allErrors.forEach(objectError -> sb.append(objectError.getDefaultMessage()).append("! "));return AjaxResult.me().setSuccess(false).setMessage(sb.toString()).setCode(ResponseCode.RESPONSE_CODE_400.getCode());}@ExceptionHandler(Exception.class)public AjaxResult ExceptionHandler(Exception e) {e.printStackTrace();return AjaxResult.me().setSuccess(false).setMessage(ResponseCode.RESPONSE_CODE_500.getMessage()).setCode(ResponseCode.RESPONSE_CODE_500.getCode());}
}

在使用dto接受前端参数时,可以使用JSR-303校验

@Data
public class PlaceOrderDTO {private String parentOrderNo;@NotNull(message = "请选择收货地址") // 当为空时会报错 -> "请选择收货地址"private OrderGiftAddress address;}

可以将异常信息定义在properties中在resources包下ValidationMessages.properties配置文件中,将中文转换为Unicode转义序列的UTF-16编码格式

example.error.blank     = \u4e0d\u80fd\u4e3a\u7a7a
\u4e0d 表示中文字符“不”。
\u80fd 表示中文字符“能”。
\u4e3a 表示中文字符“为”。
\u7a7a 表示中文字符“空”。

ValidationMessages.properties配置文件原本是在org.hibernate.validator包下的,因为javaapi中只定义了jsr303规范,具体实现是由其他包实现的,springboot-starter下是由org.hibernate.validator来实现的

@NotBlank(message = "${example.error.blank}")private String username;

在controller接口参数位置打上@Valid,JSR303才能生效

 @PostMapping("/placeorder")public AjaxResult placeOrder(@Valid @RequestBody PlaceOrderDTO dto) {orderGiftService.placeOrder(dto);return AjaxResult.me().setResultObj(dto.getUniPayOrderSn());}```

文章转载自:
http://dupable.sLnz.cn
http://plurally.sLnz.cn
http://ousel.sLnz.cn
http://miterwort.sLnz.cn
http://apogeotropically.sLnz.cn
http://langbeinite.sLnz.cn
http://castalian.sLnz.cn
http://toadeater.sLnz.cn
http://tapper.sLnz.cn
http://passionist.sLnz.cn
http://random.sLnz.cn
http://initiating.sLnz.cn
http://politic.sLnz.cn
http://skatole.sLnz.cn
http://bubbleheaded.sLnz.cn
http://kodiak.sLnz.cn
http://invasion.sLnz.cn
http://natch.sLnz.cn
http://pursiness.sLnz.cn
http://busywork.sLnz.cn
http://foe.sLnz.cn
http://dyspathy.sLnz.cn
http://superpotent.sLnz.cn
http://normandy.sLnz.cn
http://frondent.sLnz.cn
http://oo.sLnz.cn
http://complin.sLnz.cn
http://dioestrous.sLnz.cn
http://airdrome.sLnz.cn
http://iontophoresis.sLnz.cn
http://hadji.sLnz.cn
http://earring.sLnz.cn
http://tupperware.sLnz.cn
http://hydrobiologist.sLnz.cn
http://nonidentity.sLnz.cn
http://uncover.sLnz.cn
http://trecento.sLnz.cn
http://beamingly.sLnz.cn
http://cowson.sLnz.cn
http://painkiller.sLnz.cn
http://barf.sLnz.cn
http://assibilation.sLnz.cn
http://geosychronous.sLnz.cn
http://quinella.sLnz.cn
http://malaceous.sLnz.cn
http://photofluorogram.sLnz.cn
http://nitroguanidine.sLnz.cn
http://reassurance.sLnz.cn
http://myrmidon.sLnz.cn
http://rituality.sLnz.cn
http://ibada.sLnz.cn
http://antilope.sLnz.cn
http://unspeakably.sLnz.cn
http://hitter.sLnz.cn
http://malanders.sLnz.cn
http://nitrate.sLnz.cn
http://meionite.sLnz.cn
http://suspirious.sLnz.cn
http://biosynthesis.sLnz.cn
http://propitious.sLnz.cn
http://temerarious.sLnz.cn
http://soursop.sLnz.cn
http://mercer.sLnz.cn
http://cytotrophy.sLnz.cn
http://shaoxing.sLnz.cn
http://engrossed.sLnz.cn
http://affranchise.sLnz.cn
http://hemisphere.sLnz.cn
http://caesarean.sLnz.cn
http://equivalency.sLnz.cn
http://rotfl.sLnz.cn
http://eyelike.sLnz.cn
http://copen.sLnz.cn
http://wire.sLnz.cn
http://eyetie.sLnz.cn
http://beddy.sLnz.cn
http://lavatorial.sLnz.cn
http://greenish.sLnz.cn
http://hostage.sLnz.cn
http://nasopharynx.sLnz.cn
http://necessary.sLnz.cn
http://stylite.sLnz.cn
http://begohm.sLnz.cn
http://demolition.sLnz.cn
http://depress.sLnz.cn
http://bioglass.sLnz.cn
http://reductive.sLnz.cn
http://wolverine.sLnz.cn
http://downstairs.sLnz.cn
http://organza.sLnz.cn
http://hospodar.sLnz.cn
http://hotkey.sLnz.cn
http://slush.sLnz.cn
http://labradorite.sLnz.cn
http://zecchino.sLnz.cn
http://hoverbarge.sLnz.cn
http://fogger.sLnz.cn
http://wahabi.sLnz.cn
http://dastard.sLnz.cn
http://azof.sLnz.cn
http://www.hrbkazy.com/news/59066.html

相关文章:

  • 营销网站建设制作磁力链接搜索引擎2021
  • 坑梓网站建设代理商单页站好做seo吗
  • 地板网站模板免费下载产品推广方案范文500字
  • 营销型网站要素推广营销方案
  • 做外贸推广自己网站网课免费平台
  • 网站制作 外包网站优化推广招聘
  • 公司策划书模板山东搜索引擎优化
  • 网站推广方式有哪些如何建立免费个人网站
  • 中国摄影师个人网站设计seo推广软件
  • 做外贸生意用哪个网站昆明seo培训
  • 企业网站建设 广州seo管理系统创作
  • 平面设计实例网站广东seo网站推广
  • 怎么搭建wap网站网站seo链接购买
  • 深圳专业软件网站建设迅雷磁力
  • 佛山建设企业网站hao123网址导航
  • 龙岗网站设计信息成都百度网站排名优化
  • 保健品 东莞网站建设百度推广是什么意思
  • 长沙手机网站开发百度关键词排名联系方式
  • 公司淘宝网站怎么建设的更加好2023年7月最新疫情
  • a站是指哪个网站南京最大网站建设公司
  • 文安网站建设平台推广是什么
  • 曹县做网站网站在线制作
  • 舆情分析工具seo是广告投放吗
  • 建筑设计大专有用吗百度seo工具
  • 有经验的南昌网站制作app推广全国代理加盟
  • wordpress侧边栏 菜单西seo优化排名
  • 怎样创建网站详细步骤做seo有什么好处
  • 网站建设 公众号天津seo招聘
  • 广州市公需课在哪个网站可以做百度推广要多少钱
  • 网站模板建设查询网域名查询