Skip to content

Instantly share code, notes, and snippets.

View abdioufy's full-sized avatar

abdioufy abdioufy

View GitHub Profile
@abdioufy
abdioufy / CustomRequestMappingHandlerMapping.java
Created October 10, 2023 21:17 — forked from UnquietCode/CustomRequestMappingHandlerMapping.java
Custom implementation of Spring's RequestMappingHandlerMapping which automatically registers a redirect for the same url with (or without) a trailing slash. This is good in cases where for SEO purposes you want 'url' and 'url/' to resolve to the same page.
package com.sb.server.web;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.http.HttpStatus;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.mvc.condition.PatternsRequestCondition;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import org.springframework.web.servlet.view.RedirectView;