0

Подключаем Freemarker

This commit is contained in:
2017-04-09 22:43:56 +03:00
parent f206f03133
commit 8fee91a915
4 changed files with 53 additions and 3 deletions

View File

@@ -8,6 +8,9 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
@Configuration
@PropertySource("classpath:/application.properties")
@@ -16,4 +19,19 @@ public class SpringConfig {
public WebApp webapp(@Value("${webapp.host}") String host, @Value("${webapp.port}") int port) {
return new WebApp(host, port);
}
@Bean
public ViewResolver viewResolver() {
FreeMarkerViewResolver viewResolver = new FreeMarkerViewResolver();
viewResolver.setCache(true);
viewResolver.setSuffix(".ftl");
return viewResolver;
}
@Bean
public FreeMarkerConfigurer freemarkerConfig() {
FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer();
freeMarkerConfigurer.setTemplateLoaderPath("classpath:/kinosearch/kinosearch3/webpp/");
return freeMarkerConfigurer;
}
}

View File

@@ -4,16 +4,30 @@
*/
package kinosearch.kinosearch3.webpp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@Controller
public class WebAppController {
private final Logger logger = LoggerFactory.getLogger(WebAppController.class);
@RequestMapping(value = "/", method = RequestMethod.GET)
@ResponseBody
public String hello() {
return "hello...?";
return "index";
}
@RequestMapping(value = "/favicon.ico")
public void favicon(HttpServletResponse response) {
try {
response.sendError(404);
} catch (IOException e) {
logger.error("favicon 404", e);
}
}
}