国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Springboot前后端不分離

這篇具有很好參考價值的文章主要介紹了Springboot前后端不分離。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

當前項目前后端都在一起時,避免一個一個controller的寫使用配置文件進行映射文章來源地址http://www.zghlxwxcb.cn/news/detail-527930.html

package com.example.ruiji.Config;

import com.example.ruiji.Interceptor.LoginInterceptor;
import com.example.ruiji.commom.JacksonObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.cbor.MappingJackson2CborHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.util.List;

@Configuration
//為了解決 WebMvcConfigurationSupport和 Spring Boot 2.0版本以后,官方不再推薦使用WebMvcConfigurationSupport,取而代之的是使用WebMvcConfigurer接口。因此,如果您使用了繼承自WebMvcConfigurationSupport的配置類1
public class webMvc extends WebMvcConfigurationSupport {
    /**
     * 在mvc 框架中設(shè)置靜態(tài)資源目錄映射 對mvc 路徑進行映射
     * @param registry
     */
    @Autowired
    StringRedisTemplate redisTemplate;
    @Autowired
    LoginInterceptor loginInterceptor;
    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
            //訪問這個路徑 映射到對應(yīng)的靜態(tài)資源目錄  就不需要一個個的controller寫跳轉(zhuǎn)
        registry.addResourceHandler("/backend/**").addResourceLocations("classpath:/template/backend/");
        registry.addResourceHandler("/front/**").addResourceLocations("classpath:/template/front/");
        super.addResourceHandlers(registry);
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor).excludePathPatterns(
                "/backend/**",
                "/front/**",
                "/employee/login",
                "/user/login",
                "backend/page/login/**",
                "/employee/logout/**",
                "/common/**",// 因為前端是通過action直接上傳 并不不axios發(fā)的 沒有authentic 肯定會被攔截
                 //因為前端攔截器失效 所以后端攔截器放行我自己寫的驗證登錄狀態(tài)接口 來給前端響應(yīng)式跳轉(zhuǎn)
//                前端除去個人信息不攔截
                "/category/list",
                "/shoppingCart/list",
                "/setmeal/list",
                "/dish/list",
                "/shoppingCart/add"
        );//不用在new 攔截器 并且需要配置攔截路徑 避免全部看攔截

    }

    /**
     * 擴展默認轉(zhuǎn)換器
     * 來替代默認的springmvc的轉(zhuǎn)換器
     * @param converters the list of configured converters to extend
     */

//    @Override
//    protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
//        MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
        設(shè)置對象轉(zhuǎn)換器 自定義的
//        mappingJackson2HttpMessageConverter.setObjectMapper(new JacksonObjectMapper());
//        // 上寫的轉(zhuǎn)換器添加到轉(zhuǎn)換器鏈中
//        converters.add(0,mappingJackson2HttpMessageConverter);
//
//    }
}

到了這里,關(guān)于Springboot前后端不分離的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包