2017-03-10 105 views
0

我使用Spring Roo 2 RC1和Spring Tool Suite 3.8.3。我建立了一個項目來列出MySQL表格的內容並允許我編輯它。除了發現者之外,一切都在工作。他們沒有顯示在網絡應用程序。這是因爲我必須自己配置那部分?以下是我的log.roo文件。Spring Roo是否構建查找器的html模板?

// Spring Roo 2.0.0.RC1 [rev 28015e3] log opened at 2017-03-07 14:07:55 
project setup --topLevelPackage org.oclc --projectName "sfdcIntegration" --java 8 --packaging JAR 
// Spring Roo 2.0.0.RC1 [rev 28015e3] log closed at 2017-03-07 14:07:57 
// Spring Roo 2.0.0.RC1 [rev 28015e3] log opened at 2017-03-07 14:08:00 
jpa setup --provider HIBERNATE --database MYSQL 
entity jpa --class ~.domain.SfdcAccount --table sfdc_account --identifierColumn account_id --identifierStrategy AUTO --sequenceName sequenceName --identifierType java.lang.Integer 
field string --fieldName sfdcRecordId --column sfdc_record_id --sizeMax 18 
field string --fieldName siebelRowId --column siebel_row_id --sizeMax 18 
field string --fieldName sfdcParentId --column sfdc_parent_id --sizeMax 18 
field string --fieldName siebelParentId --column siebel_parent_id --sizeMax 15 
field string --fieldName sfdcRecordTypeId --column sfdc_record_type_id --sizeMax 18 
field string --fieldName siebelRecordTypeId --column siebel_record_type_id --sizeMax 30 
field string --fieldName siebelResponsibleInstitutionName --column siebel_responsible_institution_name --sizeMax 15 
field string --fieldName responsibleInstitutionSymbol --column responsible_institution_symbol --sizeMax 40 
field string --fieldName billingStreet --column billing_street --sizeMax 255 
// [failed] field string --fieldName billingStreet --column billing_street --sizeMax 255 
field string --fieldName billingCity --column billing_city --sizeMax 40 
field string --fieldName billingState --column billing_state --sizeMax 80 
field string --fieldName billingPostalCode --column billing_postal_code --sizeMax 45 
field string --fieldName billingCountry --column billing_country --sizeMax 80 
field string --fieldName name --column name --sizeMax 255 
// [failed] field string --fieldName name --column name --sizeMax 255 
field string --fieldName fax --column fax --sizeMax 40 
field string --fieldName shippingStreet --column shipping_street --sizeMax 255 
field string --fieldName shippingCity --column shipping_city --sizeMax 40 
field string --fieldName shippingState --column shipping_state --sizeMax 80 
field string --fieldName shippingPostalCode --column shipping_postal_code --sizeMax 45 
field string --fieldName shippingCountry --column shipping_country --sizeMax 80 
field string --fieldName oclcAccountId --column oclc_account_id --sizeMax 50 
field string --fieldName oclcRegistryId --column oclc_registry_id --sizeMax 15 
field string --fieldName accountType --column account_type --sizeMax 40 
field string --fieldName dataCenter --column data_center --sizeMax 15 
field number --fieldName designatedVotingMember --type byte --column designated_voting_member 
exit 
// Spring Roo 2.0.0.RC1 [rev 28015e3] log closed at 2017-03-07 14:28:15 
// Spring Roo 2.0.0.RC1 [rev 28015e3] log opened at 2017-03-07 16:51:41 
field number --fieldName disableMailing --type byte --class ~.domain.SfdcAccount --column disable_mailings 
field number --fieldName oclcBoardOfTrustees --type byte --column oclc_board_of_trustees 
field number --fieldName apCouncilExecutiveCommittee --type byte --column ap_council_executive_committee 
field number --fieldName oclcGlobalCouncil --type byte --column oclc_global_council 
field number --fieldName oclcArcExecutiveCommittee --type byte --column oclc_arc_executive_committee 
field string --fieldName memberStatus --column member_status --sizeMax 30 
field string --fieldName accountStatus --column account_status --sizeMax 30 
field string --fieldName currencyIsoCode --column currency_iso_code --sizeMax 40 
field string --fieldName accountSubType --column account_sub_type --sizeMax 15 
field string --fieldName groupNumber --column group_number --sizeMax 22 
field string --fieldName groupType --column group_type --sizeMax 50 
field string --fieldName groupCode --column group_code --sizeMax 30 
field string --fieldName primaryLibraryType --column primary_library_type --sizeMax 100 
field string --fieldName secondaryLibraryType --column secondary_library_type --sizeMax 100 
field string --fieldName salesRep --column sales_rep --sizeMax 255 
field string --fieldName ownerName --column owner_name --sizeMax 255 
field number --fieldName sfdcAccountStatus --type java.lang.Long --column sfdc_account_status 
field number --fieldName sfdcLastUpdatedFlag --type byte --column sfdc_last_updated_flag 
field date --fieldName sfdcLastUpdatedDate --type java.util.Calendar --column sfdc_last_updated_date --persistenceType JPA_TIMESTAMP --dateTimeFormatPattern SS 
field number --fieldName siebelLastUpdatedFlag --type byte --column siebel_last_updated_flag 
field date --fieldName siebelLastUpdatedDate --type java.util.Calendar --column siebel_last_updated_date --persistenceType JPA_TIMESTAMP --dateTimeFormatPattern MM 
field string --fieldName lastUpdatedBy --column last_updated_by --sizeMax 45 
field date --fieldName lastUpdatedDate --type java.util.Calendar --column last_updated_date --persistenceType JPA_TIMESTAMP --dateTimeFormatPattern MM 
field string --fieldName sfdcResponsibleInstitutionName --column sfdc_responsible_institution_name --sizeMax 18 
field number --fieldName newRecordFlag --type byte --column new_record_flag 
field number --fieldName isDeleted --type byte --column isDeleted 
field number --fieldName loadId --type java.lang.Integer --column load_id 
field number --fieldName activeFlag --type byte --column active_flag 
field number --fieldName sfdcSent --type byte --column sfdc_sent 
field string --fieldName region --column region --sizeMax 45 
field number --fieldName relation --type byte --column relation 
field number --fieldName hasError --type byte --column has_error 
field number --fieldName siebelSent --type byte --column siebel_sent 
repository jpa --all 
finder add --entity ~.domain.SfdcAccount --name findByOclcAccountId 
finder add --entity ~.domain.SfdcAccount --name findBySfdcRecordId 
finder add --entity ~.domain.SfdcAccount --name findBySiebelRowId 
// [failed] finder add --entity ~.domain.SfdcAccount --name findByOclcSymbol 
field string --fieldName oclcSymbol --column oclc_symbol --sizeMax 12 
hint 
finder add --entity ~.domain.SfdcAccount --name findByOclcSymbol 
service --all 
web mvc setup 
web mvc view setup --type THYMELEAF 
web mvc templates setup --type THYMELEAF 
web mvc controller --entity ~.domain.SfdcAccount --responseType THYMELEAF 
web mvc finder --all --responseType THYMELEAF 
exit 
// Spring Roo 2.0.0.RC1 [rev 28015e3] log closed at 2017-03-07 18:37:44 
// Spring Roo 2.0.0.RC1 [rev 28015e3] log opened at 2017-03-08 13:38:19 
exit 
// Spring Roo 2.0.0.RC1 [rev 28015e3] log closed at 2017-03-08 18:04:35 
// Spring Roo 2.0.0.RC1 [rev 28015e3] log opened at 2017-03-09 09:35:01 
// [failed] web mvc finder --entity ~.domain.SfdcAccount --package org.oclc.web --pathPrefix 'find' --queryMethod findBy --responseType THYMELEAF 
// [failed] web mvc finder --entity ~.domain.SfdcAccount --package org.oclc.web --pathPrefix 'find' --queryMethod findBySiebelRowId --responseType THYMELEAF 
web mvc finder --all --responseType THYMELEAF --pathPrefix 'find' 
exit 
// Spring Roo 2.0.0.RC1 [rev 28015e3] log closed at 2017-03-09 10:23:10 
// Spring Roo 2.0.0.RC1 [rev 28015e3] log opened at 2017-03-09 12:06:44 
finder add --entity ~.domain.SfdcAccount --name findByOclcSymbolEqualsIgnoreCase 
hint 
web mvc finder --all --responseType THYMELEAF 
service --all 
web mvc templates setup --type THYMELEAF 
web mvc finder --entity ~.domain.SfdcAccount --responseType THYMELEAF 
// [failed] web mvc finder --entity ~.domain.SfdcAccount --queryMethod findByOclcSymbolEqualsIgnoreCase 
// [failed] web mvc finder --entity ~.domain.SfdcAccount --queryMethod findByOclcAccountId findByOclcSymbolEqualsIgnoreCase 
// [failed] web mvc finder --entity ~.domain.SfdcAccount --queryMethod findByOclcAccountId 
// [failed] web mvc finder --entity ~.domain.SfdcAccount --queryMethod findByOclcAccountId, findBySfdcRecordId, findBySiebelRowId, findByOclcSymbol, findByOclcSymbolEqualsIgnoreCase 
// [failed] web mvc finder --entity ~.domain.SfdcAccount --queryMethod SfdcAccount.class 
// [failed] web mvc finder --entity ~.domain.SfdcAccount --queryMethod SfdcAccount 
// [failed] web mvc finder --entity ~.domain.SfdcAccount --queryMethod findBy 
// Spring Roo 2.0.0.RC1 [rev 28015e3] log closed at 2017-03-09 18:39:52 

我創建了一個DTO的form bean如下:

dto --class ~.domain.SiebelRowIdFormBean 
field string --fieldName siebelRowId --sizeMax 18 
finder add --entity ~.domain.SfdcAccount --name findBySiebelRowIdEquals --formBean ~.domain.SiebelRowIdFormBean 

但是當我嘗試發佈它,我必須提供pathPrefix。我無法弄清楚pathPrefix是什麼。這是我輸入的內容:

web mvc finder --entity ~.domain.SfdcAccount --responseType THYMELEAF --queryMethod findBySiebelRowIdEquals --package org.oclc.web --pathPrefix sfdcaccounts/search 

,但我得到這個錯誤:

ERROR: Already exists a controller associated to entity 'SfdcAccount' in the same package 'org.oclc.web', with different 'pathPrefix'. Specify a different 'pathPrefix' and a different package that the existing one to create a new one, or the same 'package' and 'pathPrefix' to update the existing controller. 

我想我找到了通過「Web MVC框架的取景器」命令,如何重新構建發現者。我刪除了網絡包下的搜索實體。然後我再次輸入「web mvc finder --all --responseType THYMELEAF」。 Spring Roo爲我重新發現了發現者。

回答

1

Spring Roo 2.0.0.RC1提供了在Spring Data Repositories中創建新查找器的必要命令。在創建之後,它提供了將它們發佈到Web層的必要命令。

但是並非每個發現者都可以發佈到網絡層

正如我在log.roo中看到的,您的所有查找器都使用默認的彈簧數據命名法findBy,而無需將投影指定爲defaultReturnType或DTO作爲formBean。正如您可以檢查的那樣,它們只是在干擾表面~.repository.SfdcAccountRepository中生成的,因爲它們不使用QueryDSL實現。

可以發佈到Web層的查找方法需要一些特定的參數才能正確處理DataTables組件。所以,只有像下面這樣生成的發現者才能發佈。

finder add --entity ~.domain.ENTITY --name findByFIELD --formBean ~.domain.DTO 

嘗試使用DTO作爲你的一些發現者以上,之後的的formBean,使用web mvc finder命令發佈取景器。

你會看到這個工作正常!

也許這在Spring Roo參考指南中並不十分清楚,所以我剛剛創建了以下任務來檢查它。

https://jira.spring.io/browse/ROO-3903

感謝您的Spring Roo的項目的貢獻!

希望它有幫助!

+0

我添加了一個DTO,但我仍然無法讓web mvc finder命令工作。我在最初的問題中增加了更多信息。 –