JFinal 怎么用setAttr 然后在页面用jsp取 我明明存的对象 给我自动转换成HashMap了a

快慢机 发布于 2013/08/21 16:20
阅读 1K+
收藏 0
JFinal 怎么用setAttr 然后在页面用jsp取 我明明存的对象 给我自动转换成HashMap了   坑啊
加载中
0
JFinal
JFinal
jstl 数据读取能力太弱,所以 JFinal 将数据转成了 map,如果不需要这个转换,可以在 YourJFinalConfig 中调用一下 JspRender.setSupportActiveRecord(false)
快慢机
快慢机
汗。。。 真应该好好读读源码 我自己又在Constants里面加了个参数判断了下
0
快慢机
快慢机

好吧!我看源码知道问题在那了

private Object handlePage(Page page, int depth) {
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("list", handleList(page.getList(), depth));
		result.put("pageNumber", page.getPageNumber());
		result.put("pageSize", page.getPageSize());
		result.put("totalPage", page.getTotalPage());
		result.put("totalRow", page.getTotalRow());
		return result;
	}

0
红星xx
红星xx
楼主二了 ,这么用。搞复杂了。
快慢机
快慢机
没有我改了下jfinal操作数据的那块把他和jdao那个开源项目结合,用着挺方便的
0
快慢机
快慢机
package com.model;

import com.core.jfinal.anatation.TableBind;
import com.core.jfinal.model.Fields;
import com.core.jfinal.model.FieldsUtils;
import com.jfinal.plugin.activerecord.Model;
/**
 * 
 * @author lxp
 *
 */
@TableBind(name = "fk_channel" , pk = "id")
public class FkChannel extends Model<FkChannel> {
	/**
	 * 数据库操作dao 
	 * 单例模式
	 */
	public static final FkChannel getJdbc(){
		return new FkChannel();
	}
	
	
	/**
	 * 字段配置
	 */
	public final static Fields id = new Fields("id", "主键ID",Integer.class);
	public final static Fields channelname = new Fields("channelName", "栏目名称",java.lang.String.class);
	public final static Fields sort = new Fields("sort", "排序",Integer.class);
	public final static Fields url = new Fields("url", "网址",java.lang.String.class);
	public final static Fields createuserid = new Fields("createUserId", "创建人",java.lang.String.class);
	public final static Fields createdate = new Fields("createDate", "创建时间",java.sql.Timestamp.class);
	public final static Fields updateuserid = new Fields("updateUserId", "最后一次修改人",java.lang.String.class);
	public final static Fields updatedatee = new Fields("updateDatee", "最后一次修改时间",java.sql.Timestamp.class);
	
	public Integer getId(){
		return this.getInt(id.getFieldName());
	}
	public java.lang.String getChannelname(){
		return this.getStr(channelname.getFieldName());
	}
	public Integer getSort(){
		return this.getInt(sort.getFieldName());
	}
	public java.lang.String getUrl(){
		return this.getStr(url.getFieldName());
	}
	public java.lang.String getCreateuserid(){
		return this.getStr(createuserid.getFieldName());
	}
	public java.sql.Timestamp getCreatedate(){
		return this.getTimestamp(createdate.getFieldName());
	}
	public java.lang.String getUpdateuserid(){
		return this.getStr(updateuserid.getFieldName());
	}
	public java.sql.Timestamp getUpdatedatee(){
		return this.getTimestamp(updatedatee.getFieldName());
	}
	
	public void setId(Integer id){
		this.set(this.id.getFieldName(),id);
	}
	public void setChannelname(java.lang.String channelname){
		this.set(this.channelname.getFieldName(),channelname);
	}
	public void setSort(Integer sort){
		this.set(this.sort.getFieldName(),sort);
	}
	public void setUrl(java.lang.String url){
		this.set(this.url.getFieldName(),url);
	}
	public void setCreateuserid(java.lang.String createuserid){
		this.set(this.createuserid.getFieldName(),createuserid);
	}
	public void setCreatedate(java.util.Date createdate){
		this.set(this.createdate.getFieldName(),createdate);
	}
	public void setUpdateuserid(java.lang.String updateuserid){
		this.set(this.updateuserid.getFieldName(),updateuserid);
	}
	public void setUpdatedatee(java.util.Date updatedatee){
		this.set(this.updatedatee.getFieldName(),updatedatee);
	}
	
	public String[] toShowNameAll(){
		return  FieldsUtils.toArrayShowNames(id,channelname,sort,url,createuserid,createdate,updateuserid,updatedatee);
	}
	public String[] toFieldNameAll(){
		return FieldsUtils.toArrayFieldNames(id,channelname,sort,url,createuserid,createdate,updateuserid,updatedatee);
	}
	
}
<%
 for(int i = 0 ; i< pageInfo.getList().size() ; i++){
	 FkChannel model = (FkChannel) pageInfo.getList().get(i);
%>
<tr align='center' bgcolor="#FFFFFF" onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';" height="22" >
	<td><%=model.getId() %></td>
	<td><input name="id" type="checkbox" id="id" value="<%=model.getId() %>" class="np"></td>
	<td align="left"><a href=''><u><%=model.getChannelname() %></u></a></td>
	<td><%=model.getSort() %></td>
	<td><%=model.getUrl() %></td>
	<td><%=model.getCreateuserid() %></td>
	<td><%=model.getCreatedate() %></td>
	<td><%=model.getUpdateuserid() %></td>
	<td><%=model.getUpdatedatee() %></td>
	<td><a href="101">编辑</a> | <a href="101">预览</a></td>
</tr>
<%
 }
%>
public void login() throws Exception {
		FkAdmin model = getModel(FkAdmin.class);
		if (model != null && StringUtils.isNotBlank(model.getJName())) {
			String msg = "";
			FkAdmin admin =   FkAdmin.getJdbc().where(FkAdmin.jName.EQ(model.getJName())).limit(1, 1).queryById();
			if (admin != null) {
				String passwd = AES.encrypttoStr(model.getPasswd() + admin.getJRandom());
				if (StringUtils.equals(passwd, admin.getPasswd())) {
					setSessionAttr(LanguageKey.FkAdminSession, admin);
					MemcacheTool.mcc.set(admin.getJName(), admin);
					setCookie("user_token", admin.getJName(), -1);
					redirect("index");
				}else {
					msg = "密码错误!";
				}
			}else {
				msg = "用户名不存在!";
			}
			setAttr("msg",msg);
		}
	}
返回顶部
顶部