最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Springboot中使用攔截器、過濾器、監(jiān)聽器的流程分析

 更新時間:2023年12月20日 11:55:35   作者:程序三兩行  
Javaweb三大組件:servlet、Filter(過濾器)、?Listener(監(jiān)聽器),這篇文章主要介紹了Springboot中使用攔截器、過濾器、監(jiān)聽器的流程分析,感興趣的朋友跟隨小編一起看看吧

一、Servlet、Filter(過濾器)、 Listener(監(jiān)聽器)、Interceptor(攔截器)

Javaweb三大組件:servlet、Filter(過濾器)、 Listener(監(jiān)聽器)

SpringBoot特有組件:Interceptor(攔截器)

過濾器、攔截器、監(jiān)聽器、AOP(后續(xù)文章介紹)、全局異常處理器(后續(xù)文章介紹)是搭建系統(tǒng)框架時,經(jīng)常用到的部分,全局異常處理器的作用很明顯,就是處理接口執(zhí)行過程中的異常,而過濾器、攔截器和AOP的作用就很豐富了,日志記錄、性能監(jiān)控、安全認證等等可以向上抽取的功能組件,均可以用他們來實現(xiàn)。

傳統(tǒng)基于Servlet容器的程序中,我們可以使用過濾器和監(jiān)聽器,在Java 框架中還可以使用攔截器,而面向切面編程AOP更是作為Spring框架中的核心思想被大家所關注

Filter和Listener:依賴Servlet容器,基于函數(shù)回調(diào)實現(xiàn)??梢詳r截所有請求,覆蓋范圍更廣,但無法獲取ioc容器中的bean。

Interceptor和aop:依賴spring框架,基于java反射和動態(tài)代理實現(xiàn)。只能攔截controller的請求,可以獲取ioc容器中的bean,這點很重要,在攔截器里注入一個service,可以調(diào)用業(yè)務邏輯。。 

從 Filter -> Interceptor -> aop ,攔截的功能越來越細致、強大,尤其是Interceptor和aop可以更好的結合spring框架的上下文進行開發(fā)。但是攔截順序也是越來越靠后,請求是先進入Servlet容器的,越早的過濾和攔截對系統(tǒng)性能的消耗越少。具體選用哪種方法,就需要開發(fā)人員根據(jù)實際業(yè)務情況綜合考慮了。

二、過濾器

1、過濾器作用

Filter過濾器是Servlet容器層面的,在實現(xiàn)上基于函數(shù)回調(diào),可以對幾乎所有請求進行過濾

過濾器是對數(shù)據(jù)進行過濾,預處理過程,當我們訪問網(wǎng)站時,有時候會發(fā)布一些敏感信息,發(fā)完以后有的會用*替代,還有就是登陸權限控制等,一個資源,沒有經(jīng)過授權,肯定是不能讓用戶隨便訪問的,這個時候,也可以用到過濾器,主要是對用戶的一些請求進行一些預處理,并在服務器響應后再進行預處理,返回給用戶。

過濾器的功能還有很多,例如實現(xiàn)URL級別的權限控制、壓縮響應信息、編碼格式等等。對web服務器管理所有的web資源,例如jsp,靜態(tài)圖片 過濾敏感詞匯,某些信息用*隱藏。
使用方式有以下三種

2、過濾器執(zhí)行流程

3、過濾器攔截路徑

4、過濾鏈

一個javaweb系統(tǒng)中,可以配置多個過濾器、這多個過濾器就形成了一個過濾鏈,當然可以控制每個過濾器順序,見過濾器三種實現(xiàn)方式

5、過濾器三種實現(xiàn)方式

第一種方式:利用Servlet3.0的WebFilter注解配置

@WebFilter是Servlet3.0新增加的注解,在servlet3.0之前,我們需要在web.xml文件中進行過濾器的配置,而現(xiàn)在可以通過此注解進行配置,當項目啟動時,會自動掃描自動注冊

通過 @WebFilter 注解來標記一個過濾器,這種方式相信大家很容易想到。這是將 Servlet 中的那一套東西直接拿到 Spring Boot 上用。

具體做法就是通過 @WebFilter 注解來標記一個 Filter,如下:

//一個是filter的名字,一個是url為什么時用此過濾器,其他的看源碼,Filter,必須要有名字,所有的過濾器執(zhí)行順序是根據(jù)Filter的名字字母順序來執(zhí)行的
@WebFilter(filterName = "filter1",urlPatterns = {"/hello/*"})
public class TimeFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("=======初始化過濾器=========");
    }
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
            throws IOException, ServletException {
        long start = System.currentTimeMillis();
        filterChain.doFilter(request, response);
        System.out.println("filter 耗時:" + (System.currentTimeMillis() - start));
    }
    @Override
    public void destroy() {
        System.out.println("=======銷毀過濾器=========");
    }
}

這個注解要生效,還需要我們在項目啟動類上配置 @ServletComponentScan 注解,

@ServletComponentScan 注解雖然名字帶了 Servlet,但是實際上它不僅僅可以掃描項目中的 Servlet 容器,也可以掃描 Filter 和 Listener。

這是我們在 Spring Boot 中使用過濾器的第一種方式,在實際項目中,這種方式使用較少,因為這種方式有一個很大的弊端就是無法指定 Filter 的優(yōu)先級,如果存在多個 Filter 時,無法通過 @Order 指定優(yōu)先級。

@SpringBootApplication
@ServletComponentScan
public class SysoaApplication {
    public static void main(String[] args) {
        SpringApplication.run(SysoaApplication.class, args);
    }
}

第二種方式:利用SpringBoot的配置類來添加過濾器

這種方式最簡單,直接實現(xiàn)Filter接口,并使用@Component注解標注為組件自動注入bean,

Filter接口有 init、doFilter、destroy 三個方法,但 init、destroy 是有默認方法實現(xiàn),可以不重寫。

@Component
public class TimeFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("=======初始化過濾器=========");
    }
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
            throws IOException, ServletException {
        long start = System.currentTimeMillis();
        filterChain.doFilter(request, response);
        System.out.println("filter 耗時:" + (System.currentTimeMillis() - start));
    }
    @Override
    public void destroy() {
        System.out.println("=======銷毀過濾器=========");
    }
}

但是缺點是沒辦法設置過濾的路徑,默認是 /* 過濾所有(當然代碼中可以加入相關判斷)。 

public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        String requestUri = request.getRequestURI().replaceFirst(contextPath, "");
        String[] urlList = {"/login","/loginPage","logOut"};
        for (String uriItem : urlList){
            if(requestUri.contains(uriItem)){
                filterChain.doFilter(request,response);
                return;
            }
        }
        //判斷session中是否存在用戶,這里還可以做其他業(yè)務邏輯 比如ip黑名單等 用戶是否被禁,禁止多人在線等
        if (request.getSession().getAttribute(SystemConstants.USER) == null) {
            //沒有登錄跳轉到登錄頁面
            response.sendRedirect(contextPath+SystemConstants.LOGIN_PAGE_URL);
            return;
        }
        filterChain.doFilter(request, response);
    }

這種方式看起來很方便,一個注解將 Filter 納入到 Spring 容器中即可。而且這種方式還有一個優(yōu)勢,就是如果存在多個 Filter,可以通過 @Order 注解指定多個 Filter 的優(yōu)先級,像下面這樣:

@Component
@Order(-1)
public class MyFilter implements Filter {
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("-----doFilter-----");
        chain.doFilter(request, response);
    }
}

第三種方式:Configuration+FilterRegistrationBean

還是將 Filter 封裝成一個 Bean,但這個 Bean 是 FilterRegistrationBean,通過 FilterRegistrationBean 我們既可以配置 Filter 的優(yōu)先級,也可以配置 Filter 的攔截規(guī)則。

public class AFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("=======初始化過濾器A=========");
    }
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
            throws IOException, ServletException {
        long start = System.currentTimeMillis();
        filterChain.doFilter(request, response);
        System.out.println("filter 耗時:" + (System.currentTimeMillis() - start));
    }
    @Override
    public void destroy() {
        System.out.println("=======銷毀過濾器=========");
    }
}

 然后使用SpringBoot提供的FilterRegistrationBean來對Filter進行配置

@Configuration
public class FilterConfig  {
    /*過濾器注解bean:  FilterRegistrationBean,  注冊過濾器, 添加過濾器*/
    @Bean
    public FilterRegistrationBean<AFilter> createFilterRegistrationBean() {
        //1.創(chuàng)建FilterRegistrationBean這個對象, 一個過濾器注冊器,注冊一個過濾器
        FilterRegistrationBean<AFilter> filterRegistrationBean  = new FilterRegistrationBean<>();
        //注冊一個過濾器
        filterRegistrationBean.setFilter(new AFilter());
        //過濾器的配置, 設置攔截的url
        filterRegistrationBean.addUrlPatterns("/*");
        //給過濾器起名字
        filterRegistrationBean.setName("AFilter");
        //設置過濾器的執(zhí)行順序
        filterRegistrationBean.setOrder(1);
        return filterRegistrationBean;
    }

當然也可以配置多個并且控制順序

@Configuration
public class FilterConfig  {
    @Bean
    FilterRegistrationBean<AFilter> myFilterFilterRegistrationBean() {
        FilterRegistrationBean<AFilter> bean = new FilterRegistrationBean<>();
        bean.setFilter(new AFilter());
        bean.setOrder(-1);
        bean.setUrlPatterns(Arrays.asList("/*"));
        return bean;
    }
    @Bean
    FilterRegistrationBean<BFilter> myFilterFilterRegistrationBean2() {
        FilterRegistrationBean<BFilter> bean = new FilterRegistrationBean<>();
        bean.setFilter(new BFilter());
        bean.setOrder(-2);
        bean.setUrlPatterns(Arrays.asList("/hello"));
        return bean;
    }
}

FilterRegistrationBean 擴展

Spring Boot 為了方便大家向 Servlet 容器中注冊 Servlet、Filter 以及 Listener,提供了一個 Bean 注冊的抽象類 RegistrationBean,如下:

public abstract class RegistrationBean implements ServletContextInitializer, Ordered {
	private int order = Ordered.LOWEST_PRECEDENCE;
	private boolean enabled = true;
	@Override
	public final void onStartup(ServletContext servletContext) throws ServletException {
		String description = getDescription();
		if (!isEnabled()) {
			logger.info(StringUtils.capitalize(description) + " was not registered (disabled)");
			return;
		}
		register(description, servletContext);
	}
	protected abstract String getDescription();
	protected abstract void register(String description, ServletContext servletContext);
	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}
	public boolean isEnabled() {
		return this.enabled;
	}
	public void setOrder(int order) {
		this.order = order;
	}
	@Override
	public int getOrder() {
		return this.order;
	}
}

RegistrationBean 實現(xiàn)了 ServletContextInitializer 接口,在 Servlet 啟動時,RegistrationBean#onStartup 方法會被調(diào)用,進而完成 Filter、Servlet 以及 Listener 的注冊。
    enabled 屬性可以理解為一個開關,設置為 false 相當于關閉組件注冊。

RegistrationBean 有眾多的實現(xiàn)類,我們之前使用的 FilterRegistrationBean 只是其中之一:

實現(xiàn)類的作用一目了然:

    ServletListenerRegistrationBean 用來注冊監(jiān)聽器。
    ServletRegistrationBean 用來注冊 Servlet。
    DispatcherServletRegistrationBean 用來注冊 DispatcherServlet。
    FilterRegistrationBean 用來注冊過濾器。
    DelegatingFilterProxyRegistrationBean 則用來注冊 DelegatingFilterProxy,DelegatingFilterProxy 在 Spring Security、Spring Session、Shiro 等整合時非常有用。

6、過濾器實際項目場景使用舉例

使用filter實現(xiàn)登錄校驗

三、監(jiān)聽器

Listener監(jiān)聽器也是Servlet層面的,可以用于監(jiān)聽Web應用中某些對象、信息的創(chuàng)建、銷毀和修改等動作發(fā)生,然后做出相應的響應處理??梢栽谶@些事件發(fā)生前和發(fā)生后進行處理。

用途:

1、用于統(tǒng)計在線人數(shù)和在線用戶,

2、系統(tǒng)啟動時加載初始化信息,

3、統(tǒng)計網(wǎng)站訪問量,

4、記錄用戶訪問路徑

根據(jù)監(jiān)聽對象,將監(jiān)聽器分為3類:

第一類:ServletContext:對應application,實現(xiàn)接口ServletContextListener。在整個Web服務中只有一個,在Web服務關閉時銷毀??捎糜谧鰯?shù)據(jù)緩存,例如結合redis,在Web服務創(chuàng)建時從數(shù)據(jù)庫拉取數(shù)據(jù)到緩存服務器。

第二類:HttpSession:對應session會話,實現(xiàn)接口HttpSessionListener。在會話起始時創(chuàng)建,一端關閉會話后銷毀??捎米鳙@取在線用戶數(shù)量。

第三類:ServletRequest:對應request,實現(xiàn)接口ServletRequestListener。request對象是客戶發(fā)送請求時創(chuàng)建的,用于封裝請求數(shù)據(jù),請求處理完畢后銷毀??捎米鞣庋b用戶信息。

在寫Listener的類時,有兩種方式。

第一種是只加@Component;

第二種是 @WebListener 和 @ServletComponentScan 配合使用。

不過實現(xiàn)接口則根據(jù)監(jiān)聽對象區(qū)分,如:ServletContextListener、HttpSessionListener和ServletRequestListener。

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
@WebListener()
public class MyListener implements HttpSessionListener{
	 public static int online = 0;
	    @Override
	    public void sessionCreated(HttpSessionEvent se) {
	        System.out.println("創(chuàng)建session,在線用戶數(shù):" + (++online));
	    }
	    @Override
	    public void sessionDestroyed(HttpSessionEvent se) {
	        System.out.println("銷毀session,在線用戶數(shù):" + (--online));
	        online--;
	    }
}

啟動類

 
@SpringBootApplication
@ServletComponentScan("com.demo.listener") //需要掃描包
public class SpringBoot1Application {
	public static void main(String[] args) {
		SpringApplication.run(SpringBoot1Application.class, args);
	}
}

這里我們再補充一下常用的監(jiān)聽器接口:

1.ServletContextListener -- 監(jiān)聽servletContext對象的創(chuàng)建以及銷毀

    1.1    contextInitialized(ServletContextEvent arg0)   -- 創(chuàng)建時執(zhí)行

    1.2    contextDestroyed(ServletContextEvent arg0)  -- 銷毀時執(zhí)行

2.HttpSessionListener  -- 監(jiān)聽session對象的創(chuàng)建以及銷毀

    2.2   sessionCreated(HttpSessionEvent se)   -- 創(chuàng)建時執(zhí)行

    2.2   sessionDestroyed(HttpSessionEvent se) -- 銷毀時執(zhí)行

3.ServletRequestListener -- 監(jiān)聽request對象的創(chuàng)建以及銷毀

    3.1    requestInitialized(ServletRequestEvent sre) -- 創(chuàng)建時執(zhí)行

    3.2    requestDestroyed(ServletRequestEvent sre) -- 銷毀時執(zhí)行

4.ServletContextAttributeListener  -- 監(jiān)聽servletContext對象中屬性的改變

    4.1    attributeAdded(ServletContextAttributeEvent event) -- 添加屬性時執(zhí)行

    4.2    attributeReplaced(ServletContextAttributeEvent event) -- 修改屬性時執(zhí)行

    4.3    attributeRemoved(ServletContextAttributeEvent event) -- 刪除屬性時執(zhí)行

5.HttpSessionAttributeListener  --監(jiān)聽session對象中屬性的改變

    5.1    attributeAdded(HttpSessionBindingEvent event) -- 添加屬性時執(zhí)行

    5.2    attributeReplaced(HttpSessionBindingEvent event) -- 修改屬性時執(zhí)行

    5.3    attributeRemoved(HttpSessionBindingEvent event) -- 刪除屬性時執(zhí)行

6.ServletRequestAttributeListener  --監(jiān)聽request對象中屬性的改變

    6.1    attributeAdded(ServletRequestAttributeEvent srae) -- 添加屬性時執(zhí)行

    6.2    attributeReplaced(ServletRequestAttributeEvent srae) -- 修改屬性時執(zhí)行

    6.3    attributeRemoved(ServletRequestAttributeEvent srae) -- 刪除屬性時執(zhí)行

四、攔截器

1、攔截器作用

過濾器是攔截所有請求,而攔截器是攔截在進入到前端控制器之后的請求,

Interceptor和Filter、Listener有本質上的不同,F(xiàn)ilter、Listener都是依賴于Servlet容器,而Interceptor則是依賴于Spring框架,是aop的一種表現(xiàn),當某個方法或字段被訪問時進行攔截,在之前 和 在之后 加入某些操作

用途:權限驗證,判斷用戶是否登錄,或者再做某一操作時要確定滿足某一定的條件,基于Java的動態(tài)代理實現(xiàn)的。

2、攔截器執(zhí)行流程

3、攔截器攔截路徑

 攔截器可以根據(jù)需求配置不同的攔截路徑

4、攔截器的使用

首先通過實現(xiàn) HandlerInterceptor接口聲明攔截器的類,實現(xiàn)preHandle、postHandle和afterCompletion方法。然后通過配置類WebMvcConfigurer接口,實現(xiàn)addInterceptors方法配置攔截器

 
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Component
public class InterceptorTest  implements HandlerInterceptor {
    /**
     * 在請求處理之前進行調(diào)用(Controller方法調(diào)用之前)
     * 預處理回調(diào)方法,實現(xiàn)處理器的預處理
     * 返回值:true表示繼續(xù)流程;false表示流程中斷,不會繼續(xù)調(diào)用其他的攔截器或處理器
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        System.out.println("開始攔截.........");
        String name = MyCookie.getCookieByKey(request,response,"name");
        String password = MyCookie.getCookieByKey(request,response,"password");
        //如果session中沒有user,表示沒登陸
        if (password == null|| name == null){
            //這個方法返回false表示忽略當前請求,如果一個用戶調(diào)用了需要登陸才能使用的接口,如果他沒有登陸這里會直接忽略掉
            //當然你可以利用response給用戶返回一些提示信息,告訴他沒登陸
            request.getRequestDispatcher("/interceptor/to_login").forward(request, response);
            return false;
        }else {
            return true;//放行
        }
    }
    /**
     * 請求處理之后進行調(diào)用,但是在視圖被渲染之前(Controller方法調(diào)用之后)
     * 后處理回調(diào)方法,實現(xiàn)處理器(controller)的后處理,但在渲染視圖之前
     * 此時我們可以通過modelAndView對模型數(shù)據(jù)進行處理或對視圖進行處理
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
                           ModelAndView modelAndView) throws Exception {
        // TODO Auto-generated method stub
        System.out.println("return前");
    }
    /**
     * 在整個請求結束之后被調(diào)用,也就是在DispatcherServlet 渲染了對應的視圖之后執(zhí)行(主要是用于進行資源清理工作)
     * 整個請求處理完畢回調(diào)方法,即在視圖渲染完畢時回調(diào),
     * 如性能監(jiān)控中我們可以在此記錄結束時間并輸出消耗時間,
     * 還可以進行一些資源清理,類似于try-catch-finally中的finally,
     * 但僅調(diào)用處理器執(zhí)行鏈中
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
            throws Exception {
        // TODO Auto-generated method stub
        System.out.println("操作完之后,可以用于資源清理");
    }
}

然后將這個組件加入到boot中,在boot1版本中 通過繼承WebmvcConfigureAdapter實現(xiàn)一個web配置,例如我們配置上面的攔截器

@Configuration //聲明這是一個配置
public class LoginInterceptorConfig extends WebMvcConfigurerAdapter {
@Resource
private LoginInterceptor loginInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(loginInterceptor).addPathPatterns("/admin/**").excludePathPatterns("/admin").excludePathPatterns("/admin/login");
}
    }

 或者直接使用匿名類的方式

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * 自定義一個登陸攔截器
 */
@Configuration //聲明這是一個配置
public class LoginInterceptor extends WebMvcConfigurerAdapter {
    /*
    用來添加攔截器的方法
    InterceptorRegistry registry攔截器注冊
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //使用匿名內(nèi)部類創(chuàng)建要給攔截器
        HandlerInterceptor loginInterceptor = new HandlerInterceptor() {
            @Override
            public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws Exception {
                //判斷session中是否存在用戶
                if (request.getSession().getAttribute("user") == null) {
                    response.sendRedirect("/admin");
                    return false;
                }
                return true;
            }
            @Override
            public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
            }
            @Override
            public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
            }
        };
        registry.addInterceptor(loginInterceptor).addPathPatterns("/admin/**").excludePathPatterns("/admin").excludePathPatterns("/admin/login");
    }
}

 對于Sprinboot2版本,第一步還是定義一個攔截器組件。

第二不再是通過繼承WebmvcConfigureAdapter實現(xiàn)一個web配置,而是實現(xiàn)接口WebMvcConfigurer增加一個配置

@Configuration
public class WebConfig implements WebMvcConfigurer {
//引入我們的攔截器組件
    @Resource
    private LoginInterceptor loginInterceptor;
//實現(xiàn)攔截器配置方法
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor).addPathPatterns("/admin/**").excludePathPatterns("/admin").excludePathPatterns("/admin/login");
    }
}

踩坑5--springboot2.xl登陸攔截器中排除靜態(tài)資源的幾種情況整理 - 百度文庫 (baidu.com) 

5、攔截器使用場景舉例

Filter與Interceptor區(qū)別

1.接口范圍不同:過濾器需要實現(xiàn)Filter接口,而攔截器需要實現(xiàn)HandlerInterceptor接口。

2.攔截范圍不同:過濾器Filter會攔截所有的資源,而Interceptor只會攔截Spring環(huán)境中的資源

到此這篇關于Springboot中使用攔截器、過濾器、監(jiān)聽器的文章就介紹到這了,更多相關Springboot使用攔截器、過濾器、監(jiān)聽器內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • JDBC查詢Map轉對象實現(xiàn)過程詳解

    JDBC查詢Map轉對象實現(xiàn)過程詳解

    這篇文章主要介紹了JDBC查詢Map轉對象實現(xiàn)過程詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-10-10
  • 一文講解Java的String、StringBuffer和StringBuilder的使用與區(qū)別

    一文講解Java的String、StringBuffer和StringBuilder的使用與區(qū)別

    String是不可變的字符序列,而StringBuffer和StringBuilder是可變的字符序列,本文就來詳細的介紹一下Java的String、StringBuffer和StringBuilder的使用與區(qū)別,感興趣的可以了解一下
    2024-03-03
  • Mybatis之mapper接口多參數(shù)方式

    Mybatis之mapper接口多參數(shù)方式

    這篇文章主要介紹了Mybatis之mapper接口多參數(shù)方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-05-05
  • 在MyBatis的XML映射文件中<trim>元素所有場景下的完整使用示例代碼

    在MyBatis的XML映射文件中<trim>元素所有場景下的完整使用示例代碼

    在MyBatis的XML映射文件中,<trim>元素用于動態(tài)添加SQL語句的一部分,處理前綴、后綴及多余的逗號或連接符,示例展示了如何在UPDATE、SELECT、INSERT和SQL片段中使用<trim>元素,以實現(xiàn)動態(tài)的SQL構建,感興趣的朋友一起看看吧
    2025-01-01
  • SpringBoot中的自動裝配原理解析

    SpringBoot中的自動裝配原理解析

    這篇文章主要介紹了SpringBoot中的自動裝配原理解析,自動裝配就是指 Spring 容器在不使用<constructor-arg>和<property>標簽的情況下,可以自動裝配(autowire)相互協(xié)作的Bean之間的關聯(lián)關系,將一個 Bean注入其他Bean的Property中,需要的朋友可以參考下
    2023-08-08
  • SpringMVC中RequestBody注解的List參數(shù)傳遞方式

    SpringMVC中RequestBody注解的List參數(shù)傳遞方式

    這篇文章主要介紹了SpringMVC中RequestBody注解的List參數(shù)傳遞方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-10-10
  • Flink實現(xiàn)往Kafka中多個topic發(fā)送消息

    Flink實現(xiàn)往Kafka中多個topic發(fā)送消息

    文章介紹了使用Flink 1.13.2 和 Kafka 2.6.2 從Kafka讀取數(shù)據(jù),并根據(jù)邏輯將數(shù)據(jù)分配到不同的topic,提到了需要重寫FlinkKafka的Key序列化器,并加入自定義邏輯以發(fā)送消息到指定的topic,文中還包括了配置Kafka信息和如何連接FlinkKafka的步驟
    2025-10-10
  • Java運算符與流程控制之全類型運算符用法及分支?/?循環(huán)語句實戰(zhàn)指南

    Java運算符與流程控制之全類型運算符用法及分支?/?循環(huán)語句實戰(zhàn)指南

    這篇文章主要介紹了Java運算符與流程控制之全類型運算符用法及分支/循環(huán)語句實戰(zhàn)的相關資料,運算符包括算術、關系、邏輯、賦值和三元運算符,重點講解了它們的用法、優(yōu)先級和結合性,以及強制類型轉換的注意事項,需要的朋友可以參考下
    2026-01-01
  • Java中的HashMap內(nèi)存泄漏問題詳解

    Java中的HashMap內(nèi)存泄漏問題詳解

    這篇文章主要介紹了Java中的HashMap內(nèi)存泄漏問題詳解,WeakHashMap中的key是弱引用,如果再使用之后沒有及時remove掉這個key,那么當GC時key就可能會被回收,導致key對應的value對象占用的內(nèi)存無法回收進而導致內(nèi)存泄漏,需要的朋友可以參考下
    2023-09-09
  • MybatisPlus多條件?or()的使用問題小結

    MybatisPlus多條件?or()的使用問題小結

    這篇文章主要介紹了MybatisPlus多條件?or()的使用問題小結,本文給大家介紹的非常詳細,感興趣的朋友跟隨小編一起看看吧
    2024-05-05

最新評論

京山县| 唐海县| 赤壁市| 中卫市| 连云港市| 太康县| 晋州市| 石家庄市| 南丰县| 屏南县| 临猗县| 拉孜县| 灵武市| 兴隆县| 年辖:市辖区| 任丘市| 永善县| 阿巴嘎旗| 札达县| 扶余县| 仙游县| 武宣县| 武清区| 涞源县| 新河县| 建昌县| 临朐县| 含山县| 全椒县| 白山市| 龙南县| 南平市| 新沂市| 阿拉善盟| 绥棱县| 新绛县| 托克托县| 车险| 乌恰县| 从江县| 砀山县|