2銆丄ppFreeMarkerRender錛堝湪FreeMarkerRender涓婁慨鏀癸級錛?br />
package com.microcorecn.common.utils;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import javax.servlet.ServletContext;
import com.jfinal.render.Render;
import com.jfinal.render.RenderException;
import freemarker.template.Configuration;
import freemarker.template.ObjectWrapper;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import freemarker.template.TemplateExceptionHandler;
/**
* FreeMarkerRender.
*/
public class AppFreeMarkerRender extends Render {
private static final long serialVersionUID = -7649769283048920381L;
private transient static final String encoding = getEncoding();
private transient static final String contentType = "text/html; charset=" + encoding;
private String templateName;
private Map<String, Object> rootMap;
public AppFreeMarkerRender(Map<String, Object> rootMap, String templateName) {
this.templateName=templateName;
this.rootMap=rootMap;
}
@SuppressWarnings({"unchecked", "rawtypes"})
public void render() {
response.setContentType(contentType);
Enumeration<String> attrs = request.getAttributeNames();
Map root = new HashMap();
while (attrs.hasMoreElements()) {
String attrName = attrs.nextElement();
root.put(attrName, request.getAttribute(attrName));
}
root.putAll(rootMap);
PrintWriter writer = null;
try {
Template template = FreemarkerUtil.getAppConfiguration().getTemplate(this.templateName);
writer = response.getWriter(); //涓€杈硅姹傦紝涓€杈箁ender
template.process(root, writer); // Merge the data-model and the template
} catch (Exception e) {
throw new RenderException(e);
}
finally {
if (writer != null)
writer.close();
}
}
}
3銆丗reemarkerUtil 錛?br />package com.microcorecn.common.utils;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.jfinal.kit.PathKit;
import com.jfinal.render.FreeMarkerRender;
import freemarker.cache.FileTemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapper;
import freemarker.template.Template;
/**
* freemarker鐢熸垚html鐨勫伐鍏風被
*
* @author Administrator
*
*/
public class FreemarkerUtil {
//淇濆瓨鎵€鏈夊弬鏁?js璺緞,cs璺緞絳?/div>
private static Map<String, Object> releaseParams = new HashMap<String, Object>();
static{
//releaseParams.put("csspath", "");
}
//閰嶇疆
private static Configuration config = null;
private static Configuration appConfig = null;
/**
* appConfig閰嶇疆鎵€鏈夊弬鏁?/div>
* 閲嶅啓freemarker涓殑 reader鏂規硶錛岃鍙栬閰嶇疆鏂囦歡
* @return
*/
public static Configuration getAppConfiguration()
{
if(appConfig == null)
{
//浠巉reemarker涓幏鍙栨墍鏈夐厤緗?/div>
appConfig = (Configuration)FreeMarkerRender.getConfiguration().clone();
try {
//璁劇疆妯℃澘璺緞
/* config.setDirectoryForTemplateLoading(new File(PathKit.getWebRootPath()));
config.setObjectWrapper(new DefaultObjectWrapper());*/
appConfig.setDirectoryForTemplateLoading(new File(PathKit.getWebRootPath()+"/WEB-INF/views/"));
appConfig.setObjectWrapper(new DefaultObjectWrapper());
} catch (IOException e) {
// TODO log
}
}
return appConfig;
}

]]>
- Jfinal涓嶈兘浣跨敤鍒悕錛宲6spy鐩戞帶鏁版嵁搴撴棩蹇?/title><link>http://www.aygfsteel.com/17learning/archive/2013/04/02/397307.html</link><dc:creator>綆″厛椋?/dc:creator><author>綆″厛椋?/author><pubDate>Tue, 02 Apr 2013 10:40:00 GMT</pubDate><guid>http://www.aygfsteel.com/17learning/archive/2013/04/02/397307.html</guid><wfw:comment>http://www.aygfsteel.com/17learning/comments/397307.html</wfw:comment><comments>http://www.aygfsteel.com/17learning/archive/2013/04/02/397307.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/17learning/comments/commentRss/397307.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/17learning/services/trackbacks/397307.html</trackback:ping><description><![CDATA[<div>闂鍘熷洜錛欽Final涓牴鎹儲寮曟煡璇㈠垪鍚嶃€?br />1銆侀噸鏂版柊寤篋B綾伙細<br />package com.microcorecn.jfinalex;</div><div></div><div>import java.sql.Connection;</div><div>import java.sql.PreparedStatement;</div><div>import java.sql.ResultSet;</div><div>import java.sql.SQLException;</div><div>import java.util.ArrayList;</div><div>import java.util.List;</div><div></div><div>import com.jfinal.plugin.activerecord.ActiveRecordException;</div><div>import com.jfinal.plugin.activerecord.DbKit;</div><div></div><div>public class DbEx {</div><div><span style="white-space:pre"> </span>static <T> List<T> query(Connection conn, String sql, Object... paras) throws SQLException {</div><div><span style="white-space:pre"> </span>List result = new ArrayList();</div><div><span style="white-space:pre"> </span>PreparedStatement pst = conn.prepareStatement(sql);</div><div><span style="white-space:pre"> </span></div><div><span style="white-space:pre"> </span>for (int i=0; i<paras.length; i++) {</div><div><span style="white-space:pre"> </span>pst.setObject(i + 1, paras[i]);</div><div><span style="white-space:pre"> </span>}</div><div><span style="white-space:pre"> </span>// for (int i=0; i<paras.length; i++) {</div><div><span style="white-space:pre"> </span>// pst.setObject(i + 1, paras[i]);</div><div><span style="white-space:pre"> </span>// }</div><div><span style="white-space:pre"> </span></div><div><span style="white-space:pre"> </span>ResultSet rs = pst.executeQuery();</div><div><span style="white-space:pre"> </span></div><div><span style="white-space:pre"> </span>int colAmount = rs.getMetaData().getColumnCount();</div><div><span style="white-space:pre"> </span>String[] cols = new String[colAmount];</div><div><span style="white-space:pre"> </span>for(int i = 0; i < colAmount; ++i)</div><div><span style="white-space:pre"> </span>{</div><div><span style="white-space:pre"> </span>cols[i] = rs.getMetaData().getColumnLabel(i + 1);</div><div><span style="white-space:pre"> </span>}</div><div><span style="white-space:pre"> </span>if (colAmount > 1) {</div><div><span style="white-space:pre"> </span>while (rs.next()) {</div><div><span style="white-space:pre"> </span>Object[] temp = new Object[colAmount];</div><div><span style="white-space:pre"> </span>for (int i=0; i<colAmount; i++) {</div><div><span style="white-space:pre"> </span>temp[i] = rs.getObject(cols[i]);</div><div><span style="white-space:pre"> </span>}</div><div><span style="white-space:pre"> </span>result.add(temp);</div><div><span style="white-space:pre"> </span>}</div><div><span style="white-space:pre"> </span>}</div><div><span style="white-space:pre"> </span>else if(colAmount == 1) {</div><div><span style="white-space:pre"> </span>while (rs.next()) {</div><div><span style="white-space:pre"> </span>result.add(rs.getObject(cols[0]));</div><div><span style="white-space:pre"> </span>}</div><div><span style="white-space:pre"> </span>}</div><div><span style="white-space:pre"> </span></div><div><span style="white-space:pre"> </span>if (rs != null) {try {rs.close();} catch (SQLException e) {}}</div><div><span style="white-space:pre"> </span>if (pst != null) {try {pst.close();} catch (SQLException e) {}}</div><div><span style="white-space:pre"> </span></div><div><span style="white-space:pre"> </span>return result;</div><div><span style="white-space:pre"> </span>}</div><div><span style="white-space:pre"> </span></div><div><span style="white-space:pre"> </span>public static <T> List<T> query(String sql, Object... paras) {</div><div><span style="white-space:pre"> </span>Connection conn = null;</div><div><span style="white-space:pre"> </span>try {</div><div><span style="white-space:pre"> </span>conn = DbKit.getConnection();</div><div><span style="white-space:pre"> </span>return query(conn, sql, paras);</div><div><span style="white-space:pre"> </span>} catch (Exception e) {</div><div><span style="white-space:pre"> </span>throw new ActiveRecordException(e);</div><div><span style="white-space:pre"> </span>} finally {</div><div><span style="white-space:pre"> </span>DbKit.close(conn);</div><div><span style="white-space:pre"> </span>}</div><div><span style="white-space:pre"> </span>}</div><div>}</div><div>2銆佹煡璇俊鎭細<br /><div>List<Object[]> newAlbum=DbEx.query(sb.toString(), singerItem.get("id"));</div><div><span style="white-space:pre"> </span>if (newAlbum!= null) {</div><div><span style="white-space:pre"> </span>for(Object[] obj:newAlbum){</div><div><span style="white-space:pre"> </span> item.setBfpSingerId(obj[0]==null?"":obj[1].toString());</div><div><span style="white-space:pre"> </span> item.setSingerName(obj[1]==null?"":obj[1].toString());</div><div><span style="white-space:pre"> </span> item.setImgUrl(obj[2]==null?"":obj[2].toString());</div><div><span style="white-space:pre"> </span> item.setBfpAlbumId(obj[3]==null?"":obj[3].toString());</div><div><span style="white-space:pre"> </span> item.setNewAlbumName(obj[4]==null?"":obj[4].toString());</div><div><span style="white-space:pre"> </span>}</div><div><span style="white-space:pre"> </span></div><div><span style="white-space:pre"> </span>} </div><br /></div><img src ="http://www.aygfsteel.com/17learning/aggbug/397307.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/17learning/" target="_blank">綆″厛椋?/a> 2013-04-02 18:40 <a href="http://www.aygfsteel.com/17learning/archive/2013/04/02/397307.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>JFinal鑾峰彇瀛楃涓瞛son鎴栬€呰幏鍙杔ist榪斿洖Json瀵硅薄銆?/title><link>http://www.aygfsteel.com/17learning/archive/2013/03/15/396464.html</link><dc:creator>綆″厛椋?/dc:creator><author>綆″厛椋?/author><pubDate>Fri, 15 Mar 2013 01:05:00 GMT</pubDate><guid>http://www.aygfsteel.com/17learning/archive/2013/03/15/396464.html</guid><wfw:comment>http://www.aygfsteel.com/17learning/comments/396464.html</wfw:comment><comments>http://www.aygfsteel.com/17learning/archive/2013/03/15/396464.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/17learning/comments/commentRss/396464.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/17learning/services/trackbacks/396464.html</trackback:ping><description><![CDATA[<div>Object data=getObject();<br />if(data instanceof String) {</div><div><span style="white-space: pre;"> </span> this.renderJson((String)data);</div><div> }else {</div><div><span style="white-space: pre;"> </span>this.renderJson(data);</div><div>}</div><img src ="http://www.aygfsteel.com/17learning/aggbug/396464.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/17learning/" target="_blank">綆″厛椋?/a> 2013-03-15 09:05 <a href="http://www.aygfsteel.com/17learning/archive/2013/03/15/396464.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item></channel></rss> <footer>
<div class="friendship-link">
<a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a>
</div>
</footer>
主站蜘蛛池模板:
<a href="http://" target="_blank">兴化市</a>|
<a href="http://" target="_blank">鹤庆县</a>|
<a href="http://" target="_blank">清水河县</a>|
<a href="http://" target="_blank">凤山市</a>|
<a href="http://" target="_blank">九龙城区</a>|
<a href="http://" target="_blank">澄城县</a>|
<a href="http://" target="_blank">聂拉木县</a>|
<a href="http://" target="_blank">仙桃市</a>|
<a href="http://" target="_blank">朝阳县</a>|
<a href="http://" target="_blank">清涧县</a>|
<a href="http://" target="_blank">禹州市</a>|
<a href="http://" target="_blank">闸北区</a>|
<a href="http://" target="_blank">寻乌县</a>|
<a href="http://" target="_blank">濮阳市</a>|
<a href="http://" target="_blank">连山</a>|
<a href="http://" target="_blank">康保县</a>|
<a href="http://" target="_blank">北川</a>|
<a href="http://" target="_blank">泽普县</a>|
<a href="http://" target="_blank">年辖:市辖区</a>|
<a href="http://" target="_blank">龙口市</a>|
<a href="http://" target="_blank">上蔡县</a>|
<a href="http://" target="_blank">祁门县</a>|
<a href="http://" target="_blank">黄山市</a>|
<a href="http://" target="_blank">铁岭县</a>|
<a href="http://" target="_blank">亚东县</a>|
<a href="http://" target="_blank">花垣县</a>|
<a href="http://" target="_blank">梅河口市</a>|
<a href="http://" target="_blank">渭源县</a>|
<a href="http://" target="_blank">浏阳市</a>|
<a href="http://" target="_blank">尚义县</a>|
<a href="http://" target="_blank">阳新县</a>|
<a href="http://" target="_blank">馆陶县</a>|
<a href="http://" target="_blank">郴州市</a>|
<a href="http://" target="_blank">波密县</a>|
<a href="http://" target="_blank">平陆县</a>|
<a href="http://" target="_blank">南安市</a>|
<a href="http://" target="_blank">县级市</a>|
<a href="http://" target="_blank">亚东县</a>|
<a href="http://" target="_blank">普洱</a>|
<a href="http://" target="_blank">乌苏市</a>|
<a href="http://" target="_blank">巴里</a>|
<script>
(function(){
var bp = document.createElement('script');
var curProtocol = window.location.protocol.split(':')[0];
if (curProtocol === 'https') {
bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
}
else {
bp.src = 'http://push.zhanzhang.baidu.com/push.js';
}
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(bp, s);
})();
</script>
</body>