spring boot 整合freemaker
前端最好使用vue.js
这里是freemaker 整合spring boot
1.编写pom文件:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
</dependencies>
2.编写cotroller:
( 由于要返回模板页面文件,所以我们只能使用@Controller 而不可以使用@RestController)
@RequestMapping("/b")
public String b( Map<String,Object> map) {
Student s1=new Student("a","f",1,"aa");
Student s2=new Student("b","m",2,"bb");
Student s3=new Student("c","m",3,"cc");
Student s4=new Student("d","f",4,"dd");
ArrayList list= new ArrayList();
list.add(s1);
list.add(s2);
list.add(s3);
list.add(s4);
map.put("stu",list);
map.put("name","yangtao");
return "views/b";
}
3.编写页面(使用了bootstrap)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Owsome</title>
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- 可选的 Bootstrap 主题文件(一般不用引入) -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<div class="row">
<h1>Hello,${name}.这是另外一个界面</h1>
<div class="col-md-6" >
<img style="height: 500px " src="/imags/original.jpg" class=".img-responsive img-circle " alt="error">
</div>
<div class="col-md-6">
<div style="height: 100px"></div>
<table >
<table border="1" class="table" >
<tr>
<td>姓名</td>
<td>性别</td>
<td>年龄</td>
<td>地址</td>
</tr>
<#list stu as item>
<tr>
<td>${item.name}</td>
<td>${item.gender}</td>
<td>${item.age}</td>
<td>${item.address}</td>
</tr>
</#list>
</table>
<a href="http://127.0.0.1:8080/c">第三个页面</a>
</div>
</div>
</div>
</body>
</html>
4.编写properties
(也可以使用jsp文件,就是不知它怎么渲染了,先解释成java文件,然后渲染到html 上吗)
spring.freemarker.template-loader-path=classpath:/templates
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=false
spring.freemarker.expose-session-attributes=false
spring.freemarker.request-context-attribute=request
spring.freemarker.suffix=.html
5.编写一个实体类
(必须要有get set 方法)
package com.git.springboot.fontandbacktest.demo.contrllor;
/**
* * @description: TODO
* * @param ${tags}
* * @return ${return_type}
* * @throws
* * @author yangtao
* * @date $date$ $time$
*/
public class Student {
String name;
String gender;
String age;
String address;
public Student( String name, String gender, String age, String address ) {
this.name = name;
this.gender = gender;
this.age = age;
this.address = address;
}
。。。。。
get and set 方法
}
出现过的错误
Tip: It's the step after the last dot that caused this error, not those before it.
----
Tip: If the failing expression is known to legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
----
----
FTL stack trace ("~" means nesting-related):
- Failed at: ${item.name} [in template "views/login.html" at line 39, column 29]
2019-09-04 10:08:55.867 ERROR 1406 --- [nio-8080-exec-1] s.e.ErrorMvcAutoConfiguration$StaticView : Cannot render error page for request [/a] and exception [The following has evaluated to null or missing:
==> item.name [in template "views/login.html" at line 39, column 31]
----
Tip: It's the step after the last dot that caused this error, not those before it.
----
Tip: If the failing expression is known to legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
----
----
FTL stack trace ("~" means nesting-related):
- Failed at: ${item.name} [in template "views/login.html" at line 39, column 29]
----] as the response has already been committed. As a result, the response may have the wrong status code.
解决办法,必须使用get and set 方法
spring boot 整合freemaker的更多相关文章
- Spring Boot 整合 Elasticsearch,实现 function score query 权重分查询
摘要: 原创出处 www.bysocket.com 「泥瓦匠BYSocket 」欢迎转载,保留摘要,谢谢! 『 预见未来最好的方式就是亲手创造未来 – <史蒂夫·乔布斯传> 』 运行环境: ...
- spring boot整合jsp的那些坑(spring boot 学习笔记之三)
Spring Boot 整合 Jsp 步骤: 1.新建一个spring boot项目 2.修改pom文件 <dependency> <groupId>or ...
- spring boot 系列之四:spring boot 整合JPA
上一篇我们讲了spring boot 整合JdbcTemplate来进行数据的持久化, 这篇我们来说下怎么通过spring boot 整合JPA来实现数据的持久化. 一.代码实现 修改pom,引入依赖 ...
- Spring Kafka和Spring Boot整合实现消息发送与消费简单案例
本文主要分享下Spring Boot和Spring Kafka如何配置整合,实现发送和接收来自Spring Kafka的消息. 先前我已经分享了Kafka的基本介绍与集群环境搭建方法.关于Kafka的 ...
- Spring Boot整合Mybatis并完成CRUD操作
MyBatis 是一款优秀的持久层框架,被各大互联网公司使用,本文使用Spring Boot整合Mybatis,并完成CRUD操作. 为什么要使用Mybatis?我们需要掌握Mybatis吗? 说的官 ...
- spring boot整合Hadoop
最近需要用spring boot + mybatis整合hadoop,其中也有碰到一些坑,记录下来方便后面的人少走些弯路. 背景呢是因为需要在 web 中上传文件到 hdfs ,所以需要在spring ...
- Spring Boot整合Elasticsearch
Spring Boot整合Elasticsearch Elasticsearch是一个全文搜索引擎,专门用于处理大型数据集.根据描述,自然而然使用它来存储和搜索应用程序日志.与Logstash和K ...
- Spring Security 整合freemaker 实现简单登录和角色控制
Spring Security 整合freemaker 实现简单登录和角色控制 写这篇文章是因为我做了一个电商网站项目,近期刚加上权限控制.整个过程很简单,在此给大家梳理一下,也算是自己对知识 ...
- spring boot 整合 百度ueditor富文本
百度的富文本没有提供Java版本的,只给提供了jsp版本,但是呢spring boot 如果是使用内置tomcat启动的话整合jsp是非常困难得,今天小编给大家带来spring boot整合百度富文本 ...
随机推荐
- Python--day71--分页功能
分页功能代码: from django.shortcuts import render # Create your views here. from app01 import models def b ...
- NGINX比Apache的性能高是因为NGINX由C语言开发,而Apache由C++开发
事实上,NGINX比Apache的性能高是因为NGINX由C语言开发,而Apache由C++开发.因此,NGINX效率大概是Apache的10倍左右
- centos linux mysql 10060远程错误代码
Navicat for MySQL远程连接数据错误代码10060 1.登陆远程linux服务器命令界面 vim /etc/sysconfig/iptables 进入防火墙配置修改 增加以下两条防火墙 ...
- Python--day40--全局解释器锁
1,起一百个线程和起一百个进程所花的时间对比(开启效率的较量): import time from threading import Thread from multiprocessing impor ...
- css 百分比继承关系的探讨
引入:近日在回顾css基础的时候发现了一个有趣的问题,就是css在继承百分比类属性的时候是继承百分比后再根据父级宽高计算,还是继承父级根据百分比计算过后的绝对值.下面举一个简单的例子来描述这一个问题, ...
- MySQL中Index Merge简介
索引合并优化 官网翻译 MySQL5.7文档 索引合并是为了减少几个范围(type中的range类型:range can be used when a key column is compared t ...
- QQ三方登录
申请了十天,最终通过了审核,能够上线了,事实上申请的第一天,站点的qq登录已经做好了,而且能够用測试帐号登录,但提交审核后,总是通只是,提示:您的站点审核未通过.原因是"未放置QQ登录but ...
- 分布式全局唯一ID
方案一.UUID UUID的方式能生成一串唯一随机32位长度数据,它是无序的一串数据,按照开放软件基金会(OSF)制定的标准计算,UUID的生成用到了以太网卡地址.纳秒级时间.芯片ID码和许多可能的数 ...
- UVa 10603 Fill [暴力枚举、路径搜索]
10603 Fill There are three jugs with a volume of a, b and c liters. (a, b, and c are positive intege ...
- java笔试题及其答案
1:下列哪个工具可以编译源文件(A) A:javac B:jdb C:javadoc D:junit 2:String b = new String("1"+"2&quo ...