2013-05-02 4 views
0

J'essaie d'utiliser une classe personnalisée dans la méthode JDBCTemplate.queryForList comme type d'élément, mais aucune donnée ni aucune erreur ne sont renvoyées.Utilisation de la classe personnalisée dans queryForList()

Le code de classe personnalisée est:

public class DocumentCategory { 
     private int categoryId; 
     private String description; 
     private int divnId; 
     private int depttId; 
     private String revCategory; 
     private boolean withBids; 
     private boolean withFinalDocuments; 
     private boolean editable; 
     private int templateId; 
     private String templateName; 
     private boolean changed; 
     private String remarks; 
     private boolean withBidsChanged; 
     private boolean withFinalDocumentsChanged; 
     private int sortOrder; 

     private String vdrNumber; 

     public int getCategoryId() { 
      return categoryId; 
     } 
     public void setCategoryId(int categoryId) { 
      this.categoryId = categoryId; 
     } 
     public String getDescription() { 
      return description; 
     } 
     public void setDescription(String description) { 
      this.description = description; 
     } 
     public int getDivnId() { 
      return divnId; 
     } 
     public void setDivnId(int divnId) { 
      this.divnId = divnId; 
     } 
     public int getDepttId() { 
      return depttId; 
     } 
     public void setDepttId(int depttId) { 
      this.depttId = depttId; 
     } 
     public String getRevCategory() { 
      return revCategory; 
     } 
     public void setRevCategory(String revCategory) { 
      this.revCategory = revCategory; 
     } 
     public boolean isEditable() { 
      return editable; 
     } 
     public void setEditable(boolean editable) { 
      this.editable = editable; 
     } 
     public int getTemplateId() { 
      return templateId; 
     } 
     public void setTemplateId(int templateId) { 
      this.templateId = templateId; 
     } 
     public String getTemplateName() { 
      return templateName; 
     } 
     public void setTemplateName(String templateName) { 
      this.templateName = templateName; 
     } 
     public boolean isChanged() { 
      return changed; 
     } 
     public void setChanged(boolean changed) { 
      this.changed = changed; 
     } 
     public String getRemarks() { 
      return remarks; 
     } 
     public void setRemarks(String remarks) { 
      this.remarks = remarks; 
     } 
     public boolean getWithFinalDocuments() { 
      return withFinalDocuments; 
     } 
     public void setWithFinalDocuments(boolean withFinalDocuments) { 
      this.withFinalDocuments = withFinalDocuments; 
     } 
     public boolean getWithBids() { 
      return withBids; 
     } 
     public void setWithBids(boolean withBids) { 
      this.withBids = withBids; 
     } 
     public boolean isWithBidsChanged() { 
      return withBidsChanged; 
     } 
     public void setWithBidsChanged(boolean withBidsChanged) { 
      this.withBidsChanged = withBidsChanged; 
     } 
     public boolean isWithFinalDocumentsChanged() { 
      return withFinalDocumentsChanged; 
     } 
     public void setWithFnalDocumentsChanged(boolean withFinalDocumentsChanged) { 
      this.withFinalDocumentsChanged = withFinalDocumentsChanged; 
     } 
     public String getVdrNumber() { 
      return vdrNumber; 
     } 
     public void setVdrNumber(String vdrNumber) { 
      this.vdrNumber = vdrNumber; 
     } 
     public int getSortOrder() { 
      return sortOrder; 
     } 
     public void setSortOrder(int sortOrder) { 
      this.sortOrder = sortOrder; 
     } 

} 

Et le code de requête est:

sql = "SELECT -serialno as categoryId, describe as description,16 as divnId, 51 as depttId , NVL2(prnmatter, 'For Review', 'For Record') as revCategory, NVL2(prnquote, 1, 0) as withBids, NVL2(asbuild, 1, 0) as withFinalDocuments, VDRNO as vdrNumber, 0 as editable,100000 as templateId,'Instrumentation' as templateName, 0 as changed, '' as remarks, 0 as withBidsChanged, 0 as withFinalDocumentsChanged, serialno as sortOrder from Instreq.VDRData_to_DCTMVIEW WHERE REQNO=? AND PROJECTNO=? and predate= (SELECT * FROM(SELECT PREDATE FROM Instreq.VDRData_to_DCTMVIEW WHERE REQNO=? AND PROJECTNO=? ORDER BY PREDATE DESC) WHERE ROWNUM=1)"; 
final List<DocumentCategory> dc = jdbcTemplate.queryForList(sql, DocumentCategory.class, orderNumber, mrNumber, orderNumber, mrNumber); 

Répondre

1

Utilisez le query method taking a RowMapper as argument, et transformer chaque ligne renvoyée dans le jeu de résultats en un DocumentCategory grâce à la RowMapper .

queryForList() est utile lorsque la requête renvoie une seule colonne, pour récupérer un List<Integer> ou un List<String> par exemple.

0

Vous pouvez obtenir une liste d'objets de votre type de classe par:

jdbcTemplate.query(sql, new BeanPropertyRowMapper<DocumentCategory>(DocumentCategory.class)); 
Questions connexes