//解决重写Controller, 方法参数返回值不一致的问题,
//解决办法就是如果子类中有相同路径的url接口那么就不映射父类的url接口了
public class PathTweakingRequestMappingHandlerMapping extends RequestMappingHandlerMapping {
//handlerType.equals(ParentclassController.class) || handlerType.equals(SubclassController.class)
@Override
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
RequestMappingInfo methodMapping = super.getMappingForMethod(method, handlerType);
if (methodMapping==null) {
return methodMapping;
}
Map<RequestMappingInfo, HandlerMethod> handlerMethods = super.getHandlerMethods();
for (Map.Entry<RequestMappingInfo, HandlerMethod> requestMappingInfoHandlerMethodEntry : handlerMethods.entrySet()) {
for (String pattern : requestMappingInfoHandlerMethodEntry.getKey().getPatternsCondition().getPatterns()) {
for (String s : methodMapping.getPatternsCondition().getPatterns()) {
if (pattern.equals(s)) { //发现有重复的
//删除原来的
super.unregisterMapping(requestMappingInfoHandlerMethodEntry.getKey());
return null;
}
}
}
}
return methodMapping;
}
}
package com.schemautils.config;
import com.schemautils.PathTweakingRequestMappingHandlerMapping;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations;
import org.springframework.context.annotation.Configuration;
@Configuration
public class WebMvcRegistrationsConfig implements WebMvcRegistrations {
@Override
public PathTweakingRequestMappingHandlerMapping getRequestMappingHandlerMapping() {
return new PathTweakingRequestMappingHandlerMapping();
}
}
Ambiguous mapping(模糊映射)
小白的报错日常
Ambiguous mapping Ambiguous mapping. Cannot map 'customerController' method public com.cdmtc.model.CommonResult com.cdmtc.controller.CustomerController.insert(com.cdmtc.model.Customer) to {[/insert],methods=[POST]}: There is already 'baseInfoController' bean method public org.springframework.http.ResponseEntity<com.cdmtc.model.modelui.ResponseResult> com.cdmtc.controller.BaseInfoController.insert(com.cdmtc.model.BaseInfo) mapped.
//解决重写Controller, 方法参数返回值不一致的问题,
//解决办法就是如果子类中有相同路径的url接口那么就不映射父类的url接口了
public class PathTweakingRequestMappingHandlerMapping extends RequestMappingHandlerMapping {
//handlerType.equals(ParentclassController.class) || handlerType.equals(SubclassController.class)
@Override
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
RequestMappingInfo methodMapping = super.getMappingForMethod(method, handlerType);
if (methodMapping==null) {
return methodMapping;
}
Map<RequestMappingInfo, HandlerMethod> handlerMethods = super.getHandlerMethods();
for (Map.Entry<RequestMappingInfo, HandlerMethod> requestMappingInfoHandlerMethodEntry : handlerMethods.entrySet()) {
for (String pattern : requestMappingInfoHandlerMethodEntry.getKey().getPatternsCondition().getPatterns()) {
for (String s : methodMapping.getPatternsCondition().getPatterns()) {
if (pattern.equals(s)) { //发现有重复的
//删除原来的
super.unregisterMapping(requestMappingInfoHandlerMethodEntry.getKey());
return null;
}
}
}
}
return methodMapping;
}
}
package com.schemautils.config;
import com.schemautils.PathTweakingRequestMappingHandlerMapping;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations;
import org.springframework.context.annotation.Configuration;
@Configuration
public class WebMvcRegistrationsConfig implements WebMvcRegistrations {
@Override
public PathTweakingRequestMappingHandlerMapping getRequestMappingHandlerMapping() {
return new PathTweakingRequestMappingHandlerMapping();
}
}
Ambiguous mapping(模糊映射)
小白的报错日常
Ambiguous mapping Ambiguous mapping. Cannot map 'customerController' method public com.cdmtc.model.CommonResult com.cdmtc.controller.CustomerController.insert(com.cdmtc.model.Customer) to {[/insert],methods=[POST]}: There is already 'baseInfoController' bean method public org.springframework.http.ResponseEntity<com.cdmtc.model.modelui.ResponseResult> com.cdmtc.controller.BaseInfoController.insert(com.cdmtc.model.BaseInfo) mapped.