In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "spring how to configure the view parser of multi-view implementation". In daily operation, I believe that many people have doubts about how to configure the view parser of multi-view implementation in spring. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubt of "how to configure the view parser of multi-view implementation by spring". Next, please follow the editor to study!
Step 1. Create a new ViewResolverConfiguration
/ * bean instances related to view parsers that mainly configure multi-view implementations * * https://www.it399.com/** actually lies in two key points: * 1, configure order attribute * 2, configure viewnames attribute * * Note: * return new ModelAndView ("jsps/index"); / / or return "jsps/index" * corresponding / WEB-INF/jsps/index.jsp* = = * similarly: * return "thymeleaf/index" / / or return "thymeleaf/index" * corresponds to / WEB-INF/thymeleaf/index.html***/@Configurationpublic class ViewResolverConfiguration {@ Configuration / / to define bean @ EnableWebMvc @ ComponentScan ("com.csy.spring") public class WebConfig extends WebMvcConfigurerAdapter {@ Bean public ViewResolver viewResolver () {InternalResourceViewResolver resolver = new InternalResourceViewResolver (); / / resolver.setPrefix ("/ WEB-INF/") in the context of a DispatcherServlet application. / / resolver.setSuffix (".jsp"); / / resolver.setViewNames ("jsps/*"); resolver.setPrefix ("/"); resolver.setSuffix (".jsp"); resolver.setViewNames ("*"); resolver.setOrder (2); return resolver } @ Bean public ITemplateResolver templateResolver () {SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver (); templateResolver.setTemplateMode ("HTML5"); templateResolver.setPrefix ("/ templates/"); templateResolver.setSuffix (".html"); templateResolver.setCharacterEncoding ("utf-8"); templateResolver.setCacheable (false); return templateResolver @ Bean public SpringTemplateEngine templateEngine () {SpringTemplateEngine templateEngine = new SpringTemplateEngine (); templateEngine.setTemplateResolver (templateResolver ()); / / templateEngine return templateEngine;} @ Bean public ThymeleafViewResolver viewResolverThymeLeaf () {ThymeleafViewResolver viewResolver = new ThymeleafViewResolver (); viewResolver.setTemplateEngine (templateEngine ()) ViewResolver.setCharacterEncoding ("utf-8"); viewResolver.setOrder (1); / / viewResolver.setViewNames (new String [] {"thyme/*"}); viewResolver.setViewNames (new String [] {"thymeleaf/*", "vue/*"}); return viewResolver } @ Override public void configureDefaultServletHandling (DefaultServletHandlerConfigurer configurer) {configurer.enable ();} @ Override public void addResourceHandlers (ResourceHandlerRegistry registry) {super.addResourceHandlers (registry);}
Step 2. Test the class:
@ Controllerpublic class IndexController {@ GetMapping ("/ testJsp") public String testJsp (Model model) {model.addAttribute ("message", "this is index jsp page"); return "index";} @ GetMapping ("/ testThemleaf") public String testThemleaf (Model model) {model.addAttribute ("message", "this is index jsp page"); return "thymeleaf/test" } @ GetMapping ("/ testVue") public String testVue (Model model) {model.addAttribute ("message", "this is index jsp page"); return "vue/testVue";}}
Jsp page https://www.it399.com/index.jsp
Thymeleaf template Page https://www.it399.com/blog/web/201805031726
The page https://www.it399.com/blog/web/Web201805041746 built by vue
All display normally.
At this point, the study on "how spring configures the view parser for multi-view implementation" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.