2015-12-30 54 views
0

我不明白我如何使用一個查找器,它只需要一個參數來顯示返回的數據。 例如,我在原理實體中有一個發現者findPrincipalsByUsernameLike(String username),如何使用list.jspx中的此發現者向用戶顯示他/她的數據?在視圖中使用查找器

Principle.java

@RooJavaBean 
@RooToString 
@RooJpaActiveRecord(table = "security_principals", finders = { "findPrincipalsByUsernameLike" }) 
public class Principal { 

    @NotNull 
    @Size(min = 5, max = 50) 
    private String username; 

    @NotNull 
    @Size(min = 5, max = 50) 
    private String password; 


    private Boolean enabled; 
} 

用戶/ list.jspx

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<div xmlns:jsp="http://java.sun.com/JSP/Page" 
    xmlns:page="urn:jsptagdir:/WEB-INF/tags/form" 
    xmlns:table="urn:jsptagdir:/WEB-INF/tags/form/fields" version="2.0"> 
    <jsp:directive.page contentType="text/html;charset=UTF-8" /> 
    <jsp:output omit-xml-declaration="yes" /> 

    <page:find finderName="findPrincipalsByUsernameLike" 
     id="ff_edu_gju_syria_model_security_principal" 
     path="/principals/find"> 
     <input data-dojo-props="trim:true" data-dojo-type="dijit/form/TextBox" 
      id="toolbarFilter" name="filter" type="text" value="${filter}" /> 
    </page:find> 
    <page:list id="pl_edu_gju_syria_model_security_Principal" 
     items="${principals}" z="+E0uiC5dOFGeuICZbYdoS6Nz80o="> 
     <table:table data="${principals}" 
      id="l_edu_gju_syria_model_security_Principal" path="/security/users" 
      z="9ue3QOERNh44QuGQIg9JQzmFKnI="> 
      <table:column id="c_edu_gju_syria_model_security_Principal_username" 
       property="username" z="REKFqtjHv0gJUiSxe+y1TKytm1w=" /> 
      <table:column id="c_edu_gju_syria_model_security_Principal_password" 
       property="password" z="4khHEC8FhwrPHVFPG7c4s5cP8L4=" /> 
      <table:column id="c_edu_gju_syria_model_security_Principal_enabled" 
       property="enabled" z="boq7MuGPymSQN1CCWrQ8INhy1DM=" /> 
     </table:table> 
    </page:list> 
</div> 

如何傳遞當前用戶名不顯示用戶的文本區域?

回答

0

您不必以請求參數發送用戶。

在處理請求的Controller方法中,只需從請求中獲取用戶主體。

Spring Security 3.2引入了很大的改進,以方便用戶細節管理,看看How to get active user's UserDetails