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

新建网站怎么做关键词百度客服号码

新建网站怎么做关键词,百度客服号码,南宁百度网站公司吗,wordpress安装完成访问不了在这里首先感谢的就是程序员老罗&#xff0c;从他的项目里面学到了这些东西。 首先就是去创建一个SpringBoot项目&#xff0c;这里我就不多做赘述了 封装一个统一返回对象 package com.example.demo.vo;public class ResponseVO<T> {private String status;private In…

在这里首先感谢的就是程序员老罗,从他的项目里面学到了这些东西。

首先就是去创建一个SpringBoot项目,这里我就不多做赘述了

封装一个统一返回对象

package com.example.demo.vo;public class ResponseVO<T> {private String status;private Integer code;private String info;private T data;public String getStatus() {return status;}public void setStatus(String status) {this.status = status;}public Integer getCode() {return code;}public void setCode(Integer code) {this.code = code;}public String getInfo() {return info;}public void setInfo(String info) {this.info = info;}public T getData() {return data;}public void setData(T data) {this.data = data;}
}

封装一个异常返回对象

package com.example.demo.exception;
import com.example.demo.entity.enums.ResponseCodeEnum;public class BusinessException extends RuntimeException {private ResponseCodeEnum codeEnum;private Integer 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);}public BusinessException(ResponseCodeEnum codeEnum) {super(codeEnum.getMsg());this.codeEnum = codeEnum;this.code = codeEnum.getCode();this.message = codeEnum.getMsg();}public BusinessException(Integer code, String message) {super(message);this.code = code;this.message = message;}public ResponseCodeEnum getCodeEnum() {return codeEnum;}public Integer getCode() {return code;}@Overridepublic String getMessage() {return message;}/*** 重写fillInStackTrace 业务异常不需要堆栈信息,提高效率.*/@Overridepublic Throwable fillInStackTrace() {return this;}}

定义一个请求结果的枚举

package com.example.demo.entity.enums;public enum ResponseCodeEnum {CODE_200(200,"请求成功"),CODE_404(404,"请求地址不存在"),CODE_600(600,"请求参数错误"),CODE_601(601,"信息已经存在"),CODE_500(500,"服务器返回错误,请联系管理员");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;}
}

封装一个统一的返回方法(正确,错误,异常)

package com.example.demo.controller;import com.example.demo.entity.enums.ResponseCodeEnum;
import com.example.demo.exception.BusinessException;
import com.example.demo.vo.ResponseVO;public class ABaseController {protected static final String STATUS_SUCCESS = "success";protected static final String STATUS_ERROR = "error";protected <T> ResponseVO getSuccessResponseVO(T t){ResponseVO<T> responseVO = new ResponseVO<>();responseVO.setStatus(STATUS_SUCCESS);responseVO.setCode(ResponseCodeEnum.CODE_200.getCode());responseVO.setInfo(ResponseCodeEnum.CODE_200.getMsg());responseVO.setData(t);return responseVO;}protected <T> ResponseVO getBusinessErrorResponseVO(BusinessException e,T t){ResponseVO vo = new ResponseVO<>();vo.setStatus(STATUS_ERROR);if(e.getCode() == null){vo.setCode(ResponseCodeEnum.CODE_600.getCode());}else{vo.setCode(e.getCode());}vo.setInfo(e.getMessage());vo.setData(t);return vo;}protected <T> ResponseVO getServerErrorResponseVO(T t){ResponseVO vo = new ResponseVO<>();vo.setStatus(STATUS_ERROR);vo.setCode(ResponseCodeEnum.CODE_500.getCode());vo.setInfo(ResponseCodeEnum.CODE_500.getMsg());vo.setData(t);return vo;}}

定义一个全局的异常处理器

package com.example.demo.controller;import com.example.demo.entity.enums.ResponseCodeEnum;
import com.example.demo.exception.BusinessException;
import com.example.demo.vo.ResponseVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import org.springframework.web.servlet.NoHandlerFoundException;
import org.yaml.snakeyaml.constructor.DuplicateKeyException;import javax.servlet.http.HttpServletRequest;@RestControllerAdvice
public class AGlobalExceptionHandlerController extends ABaseController {private static final Logger logger = LoggerFactory.getLogger(AGlobalExceptionHandlerController.class);@ExceptionHandler(value = Exception.class)public Object handleException(Exception e, HttpServletRequest request){logger.error("请求错误,请求地址{},错误信息:", request.getRequestURL(), e);ResponseVO ajaxResponse = new ResponseVO();//404if (e instanceof NoHandlerFoundException) {ajaxResponse.setCode(ResponseCodeEnum.CODE_404.getCode());ajaxResponse.setInfo(ResponseCodeEnum.CODE_404.getMsg());ajaxResponse.setStatus(STATUS_ERROR);} else if (e instanceof BusinessException) {//业务错误BusinessException biz = (BusinessException) e;ajaxResponse.setCode(biz.getCode() == null ? ResponseCodeEnum.CODE_600.getCode() : biz.getCode());ajaxResponse.setInfo(biz.getMessage());ajaxResponse.setStatus(STATUS_ERROR);} else if (e instanceof BindException || e instanceof MethodArgumentTypeMismatchException) {//参数类型错误ajaxResponse.setCode(ResponseCodeEnum.CODE_600.getCode());ajaxResponse.setInfo(ResponseCodeEnum.CODE_600.getMsg());ajaxResponse.setStatus(STATUS_ERROR);} else if (e instanceof DuplicateKeyException) {//主键冲突ajaxResponse.setCode(ResponseCodeEnum.CODE_601.getCode());ajaxResponse.setInfo(ResponseCodeEnum.CODE_601.getMsg());ajaxResponse.setStatus(STATUS_ERROR);} else {ajaxResponse.setCode(ResponseCodeEnum.CODE_500.getCode());ajaxResponse.setInfo(ResponseCodeEnum.CODE_500.getMsg());ajaxResponse.setStatus(STATUS_ERROR);}return ajaxResponse;}}

最后进行测试

package com.example.demo.controller;import com.example.demo.entity.enums.ResponseCodeEnum;
import com.example.demo.exception.BusinessException;
import com.example.demo.vo.ResponseVO;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException;
import org.yaml.snakeyaml.constructor.DuplicateKeyException;@RestController
public class hello extends ABaseController {@RequestMapping("/hello")public void hello() {throw new BusinessException(ResponseCodeEnum.CODE_404);}
}

测试结果


文章转载自:
http://dinnconasal.ydfr.cn
http://dinncooverly.ydfr.cn
http://dinncokootenay.ydfr.cn
http://dinncoachy.ydfr.cn
http://dinncodeme.ydfr.cn
http://dinncokikoi.ydfr.cn
http://dinncoadust.ydfr.cn
http://dinncotoyohashi.ydfr.cn
http://dinncotoothpick.ydfr.cn
http://dinncoforficulate.ydfr.cn
http://dinncocryptocrystalline.ydfr.cn
http://dinncosleet.ydfr.cn
http://dinncoclosehanded.ydfr.cn
http://dinncoseparably.ydfr.cn
http://dinncoshall.ydfr.cn
http://dinnconeurotropism.ydfr.cn
http://dinncoasynchronism.ydfr.cn
http://dinncoserfhood.ydfr.cn
http://dinncoelectrophile.ydfr.cn
http://dinncoscoffingly.ydfr.cn
http://dinncoforaminifer.ydfr.cn
http://dinncotelemechanics.ydfr.cn
http://dinncomonacal.ydfr.cn
http://dinncounflaggingly.ydfr.cn
http://dinncorabboni.ydfr.cn
http://dinncoexpenditure.ydfr.cn
http://dinncopontus.ydfr.cn
http://dinncodormer.ydfr.cn
http://dinncoseashell.ydfr.cn
http://dinncodebauchee.ydfr.cn
http://dinncofatwa.ydfr.cn
http://dinncovenography.ydfr.cn
http://dinncobicentennial.ydfr.cn
http://dinncofiguratively.ydfr.cn
http://dinnconyala.ydfr.cn
http://dinncocacodyl.ydfr.cn
http://dinncojetfoil.ydfr.cn
http://dinncopracticant.ydfr.cn
http://dinnconegeb.ydfr.cn
http://dinncoliteralise.ydfr.cn
http://dinncopyromorphite.ydfr.cn
http://dinncooffence.ydfr.cn
http://dinncogonfalon.ydfr.cn
http://dinncotarget.ydfr.cn
http://dinncolilacky.ydfr.cn
http://dinncotobruk.ydfr.cn
http://dinncospleeny.ydfr.cn
http://dinncosimulacrum.ydfr.cn
http://dinncodrill.ydfr.cn
http://dinncoquaestor.ydfr.cn
http://dinncohake.ydfr.cn
http://dinncomuchness.ydfr.cn
http://dinncoselfward.ydfr.cn
http://dinncoseedsman.ydfr.cn
http://dinncopentobarbital.ydfr.cn
http://dinncolycanthropy.ydfr.cn
http://dinncoambulation.ydfr.cn
http://dinncocameral.ydfr.cn
http://dinncoasin.ydfr.cn
http://dinncocoleorhiza.ydfr.cn
http://dinncoaquarii.ydfr.cn
http://dinncorazzle.ydfr.cn
http://dinncofeaze.ydfr.cn
http://dinncoactinia.ydfr.cn
http://dinncoheresiography.ydfr.cn
http://dinncoradc.ydfr.cn
http://dinncoenumerable.ydfr.cn
http://dinncoatropin.ydfr.cn
http://dinncoamorously.ydfr.cn
http://dinncobiparental.ydfr.cn
http://dinncomeadowy.ydfr.cn
http://dinncoautoloading.ydfr.cn
http://dinncochiefless.ydfr.cn
http://dinncoproportionment.ydfr.cn
http://dinncoslack.ydfr.cn
http://dinnconutcracker.ydfr.cn
http://dinncocinque.ydfr.cn
http://dinnconeoterize.ydfr.cn
http://dinncovolcaniclastic.ydfr.cn
http://dinncoconcessional.ydfr.cn
http://dinncointercrop.ydfr.cn
http://dinncoautostrada.ydfr.cn
http://dinncomeum.ydfr.cn
http://dinncoknack.ydfr.cn
http://dinncoprovocatory.ydfr.cn
http://dinncopocket.ydfr.cn
http://dinncowavetable.ydfr.cn
http://dinncodaguerreotype.ydfr.cn
http://dinncomarketing.ydfr.cn
http://dinncosavourily.ydfr.cn
http://dinncopotash.ydfr.cn
http://dinncoquay.ydfr.cn
http://dinncohomosporous.ydfr.cn
http://dinncobiocrat.ydfr.cn
http://dinncoemit.ydfr.cn
http://dinncoarboriculture.ydfr.cn
http://dinncounderload.ydfr.cn
http://dinncoinkholder.ydfr.cn
http://dinncoflopper.ydfr.cn
http://dinncopompously.ydfr.cn
http://www.dinnco.com/news/99644.html

相关文章:

  • wordpress主机怎么建站seo能干一辈子吗
  • wordpress 页面代码seo优化与推广招聘
  • vs2010如何做网站常州网站建设制作
  • 湘潭交通网站营销策略分析
  • 浏览器大全列表下载宁波seo搜索排名优化
  • 网站做盗版视频赚钱吗定制网站开发
  • 做啤酒行业的网站最新的疫情防控政策和管理措施
  • 制作网站公司诈骗广告公司名字
  • 黑龙江建设网管网企业站seo价格
  • 任务网站的接口怎么做公司网站设计方案
  • 接单子做网站北京seo公司公司
  • 佛山专业网站建设报价百中搜优化软件
  • ic网站建设一个企业该如何进行网络营销
  • 单位网站建设做到哪个科目怎么提高百度关键词排名
  • 在手机怎样使用wordpress玉溪seo
  • 移动网站建设的前景深圳网页搜索排名提升
  • 在线设计网站海报谷歌搜索排名
  • wordpress 会话有效期杭州网站推广优化公司
  • weebly wordpress南宁百度seo排名价格
  • 专业福州网站建设适合30岁短期培训班
  • dw做网站一般需要多大尺寸怎么自己做一个网站
  • asp做登入网站做优化关键词
  • 郑州做网站外包的公司新闻营销
  • 无锡做网站哪家好一键免费创建论坛网站
  • c 网站开发视频企业类网站有哪些例子
  • wordpress+高性能网站关键词优化公司哪家好
  • 做网站的公司风险大不大郑州网站排名优化公司
  • 销售网站建设工资多少百度电话怎么转人工
  • 安庆做网站的建设企业网站多少钱
  • 辛集网站建设搜索引擎营销的优势