0

JSP 页面:

<s:iterator value="classes" status="userStatus">
  <tr>
    <td><s:property value="classTitle" /></td>
    <td><s:property value="viewOrder" /></td>
    <td><s:property value="createdBy" /></td>
    <td><s:date name="createdDate" format="dd-MMM-yyyy"/></td>
    <td>
      <input type="button" class="btn btn-green5" value="Manage Sections" />
      <input type="button" class="btn btn-blue5" value="Edit" />
      <input type="button" class="btn btn-red5" value="Delete" />
    </td>
  </tr>
</s:iterator>

用户逻辑类:

public class UserMasterLogic {
    private Session session;
    private static SessionFactory factory;

    public UserMasterLogic() {
        factory = new Configuration().configure().buildSessionFactory();
        this.session = factory.openSession();
    }

    public String getUserIdById(int id) {
        UserMaster user = null;
        try {
            session.beginTransaction();
            user = (UserMaster) session.get(Class.class, id);
        } catch (HibernateException h) {
            System.out.println(h);
        }

        return user.getUserId();
    }
}

现在我想将属性createdBy值传递给getUserIdById()方法并在表格行上显示返回值。


如果你想从 JSP 页面调用一些方法,那么就这样调用它:

<s:property value="getUserIdById(createdBy)" />

更新

这样做的正确方法是将您注入UserMasterLogic到您的操作类中,然后如果您想从 JSP 调用它:

<s:property value="userMasterLogic.getUserIdById(createdBy)" />
4

1 回答 1

0

如果你想从 JSP 页面调用一些方法,那么就这样调用它:

<s:property value="getUserIdById(createdBy)" />

更新

这样做的正确方法是将您注入UserMasterLogic到您的操作类中,然后如果您想从 JSP 调用它:

<s:property value="userMasterLogic.getUserIdById(createdBy)" />
于 2013-01-05T21:35:52.267 回答