freemarker获取封装类中对象的属性(六)
freemarker获取封装类中对象的属性
假如你现在还在为自己的技术担忧,假如你现在想提升自己的工资,假如你想在职场上获得更多的话语权,假如你想顺利的度过35岁这个魔咒,假如你想体验BAT的工作环境,那么现在请我们一起开启提升技术之旅吧,详情请点击http://106.12.206.16:8080/qingruihappy/index.html
1、设计思路
(1)封装学生类
(2)创建数据模型
(3)新建student.ftl
(4)运行Junit测试文件,生成HTML文件
2、封装学生类
Student.java:
1 /** 2 * @Title:Student.java 3 * @Package:com.you.freemarker.model 4 * @Description:学生类 5 * @author:Youhaidong(游海东) 6 * @date:2014-5-26 下午11:41:05 7 * @version V1.0 8 */ 9 package com.you.freemarker.model; 10 11 import java.io.Serializable; 12 import java.util.Date; 13 14 /** 15 * 类功能说明 16 * 类修改者 修改日期 17 * 修改说明 18 * <p>Title:Student.java</p> 19 * <p>Description:游海东个人开发</p> 20 * <p>Copyright:Copyright(c)2013</p> 21 * @author:游海东 22 * @date:2014-5-26 下午11:41:05 23 * @version V1.0 24 */ 25 public class Student implements Serializable 26 { 27 /** 28 * @Fields serialVersionUID:序列化 29 */ 30 private static final long serialVersionUID = 1L; 31 32 /** 33 * 学生姓名 34 */ 35 private String studentName; 36 37 /** 38 * 学生性别 39 */ 40 private String studentSex; 41 42 /** 43 * 学生年龄 44 */ 45 private int studentAge; 46 47 /** 48 * 学生生日 49 */ 50 private Date studentBirthday; 51 52 /** 53 * 学生地址 54 */ 55 private String studentAddr; 56 57 /** 58 * QQ 59 */ 60 private long studentQQ; 61 62 /** 63 * @return the studentName 64 */ 65 public String getStudentName() { 66 return studentName; 67 } 68 69 /** 70 * @param studentName the studentName to set 71 */ 72 public void setStudentName(String studentName) { 73 this.studentName = studentName; 74 } 75 76 /** 77 * @return the studentSex 78 */ 79 public String getStudentSex() { 80 return studentSex; 81 } 82 83 /** 84 * @param studentSex the studentSex to set 85 */ 86 public void setStudentSex(String studentSex) { 87 this.studentSex = studentSex; 88 } 89 90 /** 91 * @return the studentAge 92 */ 93 public int getStudentAge() { 94 return studentAge; 95 } 96 97 /** 98 * @param studentAge the studentAge to set 99 */ 100 public void setStudentAge(int studentAge) { 101 this.studentAge = studentAge; 102 } 103 104 /** 105 * @return the studentBirthday 106 */ 107 public Date getStudentBirthday() { 108 return studentBirthday; 109 } 110 111 /** 112 * @param studentBirthday the studentBirthday to set 113 */ 114 public void setStudentBirthday(Date studentBirthday) { 115 this.studentBirthday = studentBirthday; 116 } 117 118 /** 119 * @return the studentAddr 120 */ 121 public String getStudentAddr() { 122 return studentAddr; 123 } 124 125 /** 126 * @param studentAddr the studentAddr to set 127 */ 128 public void setStudentAddr(String studentAddr) { 129 this.studentAddr = studentAddr; 130 } 131 132 /** 133 * @return the studentQQ 134 */ 135 public long getStudentQQ() { 136 return studentQQ; 137 } 138 139 /** 140 * @param studentQQ the studentQQ to set 141 */ 142 public void setStudentQQ(long studentQQ) { 143 this.studentQQ = studentQQ; 144 } 145 146 /** 147 * <p>Title:</p> 148 * <p>Description:无参构造函数</p> 149 */ 150 public Student() { 151 super(); 152 } 153 154 /** 155 * <p>Title:</p> 156 * <p>Description:有参构造函数</p> 157 * @param studentName 158 * @param studentSex 159 * @param studentAge 160 * @param studentBirthday 161 * @param studentAddr 162 * @param studentQQ 163 */ 164 public Student(String studentName, String studentSex, int studentAge, 165 Date studentBirthday, String studentAddr, long studentQQ) { 166 super(); 167 this.studentName = studentName; 168 this.studentSex = studentSex; 169 this.studentAge = studentAge; 170 this.studentBirthday = studentBirthday; 171 this.studentAddr = studentAddr; 172 this.studentQQ = studentQQ; 173 } 174 175 }
3、创建数据模型
1 Map<String,Object> root = null; 2 3 /** 4 * 5 * @Title:testStudent 6 * @Description: 7 * @param: 8 * @return: void 9 * @throws 10 */ 11 @Test 12 public void testStudent() 13 { 14 //创建数据模型 15 root = new HashMap<String,Object>(); 16 root.put("student", new Student("张三丰","男",34,new Date(1988-12-12),"湖北省武汉市武昌洪山区",78451214)); 17 student("student.ftl"); 18 studentFile("student.ftl","student.html"); 19 } 20 21 /** 22 * 23 * @Title:student 24 * @Description: 25 * @param:@param name 26 * @return: void 27 * @throws 28 */ 29 private void student(String name) 30 { 31 ft.printFtl(name,root); 32 } 33 34 /** 35 * 36 * @Title:studentFile 37 * @Description: 38 * @param:@param name 39 * @param:@param fileName 40 * @return: void 41 * @throws 42 */ 43 private void studentFile(String name,String fileName) 44 { 45 ft.printFile(name, root, fileName); 46 }
4、新建student.ftl
student.ftl:
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 2 <html> 3 <head> 4 <title>学生信息</title> 5 6 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 7 <meta http-equiv="description" content="this is my page"> 8 <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 9 10 11 </head> 12 13 <body> 14 姓名:${student.studentName} 15 性别:${student.studentSex} 16 年龄:${student.studentAge} 17 生日:${(student.studentBirthday)?string("yyyy-MM-dd")} 18 地址:${student.studentAddr} 19 QQ:${student.studentQQ} 20 </body> 21 </html>
5、运行Junit测试文件,生成HTML文件
6、控制台输出结果
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 2 <html> 3 <head> 4 <title>学生信息</title> 5 6 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 7 <meta http-equiv="description" content="this is my page"> 8 <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 9 10 11 </head> 12 13 <body> 14 姓名:张三丰 15 性别:男 16 年龄:34 17 生日:1970-01-01 18 地址:湖北省武汉市武昌洪山区 19 QQ:78,451,214 20 </body> 21 </html>
假如你现在还在为自己的技术担忧,假如你现在想提升自己的工资,假如你想在职场上获得更多的话语权,假如你想顺利的度过35岁这个魔咒,假如你想体验BAT的工作环境,那么现在请我们一起开启提升技术之旅吧,详情请点击http://106.12.206.16:8080/qingruihappy/index.html
freemarker获取封装类中对象的属性(六)相关推荐
- 递归——函数在内部自己调用自己,那么该函数是递归函数 作用和循环效果一样 要加推出条件return,否则发生栈溢出,导致死循环 递归给数组中对象添加属性 toString()和随机数
递归--函数在内部自己调用自己,那么该函数是递归函数 & 作用和循环效果一样 & 要加推出条件return,否则发生栈溢出,导致死循环 & 递归给数组中对象添加属性 & ...
- easyui-combobox加载json中对象的属性
这次做项目遇到了一个问题,在easyui-combobox加载json数据中对象的属性.后台返回的json中包含一个对象,而我想调用对象中的属性,后台返回的json如下: {"rows&qu ...
- 根据数组中对象的属性值排序倒叙
数组中对象的属性值排序倒叙demo function compare(e) {return function (a, b) {var value1 = a[e];var value2 = b[e];r ...
- spring五:获取容器中对象信息
// 获取容器中对象信息@Testpublic void test2(){String configLocation = "applicationContext.xml"; // ...
- JS中对象按属性排序(冒泡排序)
原文地址 https://www.cnblogs.com/it-Ren/p/10898947.html 一路向北√ 越努力,越幸运. JS中对象按属性排序(冒泡排序) 冒泡排序:它重复地走访过要排序的 ...
- JS 取Json数据中对象特定属性值
解析JSON JSON 数据 var str = '[{"a": "1","b": "2"}, {"a&quo ...
- 删除javaScript中对象的属性
删除javaScript中对象的属性 语法 delete 对象.属性;
- 细说JavaScript中对象的属性和方法
最近在回家的路上读了尼古拉斯的新书<JavaScript面向对象精要>,发现自己对对象的属性和方法不是很熟悉,特别是es5新增的部分,特写此文总结一下,同时也与大家共勉. 本文分为两部分, ...
- JPA 中对象 set 属性时自动保存
// 查出对象,原来的 name 为 user1 User user = userManager.findOne(1); // 将userName 设置为 user2 ,用于前端显示,并没有保存 us ...
最新文章
- Python基础14-迭代器与生成器
- Spring Cloud Feign 熔断机制填坑
- active server pages 错误 asp 0126_微信小程序全栈开发课程【视频版】2.1 小程序前端页面初始配置、ESlint格式错误...
- 服务器中同一个【ip:port】可以多次accept的问题
- WUTOJ 1284: Gold Medal(Java)
- 华为杨超斌:5G方面领先同行至少12个月到18个月
- 【CodeForces - 589F】Gourmet and Banquet (贪心,思维,二分)
- 定义一个Matrix类,实现矩阵的加法和乘法
- python怎么导入数据集keras_python – 如何为Keras准备数据集?
- 一款小工具DeskPinsEx开发笔记
- css动感线条,使用css3制作动感导航条示例
- 基于表情分析的智能语音陪伴机器人
- 计算机回收站设置大小,电脑怎么设置回收站容量 电脑回收站的数据文件位置在哪...
- CMake入门使用(一)安装及HelloWorld的构建
- 网易邮箱大师代收gmail
- 基因重组-冲刺日志(第四天)
- BUUCTF笔记之Web系列部分WriteUp(三)
- 万能Markdown数学公式
- 吉大计算机学院课外八学分,通知|关于吉林大学课外八学分相关规定
- 服务器2012怎么换桌面背景,Windows Server 2012 R2桌面化详细设置图解
热门文章
- test1---peersim 0
- AI给老照片上色,真的准吗?技术圈和历史圈吵了1000帖
- 数学好=编程能力强?MIT新发现:二者激活大脑区域并不同
- 斯坦福前校长John Hennessy、张亚勤等一众大佬云集,共探最前沿技术 | CNCC2020
- UCLA教授遭到举报后被停课!原因竟是不同意学生主张的“考试放水”
- 每秒处理240万帧游戏画面,AI训练成本降低80%,谷歌开源RL并行计算框架
- 北京自动驾驶提速:华为奥迪图森完成高速测试,百度包揽全部40张载人牌照...
- 谷歌新操作系统Fuchsia网站上线,同时支持手机和PC,鼓励开发者参与进来
- python入门(一):进入python的交互模式、pip的使用和数据类型
- 【git】 重置文件