这两天用freemarker生成静态页面,顺手做个笔记,以免以后忘记

这篇博客记录了作者使用Freemarker生成静态页面的过程,包括Java目录中模板文件的设置,详细介绍了freemarker模版文件index_jsp_v2.flt的内容,并提供了相应的Java代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1:Java 目录(模版文件)

2:freemarker模版文件:index_jsp_v2.flt

 

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="../include/base.inc" %><%response.setHeader("Pragma","No-cache");response.setHeader("Cache-Control","no-cache");response.setDateHeader("Expires", -10);%>

<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="renderer" content="webkit">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<meta name="keywords" content="*****" />
		<meta name="description" content="******" />
		<link type="image/x-icon" href="favicon.ico" rel="shortcut icon" />
		<link href="favicon.ico" rel="bookmark icon" />
		<title>***</title>
		<%@ include file="../include/indexheadlink.inc" %>
		<link type="text/css" rel="stylesheet" href="${r'${ctx}'}/view/xweb/xsyr/xuilib/layui/css/layui.css" />
		<link type="text/css" rel="stylesheet" href="${r'${ctx}'}/view/xweb/xsyr/xstyle.css?t=2019" />
		<!--[if lt IE 9]>
		  <script src="xsyr/xuilib/respond.js"></script>
		<![endif]-->
		<script src="${r'${ctx}'}/view/xweb/xsyr/xuilib/html5shiv.js"></script>
	</head>
	<body>

	<%@ include file="../include/topbar.inc" %>

	<div class="xbackgroud xtop-bg" style="background-image: url(${r'${ctx}'}/view/xweb/xsyr/ximg/topbg.png);">
		
	<div class="container">
		<div class="layout">
		<div class="line">
			<!--左侧logo-->
			<div class="xl2 xs3 xm3 xb3">
				<div class="xtitlelogo">
					<a href="//www.888.org.cn"><img src="${r'${ctx}'}/view/xweb/xsyr/ximg/titlelog.png"></a>
				</div>
			</div>
			
			<!--中间菜单-->
			<div class="xl10 xs9 xm7 xb7 xtop-menu">
				<div class="xmenu-bar">
					<button class="button bg-white icon-navicon float-right" data-target="#xnav-menu">菜单</button>
					<ul class="nav nav-menu nav-inline nav-pills nav-inline nav-big nav-navicon xnav-menup" id="xnav-menu">
						<li  class="active"><a href="${r'${ctx}/index.xhtml'}">首页</a></li>
						<li ><a href="${r'${ctx}/view/production/public_class.html'}">培训报名</a></li>
						<li ><a href="${r'${ctx}/view/teacher/all_teacher.html'}">专业讲师</a></li>
						<li ><a>证书查询</a></li>
						<li  class="hidden-s"><a href="${r'${ctx}/view/news_list/all_news.html'}">新闻动态</a></li>
					</ul>
				</div>
			</div>
			
			<!--右边联系电话-->
			<div class="xm2 xb2 hidden-l hidden-s">
				<div class="xlinkphone">
				<a><img src="${r'${ctx}'}/view/xweb/xsyr/ximg/link_tel.png"></a>
				</div>
			</div>
		</div>
		
		</div>
		
		<div class="line">
			<div class="xl7 xs8 xm8 xb9 xlb-adbgimg ">
				<div class="lbt_box" >
					<div class="xadlb-box ">
						<div class="banner" data-pointer="1" data-interval="12" data-style="border-blank">
							<div class="carousel">
								<#list lunList as item>
									<div class="item"> 
									<#if item.photourl??>
										<img src="${item.photourl}" />
									<#else>
										<img src="${r'${ctx}'}/view/xweb/xsyr/ximg/3.png" />
									</#if>
									</div>
								</#list>
							</div>
						</div>
					</div>
					
				</div>
			</div>
			
			<div class="xl5 xs4 xm4 xb3">
			<!--=========================未登录时显示======================================-->
			<c:if test="${r'${empty __SESSION_LOGIN_USER}'}">
				<div class="xlogin-box" style="display: block;">
					<div class="text-center login_type-tab">
						<ul class="list-inline">
							<li class="hidden-l hidden-s active" onclick="switchLoginType(this)" data-type = "pwdtype-box">账号登录</li>
							<li class="hidden-l hidden-s" onclick="switchLoginType(this)" data-type = "qrcode-box">扫码登录</li>
						</ul>
					</div>
					
					<!-- 密码登录 -->
					<div class="pwdtype-box" style="display: block;">
						<form id="frmLogin" action="login.xhtml?v=<%=System.currentTimeMillis()%>" method="post">
							<div class="xinput-box">
								<div style="display:${r'${'}empty errormsg?'none':'block'${r'}'};color: red;z-index:9999">
									<span id="errortips">${r"${"}errormsg${r"}"}</span>
								</div>
							</div>
							<div class="xinput-box">
								<div class="xbackgroud-image xloginicon clear" style="background-image:url(${r'${ctx}'}/view/xweb/xsyr/ximg/user-icon.png);"></div>
								<input type="text" class="input xlogin-input" id="userkey" name="userkey"  placeholder="请输入用户名" />
								<div class="xinput-border"><img src="${r'${ctx}'}/view/xweb/xsyr/ximg/lineborder-bgimg.png" /></div>
							</div>
							
							<div class="xinput-box">
								<div class="xbackgroud-image xloginicon" style="background-image:url(${r'${ctx}'}/view/xweb/xsyr/ximg/pwd-icon.png);"></div>
								<input class="input" type="password" placeholder="输入密码" id="userpwd" name="userpwd"placeholder="请输入密码" />
								<div class="xinput-border"><img src="${r'${ctx}'}/view/xweb/xsyr/ximg/lineborder-bgimg.png" /></div>
							</div>
							
							<div class="xinput-box">
								<div class="line">
									<div class="x8">
									<div class="xbackgroud-image xloginicon" style="background-image:url(${r'${ctx}'}/view/xweb/xsyr/ximg/imgcode-icon.png);"></div>
									<input class="input" type="text" id="imgcode" name="imgcode"  placeholder="图形验证码"/>
									<div class="xinput-border"><img src="${r'${ctx}'}/view/xweb/xsyr/ximg/lineborder-bgimg.png" /></div>
									</div>
									<div class="x4">
										<a href="javascript:;" onclick="nextImg()" title="点击更换" > 
										<img  id="imgCodePlace"  src="${r'${ctx}'}/public/image/code.xhtml?r=<%=System.currentTimeMillis()%>"/>
										</a>
									</div>
								</div>
							</div>
							
							
							
							<a  onclick="validate(this);" class="button radius-rounded xbutton xbutton-normal xlogin-button"  id="loginBtn" href="javascript:;" >登&nbsp;录</a>
							
							<div class="code-info text-center text-big text-white line  padding-large  hidden-l hidden-s">
								<div class="x6 text-left"><a target="_blank" href="javascript:;" onclick="top.location.href='${r"${"}ctx${r"}"}/view/forget_password.html?r=<%=System.currentTimeMillis()%>'">忘记密码</a></div>
								<div class="x6 text-right"><a target="_blank" href="javascript:;" onclick="top.location.href='${r"${"}ctx${r"}"}/view/register.html?r=<%=System.currentTimeMillis()%>'">免费注册</a></div>
							</div>
						</form>
					</div>
					
					<!-- 扫码框 -->
					<div class="qrcode-box" style="display: none;">
						<form id="frmQrLogin" name="frmQrLogin" action="login.xhtml?v=<%=System.currentTimeMillis()%>" method="post">
							<input type="hidden" name="gourl" value='${r"${"}empty sgourl?gourl:sgourl${r"}"}'> 
							<input type="hidden" name="fromurl" value='${r"${"}empty sgourl?fromurl:sfromurl${r"}"}'>
							<input type="hidden" id="openid" name="openid" value="">
							<input type="hidden" id="weixid" name="weixid" value="">
							<input type="hidden" id="appid" name="appid" value="">
							<input type="hidden" id="way" name="way" value="qr">
						</form>
						
						<div class="code-boxborder">
							<div id="hide" class="qrcodeimg"></div>
							<div class="time-out" style="display: none;"> <!--显示时用 display:inline-block; -->
								<div class="retry" ><strong>二维码已失效</strong></div>
								<div onclick="loadQrcode();"  class="button bg-red margin-big-top hand">刷 新</div>
							</div>
						</div>
						
						<div class="code-info text-center text-big text-white hidden-l hidden-s">
							<p><img src='${r"${"}ctx${r"}"}/view/xweb/xsyr/ximg/scanner-bgimg.png'/> 请打开手机微信扫描二维码</p>
							<p>还没有账号,<a target="_blank" href="javascript:;" onclick="top.location.href='${r"${"}ctx${r"}"}/view/register.html?r=<%=System.currentTimeMillis()%>'">立即注册</a></p>
						</div>
					</div>
					
				</div>
			</c:if>
			<!--=========================登录成功后的处理======================================-->
			<c:if test="${r'${not empty __SESSION_LOGIN_USER}'}">
				<div class="xlogin-success" style="display: block;">
				<div class="xinfo-panel radius bg-white opacity-big box-shadow-big">
					<div class="line margin-bottom">您好,
						<a href="" title="用户中心"> <sy:secUserName nameStr="${r'${__SESSION_LOGIN_USER.username}'}"/>  </a>
						<a class="float-right" href="javascript:;"  onclick="loginOut();">退出</a>
					</div>
					
					<div class="line">
						<div class="xl2 xs3 x4 text-center">
							<a  href="#">
								<img src="https://www.8888.org.cn/staticsrc/eduweb/image/userPhoto2/user003.png" class="radius" alt="..." width="100%" >
							</a>
						</div>
						<div class="xl10 xs9 x8 padding-left">
							<ul class="text-gray height-big">
								<li>站内信:<a href="#"><span class="icon icon-envelope-o text-big"></span> 
									<span class="badge bg-red">
									${r'<c:if test="${msgCount gt 0}">
					   					${msgCount}
					   				</c:if>
					   				<c:if test="${msgCount eq 0}">
					   					${msgCount}
					   				</c:if>'}
									</span></a></li>
									<li>已获学分:<span class="text-red">
										<c:if test="${r'${not empty studyInfo.retObj}'}">
										<fmt:formatNumber type="number" pattern="0.0" value="${r'${studyInfo.retObj.alreadyScore}'}"/>
										</c:if>
									</span> 分</li>
									<c:if test="${r'${'}orderCount != '0'${r'}'}">
									<li>已报课程:<span class="text-red">${r'${studyCount}'}</span> 科</li>
					   				</c:if>
					   				<c:if test="${r'${'}orderCount == '0'${r'}'}">
									<li>已报课程:<span class="text-red">未报名</span></li>
					   				</c:if>
							</ul>
						</div>
					</div>
					<div class="margin-top  margin-bottom">
						<ul style="line-height: 26px;">
							<li>用户角色:专业技术人员</li>
							<c:if test="${r'${empty studyInfo.retObj or studyInfo.retObj eq null}'}">
								<li class="hidden-l">学习状态:未学习</li>
							</c:if>
		      				<c:if test="${r'${not empty studyInfo.retObj}'}">
		      					<c:choose>
		      						<c:when test="${r'${'}studyInfo.retObj.studyStatus eq '002' and studyInfo.retObj.alreadyScore ge studyInfo.retObj.mustScore${r'}'}">
		      						<li>学习状态:已毕业</li>
		      						</c:when>
		      						<c:otherwise>
		      						<li class="hidden-l">学习状态:学习中...</li>
		      						</c:otherwise>
		      					</c:choose>
		      				</c:if>
							
							<c:if test="${r'${not empty studyInfo.retObj}'}">
								<li class="hidden-l">课程有效期至:${r'${studyInfo.retObj.endTime}'}</li>
							</c:if>
						</ul>	
					</div>
					
					<c:if test="${r'${ '}!fn:startsWith(__SESSION_LOGIN_USER.extfiled1, 'hospital')${r'}'}">
						<div class="line">
							<a href="${r'${ctx}/view/usercenter/myuser/mydatum.html'}">
							<div class="x4 text-center" >
								<img src="${r'${ctx}/view/xweb/xsyr/ximg/user.png'}" class="login-opreat"/>
								<p>用户中心</p></div>
							</a>
							<a href="${r'${ctx}/view/production/public_class.html'}" >
							<div class="x4 text-center">
								<img src="${r'${ctx}/view/xweb/xsyr/ximg/buyclass.png'}" class="login-opreat"/>
							<p>报名</p></div>
							</a>
							<c:if test="${r'${ '}orderCount != '0'${r'}'}">
							<a href="${r'${ctx}/view/usercenter/study/myStudy.html'}" >
							<div class="x4 text-center">
								<img src="${r'${ctx}/view/xweb/xsyr/ximg/studyp.png'}" class="login-opreat"/>
							<p>学习</p></div></a>
							</c:if>
							
							<c:if test="${r'${ '}orderCount == '0' and __SESSION_LOGIN_USER.disc ne '005' and __SESSION_LOGIN_USER.disc ne '006'${r'}'}">
							<a href="" >
							<div class="x4 text-center">
								<img src="${r'${ctx}/view/xweb/xsyr/ximg/studyp.png'}" class="login-opreat"/>
							<p>学习</p></div></a>
							</c:if>
						</div>
					</c:if>
					<div class="line text-center" style="display: block;"> <!-- 其它角色调转用按钮 -->
						
						<c:if test="${r'${ '}fn:startsWith(__SESSION_LOGIN_USER.extfiled1, 'hospital') and __SESSION_LOGIN_USER.disc eq '001'${r'}'}">
			     		    <button type='button' class="button bg-blue" onclick="window.location.href='${r"${ctx}"}/private/register/modifyHospital.xhtml?userid=${r"${__SESSION_LOGIN_USER.id}"}'">去修改</button>
			     		</c:if>
			     		
			     		<c:if test="${r'${ '}__SESSION_LOGIN_USER.disc eq '004' or __SESSION_LOGIN_USER.disc eq '005' or  __SESSION_LOGIN_USER.disc eq'006'${r'}'}">
			     			<button type='button' class="button bg-blue" onclick="window.location.href='/mba/public/selfAuth/ssologin.xhtml?r=<%=System.currentTimeMillis()%>'">监管平台</button>
			     		</c:if>
			     		
			     		<c:if test="${r'${ '}__SESSION_LOGIN_USER.disc eq '007' or  __SESSION_LOGIN_USER.disc eq'999'${r'}'}">
			     			<c:if test="${r'${ '}__SESSION_LOGIN_USER.extfiled1 eq 'hospital_100'${r'}'}">
			     				<span style="color:#ff5959;font-size: 16px;font-weight:bold;position: absolute;bottom:100px;margin-left: 14px;">您登录的帐号信息异常</span>
			     			</c:if>
			     			
			     		</c:if>
			     		
			     		<c:if test="${r'${ '}__SESSION_LOGIN_USER.disc eq '110' or __SESSION_LOGIN_USER.disc eq '120'${r'}'}">
			     			<button type='button' class="button bg-blue" onclick="window.location.href='/mba/public/selfAuth/ssologin.xhtml?r=<%=System.currentTimeMillis()%>'">统计分析</button>
			     		</c:if>
					</div>
				</div>
			</div>
			</c:if>
			<!-- 登录成功展示信息end -->
				
			</div>
		</div>
		</div>
	</div>
	<!--#111顶部菜单轮播登录框end-->
	
	
	
	
	<!-- 222专题类目 -->
	<div class="container">
		<div class="xsubject-title" style="background-image: url(${r'${ctx}'}/view/xweb/xsyr/ximg/project.png);background-size: 15%;"></div>
		<div class="xsubject-more text-center">
			<a href="javascript:goUrl('/view/production/public_class.html')"><img src="${r'${ctx}'}/view/xweb/xsyr/ximg/morethan.png"></a>
		</div>
	</div>
	
	
	<div class="xbackgroud xsubject-bg" style="background-image: url(${r'${ctx}'}/view/xweb/xsyr/ximg/project_bgimg.png);">
	
		<div class="container">
			<div class="xsubject-items">
			<#list hotProdList as item>
				<#if item_index lte 3>
				<a href="${r'${ctx}'}/public/view/production/detail.xhtml?prodId=${item.linked}" target="_blank">
					<div class="xsubject-item line box-shadow-small bg-white">
						<div class="x7">
							<img src="${item.photourl}" alt="...">
						</div>
						<div class="x5 padding text-center">
							<div class="item-info">
								<div class="title">${item.title}</div>
								<div>${item.subheading}</div>
							</div>
						</div>
					</div>
				</a>
				</#if>
			</#list>
			</div>
		</div>
	</div>
	<!-- 222专题类目end -->
	
	<!-- 333名师风采 -->
	<div class="container">
		<div class="xsubject-title" style="background-image: url(${r'${ctx}'}/view/xweb/xsyr/ximg/teacher_tiltebg.png);background-size: 30%;"></div>
		<div class="xsubject-more text-center">
			<a href="javascript:goUrl('/view/teacher/all_teacher.html')"><img src="${r'${ctx}'}/view/xweb/xsyr/ximg/morethan.png"></a>
		</div>
	</div>
	
	<div class="xbackgroud xteacher-bg" style="background-image: url(${r'${ctx}'}/view/xweb/xsyr/ximg/teacher_bannerbg.png);">
	
	<div class="container">
		<div class="teacher-banner">
			<div class="line">
				<#list teacherList as item>
					<#if item_index lte 2>
					<div class="x4 padding">
						<#if item_index % 2 == 0>
						<div class="teacher teacherl ">
						<#elseif item_index % 2 != 0>
						<div class="teacher teacherm ">
						</#if>
							<a href="${item.linked}"> 
								<#if item.photourl??>
									<img src="${item.photourl}" />
								<#else>
									<img src="${r'${ctx}'}/view/xweb/xsyr/ximg/teacher.png" />
								</#if>
								 
							</a>
						</div>
					</div>
					</#if>
				</#list>
			</div>
			</div>
		</div>
	</div>
	<!-- 333名师风采end -->
	<!-- 444新闻列表 -->
	<div class="container">
		<div class="xsubject-title" style="background-image: url(${r'${ctx}'}/view/xweb/xsyr/ximg/news_action.png);background-size: 15%;"></div>
		<div class="xsubject-more text-center">
			<a href="javascript:goUrl('/view/news_list/all_news.html')"><img src="${r'${ctx}'}/view/xweb/xsyr/ximg/morethan.png"></a>
		</div>
	</div>
	
	<div class="xbackgroud xnews-bannar" style="background-image: url(${r'${ctx}'}/view/xweb/xsyr/ximg/newspoint_bg.png);">
	<div class="container">
		<div class="news-lbcontent_div"> 
			<!-- 新闻轮播图 -->
			<div class="banner">
			  <div class="carousel news-lbcontent_div">
				<#list bannerNewsList as item>
					<div class="item">
						<a href="${item.linked}" target="_blank">
						<#if item.photourl??>
							<img class="radius" src="${item.photourl}" />
						<#else>
							<img class="radius" src="${r'${ctx}'}/view/xweb/xsyr/ximg/local-news.png" />
						</#if>
						<div class="newstitle">${item.title}</div>
						</a>
					</div>
				</#list>
				
			  </div>
			</div>
			<!-- 新闻轮播图end -->
			<!-- 头条新闻 开始 -->
			<div class="padding-big"></div>
			<#list topNewsList as item>
				<#if item_index == 0>
				<div class="line margin-big-bottom">
					<div class="xl2 xs2 xm1 xb1"><div class="xnews-date float-right"><p>${item.updateDate?string("dd")}</p>${item.updateDate?string("MM")}月</div></div>
					<a href="${item.linked}" target="_blank">
					<div class="xm4 xb4 hidden-l hidden-s">
						<#if item.photourl??>
							<img src="${item.photourl }" width="98%" style="98%">
						<#else>
							<img width="98%" style="98%"src="${r'${ctx}'}/view/xweb/xsyr/ximg/new-location.png" />
						</#if>
					</div>
					</a>
					<a href="${item.linked}" target="_blank">
					<div class="xl10 xs10 xm6 xb6 text-big height-big padding">
						<div class="xnews-title">${item.title }</div>
						${item.subheading}
					</div>
					</a>
					<div class="xm-1 xb-1 hidden-l hidden-s"></div>
				</div>
				
				<div class="news-splite"></div><div class="margin-big-top"></div>
				
				<#elseif item_index == 1>
				<div class="line margin-big-bottom">
					<div class="xm1 xb1 hidden-l hidden-s"></div>
					<a href="${item.linked}" target="_blank">
					<div class="xl10 xs10 xm6 xb6 text-big height-big">
						<div class="xnews-title">${item.title }</div>
						${item.subheading}
					</div>
					</a>
					<a href="${item.linked}" target="_blank">
					<div class="xm4 xb4 hidden-l hidden-s">
					<#if item.photourl??>
						<img src="${item.photourl }"  width="98%" style="98%">
					<#else>
						<img width="98%" style="98%" src="${r'${ctx}'}/view/xweb/xsyr/ximg/new-location.png" />
					</#if>
					</div>
					</a>
					<div class="xl2 xs2 xm1 xb1"><div class="xnews-date float-left"><p>${item.updateDate?string("dd")}</p> ${item.updateDate?string("MM")}月</div></div>
				</div>
				</#if>
			</#list>	
			
			<div class="news-splite"></div><div class="margin-big-top"></div>
			<!-- 头条新闻 结束 -->
			<!-- 新闻列表展示 -->
			<div class="xnews-list height-big">
				<#list newsList as item>
					<#if item_index % 2 == 0>
					<div class="line">
						<div class="x6 news-left">
							<a href="${item.linked}" target="_blank">${item.title }<div class="float-right text-gray">${item.updateDate?string("yyyy-MM-dd")}</div></a>
						</div>
						
					<#else>
					
						<div class="x6  news-right">
							<a href="${item.linked}" target="_blank">${item.title } <div class="float-right text-gray">${item.updateDate?string("yyyy-MM-dd")}</div></a>
						</div>
					</div>
					</#if>
					
				</#list>
				
			</div>
			</div><!-- 新闻列表展示 end -->
		</div>
		</div>
	</div>
	<div class="xbackgroud xfooter-bannar" style="background-image: url(${r'${ctx}'}/view/xweb/xsyr/ximg/footer_bgimg.png);"></div>
	<!-- 444新闻列表end -->
	
	<!-- 555关于我们 -->
	<div class="container" >
		<div class="xsubject-title" style="background-image: url(${r'${ctx}'}/view/xweb/xsyr/ximg/aboutas_bgimg.png);background-size: 18%;margin-top: 5%;"></div>
	</div>
	<div class="padding-big"></div>
	<div class="xbackgroud xaboutus-bannar" style="background-image: url(${r'${ctx}'}/view/xweb/xsyr/ximg/aboutbgimg.png);">
	
	<div class="container">
		<div class="xcontainer">
			<div class="radius bg-white opacity-big box-shadow-big padding-big text-big  about-text" >
			关于我们
			</div>
			
			<div class="about-link">
				<p><span class="icon-phone text-big color-blue"></span>&nbsp;&nbsp;&nbsp;&nbsp;400-138-1266 </p>
				<p><span class="icon-map-marker text-big color-blue"></span>&nbsp;&nbsp;&nbsp;&nbsp;地址</p>
				<p><span class="icon-envelope color-blue"></span>&nbsp;&nbsp;&nbsp;wangjian@sypxgl.org</p>
			</div>
		</div>
	</div>
	</div>
	
	<!-- 555关于我们end -->
	
	<!-- 页脚开始 -->
	<script type="text/javascript" src="${r'${staticctx}'}/eduweb/r/slick/js/slick.min.js"></script>
	<script src="${r'${staticctx}'}/assests/lib/jquery.qrcode.min.js"></script>
	<script src="${r'${ctx}'}/view/xweb/xsyr/xuilib/jquery.js" type="text/javascript"></script>
	<script src="${r'${ctx}'}/view/xweb/xsyr/xuilib/pintu/pintuer.js" type="text/javascript"></script>
	<script src="${r'${ctx}'}/view/xweb/xsyr/xuilib/layui/layui.js" type="text/javascript"></script>
	<script type="text/javascript" src="${r'${staticctx}'}/eduweb/js/base.js?t=${r'${_ver}'}"></script>
<script type="text/javascript" src="${r'${staticctx}'}/eduweb/js/main.js?t=${r'${_ver}'}"></script>
	<script src="${r'${staticctx}'}/assests/lib/jquery.qrcode.min.js"></script>
	<script src="${r'${ctx}'}/view/xweb/xsyr/xjs/xindex.js?t=2019" type="text/javascript"></script>
	<%@ include file="../include/baseScript.inc" %><%@ include file="../include/footer.inc" %><%@ include file="../include/bottom.inc" %>
	<!-- 页脚结束 -->
	</body>
</html>
	
	

3:Java 代码

/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.cloudedu.manager.modules.indexhtml.web;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringWriter;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.cloudedu.api.common.persistence.FinalResult;
import com.cloudedu.manager.common.config.Global;
import com.cloudedu.manager.common.web.BaseController;
import com.cloudedu.manager.modules.indexhtml.entity.IndexHtml;
import com.cloudedu.manager.modules.indexhtml.service.IndexHtmlService;

import freemarker.template.Configuration;
import freemarker.template.Template;

/**
 * 首页静态Controller
 * @author 
 * @version 2019-03-11
 */
@Controller
@RequestMapping(value = "${adminPath}/indexhtml/indexHtml")
public class BuildHtmlController extends BaseController {

	@Autowired
	private IndexHtmlService indexHtmlService;
	
	@RequestMapping("/buildIndxHtml")
	public String buildIndxHtml(Model m, HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) {
		String flag = request.getParameter("done");
		FileWriter out = null;
		FinalResult result = new FinalResult();
	    String name = "index_jsp_v2.ftl";
	    Map<String, Object> root = new HashMap<String, Object>();
		 // 设定去哪里读取相应的ftl模板文件
	    String path = this.getClass().getResource("/").getPath();
	    Configuration cfg = new Configuration();
	    System.out.println(path);
        try {
            //3 设置ftl文件的字符集编码
            cfg.setDefaultEncoding("UTF-8");
            
            cfg.setDirectoryForTemplateLoading(new File(path));
            
        	// 在模板文件目录中找到名称为name的文件
			Template temp = cfg.getTemplate(name);
			StringWriter sw = new StringWriter();
			//1.轮播图
			Map<String, Object> lunb = new HashMap<String, Object>();
			lunb.put("channelId", '1');
			lunb.put("grade", "1");
			root.put("lunList", indexHtmlService.findListByMap(lunb));
			
			//2.热门培训班
			Map<String, Object> hotProd = new HashMap<String, Object>();
			hotProd.put("channelId", '2');
			hotProd.put("grade", "1");
			root.put("hotProdList", indexHtmlService.findListByMap(hotProd));
			
			//3.讲师风采
			Map<String, Object> teacher = new HashMap<String, Object>();
			teacher.put("channelId", '4');
			teacher.put("grade", "1");
			root.put("teacherList", indexHtmlService.findListByMap(teacher));
			
			//4.新闻
			//标题轮播图
			Map<String, Object> map1 = new HashMap<String, Object>();
			map1.put("channelId", '5');
			map1.put("grade", "1");
			map1.put("type", "001");
			root.put("bannerNewsList", indexHtmlService.findListByMap(map1));
			//头条新闻
			Map<String, Object> map2 = new HashMap<String, Object>();
			map2.put("channelId", '5');
			map2.put("grade", "1");
			map2.put("type", "002");
			root.put("topNewsList", indexHtmlService.findListByMap(map2));
			
			//新闻列表
			Map<String, Object> newsMap = new HashMap<String, Object>();
			newsMap.put("channelId", '5');
			newsMap.put("grade", "1");
			newsMap.put("type", "003");
			root.put("newsList", indexHtmlService.findListByMap(newsMap));
			
			System.out.println(sw.toString());
			// 读取配置文件中输出路径
            String realPath=Global.getConfig("index_html_path");
			String outPath= realPath+File.separator;
			File f = null;
			if("view".equals(flag)){
				f=new File(outPath+"view_gxk_index.jsp");
				out = new FileWriter(f);
				temp.process(root, out);
				result.setState("SUCCESS");
				writeJson(response, result);
			} else {
				f=new File(outPath+"gxk_index.jsp");
				out = new FileWriter(f);
				temp.process(root, out);
			}
			 addMessage(redirectAttributes, "静态页面生成成功");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			result.setState("FAILD");
		} finally {
			try {
                if (out != null)
                    out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
		}
        
        return "redirect:"+Global.getAdminPath()+"/indexhtml/indexHtml/list?grade=0&repage";
	}
		
}

结束

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值