In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article shows you how to integrate SpringMVC into freemarker and how to use it. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
1. What is Spring MVC?
SpringMVC is a Java-based lightweight Web framework that implements the request-driven type of Web MVC design pattern. Even if the idea of MVC architecture pattern is used, the responsibility of the Web layer is decoupled. Based on request-driven refers to the use of request-response model, the purpose of SpringMVC framework is to help us simplify development.
Spring MVC implements the core concept of ready-to-use MVC. It provides a large number of functions related to this pattern for controllers and handlers. And when adding inversion control (Inversion of Control,IoC) to MVC, it highly decouples the application, providing the flexibility to dynamically change components with simple configuration changes. Spring MVC provides complete control over all aspects of the application. Spring's Web MVC module is designed around DispatcherServlet. DispatcherServlet dispatches requests to handlers, performs view parsing, handles locale and topic parsing, and also provides support for uploading files.
Spring MVC is a follow-up product of Spring Frame Work and has been integrated into Spring Web Flow. The Spring framework was originally written by Rod Johnson and was first released under the Apache 2.0 license in June 2003.
The Spring MVC framework provides the MVC (Model-View-Controller) architecture and components for developing flexible and loosely coupled Web applications. The MVC pattern results in the separation of different aspects of the application (input logic, business logic, and UI logic) while providing loose coupling between these elements.
The model (Model) encapsulates the application data, which will usually be made up of POJO classes. The view (View) is responsible for rendering the model data and generally generates client-side browsers that can interpret the HTML output. The controller (Controller) is responsible for processing the user's request, building the appropriate model, and passing it to the view for rendering.
Reference: SpringMVC Chinese official website: SpringMVC Chinese official website
2. What is Freemarker
FreeMarker is a template engine written in the Java language that generates text output based on templates. FreeMarker has nothing to do with the Web container, that is, when Web is running, it does not know about Servlet or HTTP. It can not only be used as a presentation layer implementation technology, but also can be used to generate XML,JSP or Java and so on. At present, in enterprises, Freemarker is mainly used for static page or page display.
3. How to use Freemarker
Add the jar package of freemarker to the project, and the Maven project add dependencies
Org.freemarkerfreemarker2.3.23
Contents of springMVC-servlet.xml file:
Contents of applicationContext.xml file:
10zh_CNyyyy-MM-ddyyyy-MM-dd#.##
Sample template file, ftl file, freemarker.ftl
${title} ${content}
Controler example, referencing a template through ModelAndView, using a name without a suffix
@ Controller@RequestMapping ("/ index/") public class FreeMarkerController {private Logger LOGGER = LoggerFactory.getLogger (FreeMarkerController.class); / / @ RequestMapping (value = "test", produces = "text/plain;charset=UTF-8", method = RequestMethod.GET) public ModelAndView freeMarkerTest () {ModelAndView mv = new ModelAndView ("freemarker"); mv.addObject ("title", "Spring MVC And Freemarker"); mv.addObject ("content", "Hello world, This is my first spring mvc!"); return mv;}}
The above content is SpringMVC integration freemarker and how to use it. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
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.