Fork me on Gitee

jfinal使用jstl表达的存在的问及解决

问题

  • 使用jstl 的el表达式 传递数据刷新页面,页面数据不显示,经过验证,数据的确传递过去,但是官方文档并没有详细描述,getModel() 不需要设get set() ,但是使用jstl el表达式必须设置
    model 代码
package Model;

import java.util.List;

import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;

public class User extends Model<User> {

    private int id;
    private String name;
    private String pwd;

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getPwd() {
        return pwd;
    }

    public void setId(int id) {
        this.id = id;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    public final static User me = new User();

    /*
     * 删除用户
     */
    public void delUser() {
        // me.deleteById("1");
    }

    /*
     * 普通无参数查询
     */
    public List<User> queryUserList() {
        List<User> find = me.find("select * from user where id>1");
        return find;
    }

    /*
     * 带参数查询
     */
    public List<User> queryparamList() {
        List<User> find = me.find("select * from user where id>?", 2);
        return find;
    }

    /*
     * 分页查询
     */
    public Page<User> queryUserListpage() {
        Page<User> page = me.paginate(1, 4, "select *",
                " from user where id > ?", 2);
        return page;
    }

}

数据传递代码

public void pagejava(){
        User user=getModel(User.class);
        List<User> list = user.queryUserList();
        System.out.println(list.toString());
        setAttr("listname", list);
        render("/pagelist.jsp");
    }

前端代码

<%@ page language="Java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page isELIgnored="false"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>??</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
    sss
    <c:forEach items="${listname}" var="list">
        <label>${list.id}</label>
        <label>${list.name}</label>
        <label>${list.pwd}</label>
    </c:forEach>
</body>
</html>

可以正确显示数据

这里写图片描述

posted @ 2017-10-07 17:13  ---dgw博客  阅读(189)  评论(0编辑  收藏  举报