springboot怎么整合freemarker模板
springboot怎么整合freemarker模板
今天小编给大家分享一下springboot怎么整合freemarker模板的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。
Freemarker作用于表现层,能更好的实现mvc分离。
1、首先,在pom文件里加入freemarker依赖
<!-- 整合freemarker -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
2、在配置文件application.properties中加入freemarker配置
# freemarker静态资源配置
# 设定ftl文件路径
spring.freemarker.tempalte-loader-path=classpath:/templates
# 关闭缓存,及时刷新,上线生产环境需要修改为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、在public目录下建立freemarker文件夹
4、建立login.ftl文件
[#ftl]<html><head><metacharset="GBK"><title>杭州天纵智能管理平台</title><linkrel="stylesheet"href="../css/layui.css"rel="stylesheet"><linkrel="stylesheet"href="../css/modules/layer/default/layer.css?v=3.1.1"rel="stylesheet"><style>html,body{width:100%;height:100%;margin:0;padding:0;}body{display:flex;align-items:center;/*定义body的元素垂直居中*/justify-content:center;/*定义body的里的元素水平居中*/}</style></head><body><formclass="layui-form"><divclass="layui-form-item"><labelclass="layui-form-label">用户名</label><divclass="layui-input-inline"><inputtype="text"name="userName"lay-verify="required"autocomplete="off"placeholder="请输入用户名称"class="layui-input"></div></div><divclass="layui-form-item"><labelclass="layui-form-label">密码</label><divclass="layui-input-inline"><inputtype="password"name="passWord"lay-verify="required"autocomplete="off"placeholder="请输入密码"class="layui-input"/></div></div><divclass="layui-form-item"><labelclass="layui-form-label"></label><divclass="layui-input-inline"><buttontype="submit"class="layui-btn"lay-submit=""lay-filter="demo1">登录</button></div></div></form><scriptsrc="../js/layui.js"></script><scriptsrc="../js/jquery-1.12.4.js"></script><script>layui.use(['form'],function(){varform=layui.form,layer=layui.layerform.on('submit(demo1)',function(data){$.ajax({url:"/manage/login",type:"get",data:data.field,async:false,success:function(data){if(data>0){alert("登录成功");window.location.href="/index.html";event.preventDefault();}else{alert("登录失败");}},error:function(XMLHttpRequest,textStatus,errorThrown){alert(XMLHttpRequest.status);//状态码alert(XMLHttpRequest.readyState);//状态alert(textStatus);//错误信息}})});});</script></body></html>
5、写controller方法
@RequestMapping(value = "/manage")
@Controller
public class login(){
@RequestMapping(value="login")
public String loginFtl(HttpServletRequest request, HttpServletResponse response){
return "/freemarker/login";
}
}
6、访问localhost:8080/manage/login
以上就是“springboot怎么整合freemarker模板”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注恰卡编程网行业资讯频道。
推荐阅读
-
vue动态添加删除输入框(springboot vue怎么让数据库显示出来)
springbootvue怎么让数据库显示出来?一般情况下是前端调阅后端接口,来获取到数据库的数据,后端哪里会把数据库的数据整理...
-
springboot实现基于aop的切面日志
本文实例为大家分享了springboot实现基于aop的切面日志的具体代码,供大家参考,具体内容如下通过aop的切面方式实现日志...
-
SpringBoot定时任务功能怎么实现
-
SpringBoot中的@Import注解怎么使用
-
SpringBoot整合Lombok及常见问题怎么解决
-
springboot图片验证码功能模块怎么实现
-
Springboot+SpringSecurity怎么实现图片验证码登录
-
SpringBoot注解的知识点有哪些
SpringBoot注解的知识点有哪些这篇“SpringBoot注...
-
SpringBoot2.x中management.security.enabled=false无效怎么解决
-
springboot怎么禁用某项健康检查
springboot怎么禁用某项健康检查今天小编给大家分享一下sp...