如图所示,寻找解决方案ing
我最近在看源码,已经看到org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(MethodParameter, ModelAndViewContainer, NativeWebRequest, WebDataBinderFactory)了
记下来,下次接着看
看完了,直接上解决方案
/** * */ package com.grc.common.converter; import org.springframework.core.convert.converter.Converter; /** * @author Lille * @time 2021年11月13日 下午4:02:50 */ public class StringToStringArrayConverter implements Converter<String,String[]> { @Override public String[] convert(String source) { if(source==null) { return new String[0]; }else { return new String[] {source}; } } }
/** * */ package red.lille.makecode.configuration; import javax.annotation.Resource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.convert.converter.Converter; import org.springframework.format.FormatterRegistry; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import com.grc.common.converter.StringToStringArrayConverter; import com.grc.common.properties.SysConfig; import com.grc.common.properties.XMLProperties; /** * @author Lille * */ @Configuration @EnableWebMvc public class XmlConfiguration implements WebMvcConfigurer{ @Resource(name = "stringToStringArrayConverter") private Converter<String, String[]> stringToStringArrayConverter; @Bean("stringToStringArrayConverter") public StringToStringArrayConverter getStringToStringArrayConverter() { return new StringToStringArrayConverter(); } @Override public void addFormatters(FormatterRegistry registry) { registry.addConverter(stringToStringArrayConverter); } }