Spring mvc Spring Boot为自定义FreeMarker登录页面发送空json
在SpringBoot中,我为自定义MVC添加了带有@EnableWebMvc注释的@Configuration。它使用src/main/resources/templates下的Freemarker模板。问题是登录页面被作为空json发送回浏览器。我是否需要添加额外的谈判内容或其他内容?ThxSpring mvc Spring Boot为自定义FreeMarker登录页面发送空json,spring-mvc,spring-security,spring-boot,Spring Mvc,Spring Security,Spring Boot,在SpringBoot中,我为自定义MVC添加了带有@EnableWebMvc注释的@Configuration。它使用src/main/resources/templates下的Freemarker模板。问题是登录页面被作为空json发送回浏览器。我是否需要添加额外的谈判内容或其他内容?Thx @Configuration @EnableWebMvc public class WebMvcConfig extends WebMvcConfigurerAdapter { @Bean publi
@Configuration
@EnableWebMvc
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
@Bean
public ContentNegotiatingViewResolver contentViewResolver() throws Exception {
ContentNegotiationManagerFactoryBean contentNegotiationManager = new ContentNegotiationManagerFactoryBean();
contentNegotiationManager.addMediaType("json", MediaType.APPLICATION_JSON);
FreeMarkerViewResolver viewResolver = new FreeMarkerViewResolver();
viewResolver.setPrefix("/templates/");
viewResolver.setSuffix(".ftl");
MappingJackson2JsonView defaultView = new MappingJackson2JsonView();
defaultView.setExtractValueFromSingleKeyModel(true);
ContentNegotiatingViewResolver contentViewResolver = new ContentNegotiatingViewResolver();
contentViewResolver.setContentNegotiationManager(contentNegotiationManager.getObject());
contentViewResolver.setViewResolvers(Arrays.<ViewResolver> asList(viewResolver));
contentViewResolver.setDefaultViews(Arrays.<View> asList(defaultView));
return contentViewResolver;
}
....
登录控制器缺少客户端HTTP GET的适当内容类型设置,因此我添加了这个products属性。
@RequestMapping(value=“/login”,products=“application/xml”)登录控制器缺少客户端HTTP GET的适当内容类型设置,因此我添加了这个products属性。 @请求映射(value=“/login”,products=“application/xml”)
@Controller
@SessionAttributes
public class LoginController {
@RequestMapping("/login")
public String login() {
return "login";
}
}