Last active
March 21, 2020 08:34
-
-
Save mloza/0c02e59ef24757fd473fe339c51c8638 to your computer and use it in GitHub Desktop.
Kod źródłowy do wpisu Spring Boot Widoki - https://blog.mloza.pl/spring-boot-widoki
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ComponentScan(basePackageClasses = {MainController.class, WebAppConfiguration.class}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>com.lyncode</groupId> | |
<artifactId>jtwig-spring</artifactId> | |
<version>2.1.7</version> | |
</dependency> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@EnableAutoConfiguration | |
@ComponentScan | |
public class Main { | |
public static void main(String[] args) { | |
SpringApplication.run(Main.class); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Controller | |
public class MainController { | |
@RequestMapping("/") | |
public ModelAndView index() { | |
return new ModelAndView("index"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Controller | |
public class MainController { | |
@RequestMapping("/") | |
public ModelAndView index() { | |
ModelAndView modelAndView = new ModelAndView("index"); | |
modelAndView.addObject("greetings", "Hello world from variable!"); | |
modelAndView.addObject("greetingsArray", new String[] {"Hello", "World", "!"}); | |
return modelAndView; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<parent> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-parent</artifactId> | |
<version>1.2.0.RELEASE</version> | |
</parent> | |
<dependencies> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-web</artifactId> | |
</dependency> | |
</dependencies> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Hello World from view!</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h3>{{ greetings }}</h3> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul> | |
{% for i in greetingsArray %} | |
<li>{{ i }}</li> | |
{% endfor %} | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul> | |
{% for i in greetingsArray %} | |
<li>{{ loop.index+1}}. {{ i }}</li> | |
{% endfor %} | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
public class WebAppConfiguration { | |
@Bean | |
public ViewResolver viewResolver() { | |
JtwigViewResolver jtwigViewResolver = new JtwigViewResolver(); | |
jtwigViewResolver.setPrefix("classpath:views/"); | |
jtwigViewResolver.setSuffix(".twig"); | |
return jtwigViewResolver; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment