formatting work
This commit is contained in:
+19
-19
@@ -11,28 +11,28 @@ import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
|
||||
|
||||
@EnableWebMvc
|
||||
@Configuration
|
||||
@ComponentScan({"com.baeldung.freemarker"})
|
||||
@ComponentScan({ "com.baeldung.freemarker" })
|
||||
public class SpringWebConfig extends WebMvcConfigurerAdapter {
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
|
||||
}
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FreeMarkerViewResolver freemarkerViewResolver() {
|
||||
FreeMarkerViewResolver resolver = new FreeMarkerViewResolver();
|
||||
resolver.setCache(true);
|
||||
resolver.setPrefix("");
|
||||
resolver.setSuffix(".ftl");
|
||||
return resolver;
|
||||
}
|
||||
@Bean
|
||||
public FreeMarkerViewResolver freemarkerViewResolver() {
|
||||
FreeMarkerViewResolver resolver = new FreeMarkerViewResolver();
|
||||
resolver.setCache(true);
|
||||
resolver.setPrefix("");
|
||||
resolver.setSuffix(".ftl");
|
||||
return resolver;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FreeMarkerConfigurer freemarkerConfig() {
|
||||
FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer();
|
||||
freeMarkerConfigurer.setTemplateLoaderPath("/WEB-INF/views/ftl/");
|
||||
return freeMarkerConfigurer;
|
||||
}
|
||||
@Bean
|
||||
public FreeMarkerConfigurer freemarkerConfig() {
|
||||
FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer();
|
||||
freeMarkerConfigurer.setTemplateLoaderPath("/WEB-INF/views/ftl/");
|
||||
return freeMarkerConfigurer;
|
||||
}
|
||||
|
||||
}
|
||||
+12
-12
@@ -4,19 +4,19 @@ import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatche
|
||||
|
||||
public class WebConfiguration extends AbstractAnnotationConfigDispatcherServletInitializer {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getServletConfigClasses() {
|
||||
return new Class[] { SpringWebConfig.class };
|
||||
}
|
||||
@Override
|
||||
protected Class<?>[] getServletConfigClasses() {
|
||||
return new Class[] { SpringWebConfig.class };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getServletMappings() {
|
||||
return new String[] { "/" };
|
||||
}
|
||||
@Override
|
||||
protected String[] getServletMappings() {
|
||||
return new String[] { "/" };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getRootConfigClasses() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
protected Class<?>[] getRootConfigClasses() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+24
-26
@@ -16,33 +16,31 @@ import com.baeldung.freemarker.model.Car;
|
||||
@Controller
|
||||
public class SpringController {
|
||||
|
||||
private static List<Car> carList = new ArrayList<Car>();
|
||||
|
||||
@RequestMapping(value = "/", method = RequestMethod.GET)
|
||||
public String home(Locale locale, Model model) {
|
||||
return "redirect:/cars";
|
||||
}
|
||||
|
||||
static {
|
||||
carList.add(new Car("Honda", "Civic"));
|
||||
carList.add(new Car("Toyota", "Camry"));
|
||||
carList.add(new Car("Nissan", "Altima"));
|
||||
}
|
||||
private static List<Car> carList = new ArrayList<Car>();
|
||||
|
||||
@RequestMapping(value = "/", method = RequestMethod.GET)
|
||||
public String home(Locale locale, Model model) {
|
||||
return "redirect:/cars";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/cars", method = RequestMethod.GET)
|
||||
public String init(@ModelAttribute("model") ModelMap model) {
|
||||
model.addAttribute("carList", carList);
|
||||
return "index";
|
||||
}
|
||||
static {
|
||||
carList.add(new Car("Honda", "Civic"));
|
||||
carList.add(new Car("Toyota", "Camry"));
|
||||
carList.add(new Car("Nissan", "Altima"));
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/cars", method = RequestMethod.GET)
|
||||
public String init(@ModelAttribute("model") ModelMap model) {
|
||||
model.addAttribute("carList", carList);
|
||||
return "index";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/add", method = RequestMethod.POST)
|
||||
public String addCar(@ModelAttribute("car") Car car) {
|
||||
if (null != car && null != car.getMake() && null != car.getModel() && !car.getMake().isEmpty() && !car.getModel().isEmpty()) {
|
||||
carList.add(car);
|
||||
}
|
||||
return "redirect:/cars";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/add", method = RequestMethod.POST)
|
||||
public String addCar(@ModelAttribute("car") Car car) {
|
||||
if (null != car && null != car.getMake() && null != car.getModel()
|
||||
&& !car.getMake().isEmpty() && !car.getModel().isEmpty()) {
|
||||
carList.add(car);
|
||||
}
|
||||
return "redirect:/cars";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,32 +2,32 @@ package com.baeldung.freemarker.model;
|
||||
|
||||
public class Car {
|
||||
|
||||
private String make;
|
||||
private String model;
|
||||
|
||||
public Car(){
|
||||
|
||||
}
|
||||
|
||||
public Car(String make, String model) {
|
||||
this.make = make;
|
||||
private String make;
|
||||
private String model;
|
||||
|
||||
public Car() {
|
||||
|
||||
}
|
||||
|
||||
public Car(String make, String model) {
|
||||
this.make = make;
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
public String getMake() {
|
||||
return make;
|
||||
}
|
||||
public String getMake() {
|
||||
return make;
|
||||
}
|
||||
|
||||
public void setMake(String make) {
|
||||
this.make = make;
|
||||
}
|
||||
public void setMake(String make) {
|
||||
this.make = make;
|
||||
}
|
||||
|
||||
public String getModel() {
|
||||
return model;
|
||||
}
|
||||
public String getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
public void setModel(String model) {
|
||||
this.model = model;
|
||||
}
|
||||
public void setModel(String model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user