欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

springboot 錯(cuò)誤處理小結(jié)

 更新時(shí)間:2018年03月26日 17:22:39   作者:crazyCodeLove  
在 java web開(kāi)發(fā)過(guò)程中,難免會(huì)有一些系統(tǒng)異常或人為產(chǎn)生一些異常。在 RESTful springboot 項(xiàng)目中如何優(yōu)雅的處理?下面腳本之家小編給大家?guī)?lái)了springboot 錯(cuò)誤處理小結(jié),感興趣的朋友一起看看吧

在 java web開(kāi)發(fā)過(guò)程中,難免會(huì)有一些系統(tǒng)異?;蛉藶楫a(chǎn)生一些異常。在 RESTful springboot 項(xiàng)目中如何優(yōu)雅的處理?

分析:在RESTful 風(fēng)格的springboot 項(xiàng)目中,返回的都是 body 對(duì)象,所以定義一個(gè)結(jié)果基類,其中包含 status,message,data(請(qǐng)求方法的返回結(jié)果),是比較合適的。

如果定義多個(gè)異常類進(jìn)行處理,會(huì)比較麻煩。比如StudentNotExistsException、StudentExistsException。。。等,并且不能指定錯(cuò)誤碼,不方便前端根據(jù)錯(cuò)誤碼進(jìn)行處理。

說(shuō)明:一般的spring mvc模型處理流程如下

一般controller層 -> Service層 -> Dao層。

1.controller層,接受請(qǐng)求,進(jìn)行分頁(yè),DTO對(duì)象封裝操作。

2.service層,執(zhí)行邏輯,控制并發(fā),事務(wù)。

3.Dao層,與數(shù)據(jù)庫(kù)交互。

使用一個(gè)學(xué)生表的處理進(jìn)行說(shuō)明:

1、定義常見(jiàn)的錯(cuò)誤枚舉 StudentExceptionEnum

public enum StudentExceptionEnum {
  STUDENT_NOT_EXIST(1004,"學(xué)生不存在,請(qǐng)確認(rèn)后再查"),
  STUDENT_EXIST(1005,"學(xué)生已存在");
  private Integer status;
  private String comment;
  StudentExceptionEnum(Integer status, String comment) {
    this.status = status;
    this.comment = comment;
  }
  public Integer getStatus() {
    return status;
  }
  public void setStatus(Integer status) {
    this.status = status;
  }
  public String getComment() {
    return comment;
  }
  public void setComment(String comment) {
    this.comment = comment;
  }
}

2 定義一個(gè)基本的處理結(jié)果類 RequestResult

@Data
public class RequestResult {
  private String message;
  private Integer status;
  private Object data;
  public RequestResult(String message, Integer status, Object data) {
    this.message = message;
    this.status = status;
    this.data = data;
  }
  public RequestResult(String message, Integer status) {
    this.message = message;
    this.status = status;
  }
  public RequestResult(String message, StudentExceptionEnum requestExceptionEnum) {
    this.message = message;
    this.status = requestExceptionEnum.getStatus();
  }
  public RequestResult() {
    status = 200;
    message = "ok";
  }
  public static RequestResult OK(Object data) {
    RequestResult result = new RequestResult();
    result.setData(data);
    return result;
  }
  public static RequestResult EXCEPTION(String message, Integer status) {
    return new RequestResult(message, status);
  }
  public static RequestResult EXCEPTION(String message, StudentExceptionEnum requestExceptionEnum) {
    return new RequestResult(message, requestExceptionEnum);
  }
}

3 實(shí)體類 Student

@Data
public class Student implements Serializable{
  private String id;
  private String nickname;
  private String name;
  private int age;
  private String sex;
  private String address;
  @Override
  public String toString() {
    return ToStringBuilder.reflectionToString(this);
  }
}

4 處理請(qǐng)求,添加學(xué)生,nickname 必填項(xiàng)。此處只顯示 Service 片段代碼

@Override
  public RequestResult addStudent(Student student) {
    if (studentDao.queryIdByNickname(student.getNickname()) == null) {
      studentDao.addStudent(student);
      System.out.println("添加成功");
      student = studentDao.queryByNickname(student.getNickname());
      return RequestResult.OK(student);
    } else {
      return RequestResult.EXCEPTION("用戶" + student.getNickname() + "已存在", StudentExceptionEnum.STUDENT_EXIST);
    }
  }

5 此時(shí),已經(jīng)完成了基本的處理情況。下面就進(jìn)行基本的測(cè)試了

5.1 添加一個(gè)新同學(xué)信息

5.2 再次添加讓其出現(xiàn)異常測(cè)試

二、到此基本已大功告成,但是,對(duì)于基本的運(yùn)行時(shí)異常沒(méi)有處理,直接返回給前端會(huì)很不友好。所以要定義一個(gè)全局的 RuntimeException 異常處理類。

此處需要使用的關(guān)鍵標(biāo)注: @ExceptionHandler

用法有兩種 1)在處理請(qǐng)求的 Controller 中添加 @ExceptionHandler,此時(shí)該方法只會(huì)處理該 Controller 拋出的異常。

2)將其用在全局的異常處理類中,全局異常處理類需要使用  @RestControllerAdvice 或 @ControllerAdvice 標(biāo)記

我們需要處理全局的 RuntimeException,所以我們使用第二種方法。當(dāng)然,這樣處理是為了客戶友好型,我們還是要處理這種錯(cuò)誤,怎么辦?就需要將錯(cuò)誤的信息記錄下來(lái),方便以后分析處理。此處使用 logger 進(jìn)行記錄。代碼如下

@RestControllerAdvice
public class BaseExceptionHandler {
  private static Logger logger = LoggerFactory.getLogger(BaseExceptionHandler.class);
  @ExceptionHandler(value = RuntimeException.class)
  public RequestResult exceptionHandler(HttpServletRequest request,Exception e) {
    logError(request,e);
    return RequestResult.EXCEPTION("內(nèi)部處理異常,工程師正在抓緊搶修,請(qǐng)稍后再來(lái)...",500);
  }
  public static void logError(HttpServletRequest request, Exception e) {
    logger.error("請(qǐng)求地址:" + request.getRequestURL());
    logger.error("請(qǐng)求方法:" + request.getMethod());
    logger.error("請(qǐng)求IP:" + getRemoteIp(request));
    logger.error("錯(cuò)誤詳情:");
    StackTraceElement[] error = e.getStackTrace();
    for (StackTraceElement stackTraceElement : error) {
      logger.error(stackTraceElement.toString());
    }
  }
  public static String getRemoteIp(HttpServletRequest request) {
    String ip = request.getHeader("X-Forwarded-For");
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
      if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("Proxy-Client-IP");
      }
      if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("WL-Proxy-Client-IP");
      }
      if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("HTTP_CLIENT_IP");
      }
      if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("HTTP_X_FORWARDED_FOR");
      }
      if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getRemoteAddr();
      }
    } else if (ip.length() > 15) {
      String[] ips = ip.split(",");
      for (int index = 0; index < ips.length; index++) {
        String strIp = (String) ips[index];
        if (!("unknown".equalsIgnoreCase(strIp))) {
          ip = strIp;
          break;
        }
      }
    }
    return ip;
  }
}

進(jìn)行測(cè)試看是否生效:

修改添加學(xué)生信息代碼如下:

public RequestResult addStudent(Student student) {
    int a = 1/0;
    
    if (studentDao.queryIdByNickname(student.getNickname()) == null) {
      studentDao.addStudent(student);
      System.out.println("添加成功");
      student = studentDao.queryByNickname(student.getNickname());
      return RequestResult.OK(student);
    } else {
      return RequestResult.EXCEPTION("用戶'" + student.getNickname() + "'已存在", StudentExceptionEnum.STUDENT_EXIST);
    }
  }

進(jìn)行測(cè)試

后臺(tái)打印錯(cuò)誤信息

2018-03-26 17:01:19.125 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : 請(qǐng)求地址:http://localhost:8080/demo1/student
2018-03-26 17:01:19.125 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : 請(qǐng)求方法:POST
2018-03-26 17:01:19.125 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : 請(qǐng)求IP:0:0:0:0:0:0:0:1
2018-03-26 17:01:19.125 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : 錯(cuò)誤詳情:
2018-03-26 17:01:19.125 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : com.huitong.demo.service.StudentService.addStudent(StudentService.java:71)
2018-03-26 17:01:19.125 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : com.huitong.demo.controller.StudentController.addStudent(StudentController.java:38)
2018-03-26 17:01:19.125 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2018-03-26 17:01:19.125 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
2018-03-26 17:01:19.125 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2018-03-26 17:01:19.125 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : java.lang.reflect.Method.invoke(Method.java:498)
2018-03-26 17:01:19.125 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209)
2018-03-26 17:01:19.125 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
2018-03-26 17:01:19.125 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
2018-03-26 17:01:19.125 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:870)
2018-03-26 17:01:19.125 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:776)
2018-03-26 17:01:19.125 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
2018-03-26 17:01:19.129 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)
2018-03-26 17:01:19.129 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
2018-03-26 17:01:19.129 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
2018-03-26 17:01:19.129 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:881)
2018-03-26 17:01:19.129 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
2018-03-26 17:01:19.129 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855)
2018-03-26 17:01:19.130 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
2018-03-26 17:01:19.130 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
2018-03-26 17:01:19.130 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
2018-03-26 17:01:19.130 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
2018-03-26 17:01:19.130 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
2018-03-26 17:01:19.130 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
2018-03-26 17:01:19.130 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
2018-03-26 17:01:19.130 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
2018-03-26 17:01:19.130 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
2018-03-26 17:01:19.130 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
2018-03-26 17:01:19.130 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
2018-03-26 17:01:19.130 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
2018-03-26 17:01:19.130 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
2018-03-26 17:01:19.130 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109)
2018-03-26 17:01:19.130 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
2018-03-26 17:01:19.130 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
2018-03-26 17:01:19.131 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
2018-03-26 17:01:19.131 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81)
2018-03-26 17:01:19.131 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
2018-03-26 17:01:19.131 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
2018-03-26 17:01:19.131 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
2018-03-26 17:01:19.131 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
2018-03-26 17:01:19.131 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
2018-03-26 17:01:19.131 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
2018-03-26 17:01:19.131 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
2018-03-26 17:01:19.131 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
2018-03-26 17:01:19.131 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
2018-03-26 17:01:19.131 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496)
2018-03-26 17:01:19.131 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
2018-03-26 17:01:19.131 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
2018-03-26 17:01:19.131 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
2018-03-26 17:01:19.131 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
2018-03-26 17:01:19.131 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
2018-03-26 17:01:19.131 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
2018-03-26 17:01:19.131 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
2018-03-26 17:01:19.131 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
2018-03-26 17:01:19.131 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
2018-03-26 17:01:19.131 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
2018-03-26 17:01:19.131 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
2018-03-26 17:01:19.131 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
2018-03-26 17:01:19.131 ERROR 9136 --- [nio-8080-exec-2] c.h.d.controller.BaseExceptionHandler  : java.lang.Thread.run(Thread.java:745)
2018-03-26 17:01:19.133 WARN 9136 --- [nio-8080-exec-2] .m.m.a.ExceptionHandlerExceptionResolver : Resolved exception caused by Handler execution: java.lang.ArithmeticException: / by zero

總結(jié)

以上所述是小編給大家介紹的springboot 錯(cuò)誤處理小結(jié),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

  • Maven?Pom?文件中的隱式依賴導(dǎo)致Jar沖突問(wèn)題

    Maven?Pom?文件中的隱式依賴導(dǎo)致Jar沖突問(wèn)題

    這篇文章主要介紹了Maven?Pom?文件中的隱式依賴導(dǎo)致Jar沖突問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-12-12
  • Java中對(duì)于雙屬性枚舉的使用案例

    Java中對(duì)于雙屬性枚舉的使用案例

    今天小編就為大家分享一篇關(guān)于Java中對(duì)于雙屬性枚舉的使用案例,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧
    2018-12-12
  • Spring框架通過(guò)工廠創(chuàng)建Bean的三種方式實(shí)現(xiàn)

    Spring框架通過(guò)工廠創(chuàng)建Bean的三種方式實(shí)現(xiàn)

    這篇文章主要介紹了Spring框架通過(guò)工廠創(chuàng)建Bean的三種方式實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03
  • 當(dāng)Mybatis遇上目錄樹(shù)超全完美解決方案

    當(dāng)Mybatis遇上目錄樹(shù)超全完美解決方案

    這篇文章主要介紹了當(dāng)Mybatis遇上目錄樹(shù)有哪些解決方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-04-04
  • SSH框架網(wǎng)上商城項(xiàng)目第5戰(zhàn)之商品類別級(jí)聯(lián)查詢和分頁(yè)功能

    SSH框架網(wǎng)上商城項(xiàng)目第5戰(zhàn)之商品類別級(jí)聯(lián)查詢和分頁(yè)功能

    SSH框架網(wǎng)上商城項(xiàng)目第5戰(zhàn)之商品類別級(jí)聯(lián)查詢和分頁(yè)功能,寫一下CategoryServiceImpl實(shí)現(xiàn)類,完成數(shù)據(jù)庫(kù)的級(jí)聯(lián)查詢,感興趣的小伙伴們可以參考一下
    2016-05-05
  • java實(shí)現(xiàn)斗地主游戲

    java實(shí)現(xiàn)斗地主游戲

    這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)斗地主游戲,洗牌、發(fā)牌、看牌,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-01-01
  • SpringBoot實(shí)現(xiàn)各種參數(shù)校驗(yàn)總結(jié)(建議收藏!)

    SpringBoot實(shí)現(xiàn)各種參數(shù)校驗(yàn)總結(jié)(建議收藏!)

    本文深入解析了Spring?Validation的使用方法、實(shí)現(xiàn)原理及最佳實(shí)踐,詳細(xì)介紹了各種參數(shù)校驗(yàn)場(chǎng)景,如requestBody和requestParam/PathVariable的使用,并探討了分組校驗(yàn)、嵌套校驗(yàn)和自定義校驗(yàn)的高級(jí)應(yīng)用,需要的朋友可以參考下
    2024-09-09
  • IDEA配置Maven教程的超詳細(xì)講解版

    IDEA配置Maven教程的超詳細(xì)講解版

    IntelliJ IDEA是當(dāng)前最流行的Java IDE(集成開(kāi)發(fā)環(huán)境)之一,也是業(yè)界公認(rèn)最好用的Java開(kāi)發(fā)工具之一,這篇文章主要給大家介紹了關(guān)于IDEA配置Maven教程的超詳細(xì)講解版,需要的朋友可以參考下
    2023-11-11
  • SpringBoot+@EnableScheduling使用定時(shí)器的常見(jiàn)案例

    SpringBoot+@EnableScheduling使用定時(shí)器的常見(jiàn)案例

    項(xiàng)目開(kāi)發(fā)中經(jīng)常需要執(zhí)行一些定時(shí)任務(wù),本文主要介紹了SpringBoot+@EnableScheduling使用定時(shí)器的常見(jiàn)案例,具有一定的參考價(jià)值,感興趣的可以了解一下
    2023-09-09
  • java批量下載將多個(gè)文件(minio中存儲(chǔ))壓縮成一個(gè)zip包代碼示例

    java批量下載將多個(gè)文件(minio中存儲(chǔ))壓縮成一個(gè)zip包代碼示例

    在Java應(yīng)用程序中有時(shí)我們需要從多個(gè)URL地址下載文件,并將這些文件打包成一個(gè)Zip文件進(jìn)行批量處理或傳輸,這篇文章主要給大家介紹了關(guān)于java批量下載將多個(gè)文件(minio中存儲(chǔ))壓縮成一個(gè)zip包的相關(guān)資料,需要的朋友可以參考下
    2023-11-11

最新評(píng)論