minor formatting work
This commit is contained in:
parent
06adf29a93
commit
8bd5e12207
@ -25,69 +25,69 @@ import org.thymeleaf.templateresolver.ServletContextTemplateResolver;
|
|||||||
@Configuration
|
@Configuration
|
||||||
public class ClientWebConfig extends WebMvcConfigurerAdapter {
|
public class ClientWebConfig extends WebMvcConfigurerAdapter {
|
||||||
|
|
||||||
public ClientWebConfig() {
|
public ClientWebConfig() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
// API
|
// API
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addViewControllers(final ViewControllerRegistry registry) {
|
public void addViewControllers(final ViewControllerRegistry registry) {
|
||||||
super.addViewControllers(registry);
|
super.addViewControllers(registry);
|
||||||
|
|
||||||
registry.addViewController("/sample.html");
|
registry.addViewController("/sample.html");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ViewResolver thymeleafViewResolver() {
|
public ViewResolver thymeleafViewResolver() {
|
||||||
final ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
|
final ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
|
||||||
viewResolver.setTemplateEngine(templateEngine());
|
viewResolver.setTemplateEngine(templateEngine());
|
||||||
viewResolver.setOrder(1);
|
viewResolver.setOrder(1);
|
||||||
return viewResolver;
|
return viewResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ViewResolver viewResolver() {
|
public ViewResolver viewResolver() {
|
||||||
final InternalResourceViewResolver bean = new InternalResourceViewResolver();
|
final InternalResourceViewResolver bean = new InternalResourceViewResolver();
|
||||||
bean.setViewClass(JstlView.class);
|
bean.setViewClass(JstlView.class);
|
||||||
bean.setPrefix("/WEB-INF/view/");
|
bean.setPrefix("/WEB-INF/view/");
|
||||||
bean.setSuffix(".jsp");
|
bean.setSuffix(".jsp");
|
||||||
bean.setOrder(0);
|
bean.setOrder(0);
|
||||||
return bean;
|
return bean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@Description("Thymeleaf template resolver serving HTML 5")
|
@Description("Thymeleaf template resolver serving HTML 5")
|
||||||
public ServletContextTemplateResolver templateResolver() {
|
public ServletContextTemplateResolver templateResolver() {
|
||||||
final ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver();
|
final ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver();
|
||||||
templateResolver.setPrefix("/WEB-INF/templates/");
|
templateResolver.setPrefix("/WEB-INF/templates/");
|
||||||
templateResolver.setSuffix(".html");
|
templateResolver.setSuffix(".html");
|
||||||
templateResolver.setTemplateMode("HTML5");
|
templateResolver.setTemplateMode("HTML5");
|
||||||
return templateResolver;
|
return templateResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@Description("Thymeleaf template engine with Spring integration")
|
@Description("Thymeleaf template engine with Spring integration")
|
||||||
public SpringTemplateEngine templateEngine() {
|
public SpringTemplateEngine templateEngine() {
|
||||||
final SpringTemplateEngine templateEngine = new SpringTemplateEngine();
|
final SpringTemplateEngine templateEngine = new SpringTemplateEngine();
|
||||||
templateEngine.setTemplateResolver(templateResolver());
|
templateEngine.setTemplateResolver(templateResolver());
|
||||||
final Set<IDialect> dialects = new HashSet<>();
|
final Set<IDialect> dialects = new HashSet<>();
|
||||||
dialects.add(new CustomDialect());
|
dialects.add(new CustomDialect());
|
||||||
templateEngine.setAdditionalDialects(dialects);
|
templateEngine.setAdditionalDialects(dialects);
|
||||||
return templateEngine;
|
return templateEngine;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@Description("Spring message resolver")
|
@Description("Spring message resolver")
|
||||||
public MessageSource messageSource() {
|
public MessageSource messageSource() {
|
||||||
final ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
|
final ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
|
||||||
messageSource.setBasename("messages");
|
messageSource.setBasename("messages");
|
||||||
return messageSource;
|
return messageSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
|
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
|
||||||
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
|
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -23,14 +23,8 @@ public class ContentManagementWebConfig extends WebMvcConfigurerAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configureContentNegotiation(final ContentNegotiationConfigurer configurer) {
|
public void configureContentNegotiation(final ContentNegotiationConfigurer configurer) {
|
||||||
configurer.favorPathExtension(false).
|
configurer.favorPathExtension(false).favorParameter(true).parameterName("mediaType").ignoreAcceptHeader(true).useJaf(false).defaultContentType(MediaType.APPLICATION_JSON).mediaType("xml", MediaType.APPLICATION_XML).mediaType("json",
|
||||||
favorParameter(true).
|
MediaType.APPLICATION_JSON);
|
||||||
parameterName("mediaType").
|
|
||||||
ignoreAcceptHeader(true).
|
|
||||||
useJaf(false).
|
|
||||||
defaultContentType(MediaType.APPLICATION_JSON).
|
|
||||||
mediaType("xml", MediaType.APPLICATION_XML).
|
|
||||||
mediaType("json", MediaType.APPLICATION_JSON);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -14,37 +14,37 @@ import org.springframework.web.servlet.DispatcherServlet;
|
|||||||
|
|
||||||
public class MainWebAppInitializer implements WebApplicationInitializer {
|
public class MainWebAppInitializer implements WebApplicationInitializer {
|
||||||
|
|
||||||
private static final String TMP_FOLDER = "C:/Users/ivan/Desktop/tmp";
|
private static final String TMP_FOLDER = "C:/Users/ivan/Desktop/tmp";
|
||||||
private static final int MAX_UPLOAD_SIZE = 5 * 1024 * 1024; // 5 MB
|
private static final int MAX_UPLOAD_SIZE = 5 * 1024 * 1024; // 5 MB
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register and configure all Servlet container components necessary to power the web application.
|
* Register and configure all Servlet container components necessary to power the web application.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onStartup(final ServletContext sc) throws ServletException {
|
public void onStartup(final ServletContext sc) throws ServletException {
|
||||||
|
|
||||||
// Create the 'root' Spring application context
|
// Create the 'root' Spring application context
|
||||||
final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
|
final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
|
||||||
root.scan("com.baeldung.spring.web.config");
|
root.scan("com.baeldung.spring.web.config");
|
||||||
// root.getEnvironment().setDefaultProfiles("embedded");
|
// root.getEnvironment().setDefaultProfiles("embedded");
|
||||||
|
|
||||||
// Manages the lifecycle of the root application context
|
// Manages the lifecycle of the root application context
|
||||||
sc.addListener(new ContextLoaderListener(root));
|
sc.addListener(new ContextLoaderListener(root));
|
||||||
|
|
||||||
// Handles requests into the application
|
// Handles requests into the application
|
||||||
final ServletRegistration.Dynamic appServlet = sc.addServlet("mvc", new DispatcherServlet(new GenericWebApplicationContext()));
|
final ServletRegistration.Dynamic appServlet = sc.addServlet("mvc", new DispatcherServlet(new GenericWebApplicationContext()));
|
||||||
appServlet.setLoadOnStartup(1);
|
appServlet.setLoadOnStartup(1);
|
||||||
|
|
||||||
// final MultipartConfigElement multipartConfigElement = new
|
// final MultipartConfigElement multipartConfigElement = new
|
||||||
// MultipartConfigElement(TMP_FOLDER, MAX_UPLOAD_SIZE,
|
// MultipartConfigElement(TMP_FOLDER, MAX_UPLOAD_SIZE,
|
||||||
// MAX_UPLOAD_SIZE * 2, MAX_UPLOAD_SIZE / 2);
|
// MAX_UPLOAD_SIZE * 2, MAX_UPLOAD_SIZE / 2);
|
||||||
//
|
//
|
||||||
// appServlet.setMultipartConfig(multipartConfigElement);
|
// appServlet.setMultipartConfig(multipartConfigElement);
|
||||||
|
|
||||||
final Set<String> mappingConflicts = appServlet.addMapping("/");
|
final Set<String> mappingConflicts = appServlet.addMapping("/");
|
||||||
if (!mappingConflicts.isEmpty()) {
|
if (!mappingConflicts.isEmpty()) {
|
||||||
throw new IllegalStateException("'appServlet' could not be mapped to '/' due " + "to an existing mapping. This is a known issue under Tomcat versions " + "<= 7.0.14; see https://issues.apache.org/bugzilla/show_bug.cgi?id=51278");
|
throw new IllegalStateException("'appServlet' could not be mapped to '/' due " + "to an existing mapping. This is a known issue under Tomcat versions " + "<= 7.0.14; see https://issues.apache.org/bugzilla/show_bug.cgi?id=51278");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,19 +23,19 @@ public class WebConfig extends WebMvcConfigurerAdapter {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Bean
|
// @Bean
|
||||||
// public StandardServletMultipartResolver multipartResolver() {
|
// public StandardServletMultipartResolver multipartResolver() {
|
||||||
// return new StandardServletMultipartResolver();
|
// return new StandardServletMultipartResolver();
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@Bean(name = "multipartResolver")
|
@Bean(name = "multipartResolver")
|
||||||
public CommonsMultipartResolver multipartResolver() {
|
public CommonsMultipartResolver multipartResolver() {
|
||||||
|
|
||||||
final CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
|
final CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
|
||||||
multipartResolver.setMaxUploadSize(100000);
|
multipartResolver.setMaxUploadSize(100000);
|
||||||
|
|
||||||
return multipartResolver;
|
return multipartResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addViewControllers(final ViewControllerRegistry registry) {
|
public void addViewControllers(final ViewControllerRegistry registry) {
|
||||||
|
@ -10,23 +10,23 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
@Controller
|
@Controller
|
||||||
public class FileUploadController {
|
public class FileUploadController {
|
||||||
|
|
||||||
@RequestMapping(value = "/fileUpload", method = RequestMethod.GET)
|
@RequestMapping(value = "/fileUpload", method = RequestMethod.GET)
|
||||||
public String displayForm() {
|
public String displayForm() {
|
||||||
|
|
||||||
return "fileUploadForm";
|
return "fileUploadForm";
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
|
@RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
|
||||||
public String submit(@RequestParam("file") final MultipartFile file, final ModelMap modelMap) {
|
public String submit(@RequestParam("file") final MultipartFile file, final ModelMap modelMap) {
|
||||||
|
|
||||||
modelMap.addAttribute("file", file);
|
modelMap.addAttribute("file", file);
|
||||||
return "fileUploadView";
|
return "fileUploadView";
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/uploadMultiFile", method = RequestMethod.POST)
|
@RequestMapping(value = "/uploadMultiFile", method = RequestMethod.POST)
|
||||||
public String submit(@RequestParam("files") final MultipartFile[] files, final ModelMap modelMap) {
|
public String submit(@RequestParam("files") final MultipartFile[] files, final ModelMap modelMap) {
|
||||||
|
|
||||||
modelMap.addAttribute("files", files);
|
modelMap.addAttribute("files", files);
|
||||||
return "fileUploadView";
|
return "fileUploadView";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user