這篇文章給大家介紹怎么在SpringBoot中忽略請求參數(shù)的大小寫,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
成都創(chuàng)新互聯(lián)長期為上1000+客戶提供的網(wǎng)站建設(shè)服務(wù),團隊從業(yè)經(jīng)驗10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為古雷港企業(yè)提供專業(yè)的成都做網(wǎng)站、網(wǎng)站設(shè)計,古雷港網(wǎng)站改版等技術(shù)服務(wù)。擁有十年豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。import java.io.IOException; import java.util.Collections; import java.util.Enumeration; import java.util.Map; import javax.servlet.FilterChain; import javax.servlet.ServletException; import javax.servlet.annotation.WebFilter; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequestWrapper; import javax.servlet.http.HttpServletResponse; import org.springframework.core.annotation.Order; import org.springframework.util.LinkedCaseInsensitiveMap; import org.springframework.web.filter.OncePerRequestFilter; @Order(1) //重點 @WebFilter(filterName = "caseInsensitiveFilter", urlPatterns = "/*") public class CaseInsensitiveRequestParameterNameFilter extends OncePerRequestFilter { public CaseInsensitiveRequestParameterNameFilter() { System.out.println("CaseInsensitiveRequestParameterNameFilter.CaseInsensitiveRequestParameterNameFilter()"); } @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { filterChain.doFilter(new CaseInsensitiveParameterNameHttpServletRequest(request), response); } public static class CaseInsensitiveParameterNameHttpServletRequest extends HttpServletRequestWrapper { private final LinkedCaseInsensitiveMap<String[]> map = new LinkedCaseInsensitiveMap<>(); public CaseInsensitiveParameterNameHttpServletRequest(HttpServletRequest request) { super(request); map.putAll(request.getParameterMap()); } @Override public String getParameter(String name) { String[] array = this.map.get(name); if (array != null && array.length > 0) return array[0]; return null; } @Override public Map<String, String[]> getParameterMap() { return Collections.unmodifiableMap(this.map); } @Override public Enumeration<String> getParameterNames() { return Collections.enumeration(this.map.keySet()); } @Override public String[] getParameterValues(String name) { return this.map.get(name); } } }
并在啟動類上加入@ServletComponentScan注解
補充:springboot 接受大寫參數(shù)時,接收值為空的解決
{ "title":"文章標(biāo)題1", "content":"文章內(nèi)容22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222", "DOI":"123", "PMID":"1234", "email":"121607691@qq.com" }
springboot 接到的DOI和PMID 為null,頭字母改為小寫后正常。
是spring 使用@requestbody 接收時遵循駝峰命名規(guī)則,如果希望接收非駝峰的參數(shù)可以在對映的屬性上添加注解
@JsonProperty(value = "DOI") private String DOI;
關(guān)于怎么在SpringBoot中忽略請求參數(shù)的大小寫就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
標(biāo)題名稱:怎么在SpringBoot中忽略請求參數(shù)的大小寫-創(chuàng)新互聯(lián)
當(dāng)前路徑:http://www.rwnh.cn/article30/cedsso.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄、域名注冊、企業(yè)網(wǎng)站制作、品牌網(wǎng)站制作、網(wǎng)站設(shè)計、全網(wǎng)營銷推廣
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)