add jade engine example (#2365)

* add jade engine example

* formatting
This commit is contained in:
lor6
2017-08-03 19:47:25 +03:00
committed by Grzegorz Piwowarek
parent 8e9c36c98e
commit 71f1a2bc44
5 changed files with 65 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
package com.baeldung.spring.configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import de.neuland.jade4j.JadeConfiguration;
import de.neuland.jade4j.spring.template.SpringTemplateLoader;
import de.neuland.jade4j.spring.view.JadeViewResolver;
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = { "com.baeldung.springmvcforms", "com.baeldung.spring.controller", "com.baeldung.spring.validator" })
public class JadeTemplateConfiguration {
@Bean
public SpringTemplateLoader templateLoader() {
SpringTemplateLoader templateLoader = new SpringTemplateLoader();
templateLoader.setBasePath("/WEB-INF/views/");
templateLoader.setSuffix(".jade");
return templateLoader;
}
@Bean
public JadeConfiguration jadeConfiguration() {
JadeConfiguration configuration = new JadeConfiguration();
configuration.setCaching(false);
configuration.setTemplateLoader(templateLoader());
return configuration;
}
@Bean
public ViewResolver viewResolver() {
JadeViewResolver viewResolver = new JadeViewResolver();
viewResolver.setConfiguration(jadeConfiguration());
return viewResolver;
}
}

View File

@@ -18,6 +18,7 @@ public class WebInitializer implements WebApplicationInitializer {
//ctx.register(ThymeleafConfiguration.class);
//ctx.register(FreemarkerConfiguration.class);
//ctx.register(GroovyConfiguration.class);
//ctx.register(JadeTemplateConfiguration.class);
ctx.setServletContext(container);
// Manage the lifecycle of the root application context

View File

@@ -35,6 +35,12 @@ public class UserController {
return "registration-groovy";
}
@GetMapping("/registration-jade")
public String getRegistrationJade(Model model) {
model.addAttribute("user", new User());
return "registration-jade";
}
@PostMapping("/register")
@ResponseBody
public void register(User user){