In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, the editor will share with you the relevant knowledge points about how springboot integrates the freemarker template. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
Freemarker acts on the presentation layer, which can better achieve mvc separation.
1. First, add the freemarker dependency in the pom file
Org.springframework.boot
Spring-boot-starter-freemarker
2. Add freemarker configuration to the configuration file application.properties
# freemarker static resource configuration
# set ftl file path
Spring.freemarker.tempalte-loader-path=classpath:/templates
# disable the cache and refresh it in a timely manner. The online production environment needs to be modified to true
Spring.freemarker.cache=false
Spring.freemarker.charset=UTF-8
Spring.freemarker.check-template-location=true
Spring.freemarker.content-type=text/html
Spring.freemarker.expose-request-attributes=true
Spring.freemarker.expose-session-attributes=true
Spring.freemarker.request-context-attribute=request
Spring.freemarker.suffix=.ftl
3. Set up a freemarker folder under the public directory. 4. Establish a login.ftl file [# ftl] Hangzhou Tianzhong Intelligent Management platform html,body {width: 100%; height: 100%; margin: 0; padding: 0;} body {display: flex Align-items: center; / * defines the vertical center of the element of body * / justify-content: center / * define the horizontal center of elements in body * /} username password Log in to layui.use (['form']) Function () {var form = layui.form, layer = layui.layer form.on ('submit (demo1)', function (data) {$.ajax ({url: "/ manage/login", type: "get", data: data.field, async: false Success: function (data) {if (data > 0) {alert ("login successful") _ window.location.href= "/ index.html"; event.preventDefault ();} else {alert ("login failed") }, error:function (XMLHttpRequest, textStatus, errorThrown) {alert (XMLHttpRequest.status); / / status code alert (XMLHttpRequest.readyState); / / status alert (textStatus); / / error message}}) ); 5. Write controller method
@ RequestMapping (value = "/ manage")
@ Controller
Public class login () {
@ RequestMapping (value= "login")
Public String loginFtl (HttpServletRequest request, HttpServletResponse response) {
Return "/ freemarker/login"
}
}
6. Visit localhost:8080/manage/login
These are all the contents of the article "how springboot integrates freemarker templates". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to 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.