【问题标题】:Does Spring Roo build the html templates for the finders?Spring Roo 是否为查找器构建 html 模板?
【发布时间】:2017-03-10 14:59:06
【问题描述】:

我正在使用 Spring Roo 2 RC1 和 Spring Tool Suite 3.8.3。我建立了一个项目来列出 MySQL 表的内容并允许我对其进行编辑。除了发现者之外,一切都在工作。他们没有出现在网络应用程序上。这是因为我必须自己配置那部分吗?下面是我的 log.roo 文件。

// 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 表单 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 finder”命令重新构建查找器。我删除了 web 包下的搜索实体。然后我再次输入“web mvc finder --all --responseType THYMELEAF”。 Spring Roo 为我重新生成了查找器。

【问题讨论】:

    标签: spring-roo


    【解决方案1】:

    Spring Roo 2.0.0.RC1 提供了在 Spring Data Repositories 中创建新查找器所需的命令。创建完成后,它会提供必要的命令将它们发布到 Web 层。

    并非每个查找器都可以发布到网络层。

    正如我在您的log.roo 中看到的那样,您的所有查找器都使用默认的 Spring Data 命名法findBy,而没有将投影指定为 defaultReturnType 或将 DTO 指定为 formBean。如您所见,它们仅在接口 ~.repository.SfdcAccountRepository 中生成,因为它们不使用 QueryDSL 实现。

    可以发布到 web 层的 finder 方法需要一些特定的参数才能与 DataTables 组件一起正常工作。所以,只有像下面这样生成的finder才能被发布。

    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 项目的贡献!

    希望对你有帮助!

    【讨论】:

    • 我添加了一个 DTO,但我仍然无法让 web mvc finder 命令正常工作。我在最初的问题中添加了更多信息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-13
    • 1970-01-01
    相关资源
    最近更新 更多