Skip to content

导出可以提供instance类型的支持吗 #366

@en-o

Description

@en-o

Search before asking

  • I searched in the issues and found nothing similar.

Motivation

原因

我习惯使用Jpa, 在jpa中使用projections时,用情况使用instance作为返回来,有些特性在低版本中不支持class方式,我在使用过程中发现查询的数据在导出的时候出现converter失败问题

    Specification<LogExport> beanWhere = EnhanceSpecification.beanWhere(page);

        List<LogExport> all = userManageLogService.getJpaBasicsDao().findBy(beanWhere, query ->
                        query.project( "operator",
                                        "operatorTime",
                                        "dataType",
                                        "event",
                                        "eventDescription")
                                .as(LogExport.class)
                                .all());

        HttpServletResponse responseHeader = ResponseFile.xlsxResponse(response
                , "日志-" + DateTime.now().toString("yyyyMMddHHmmss"));
        ExcelWriterBuilder excelWriterBuilder = write(responseHeader.getOutputStream())
                .head(LogExport.class);
        excelWriterBuilder.registerConverter(new LongStringConverter())
                .sheet("日志")
                .doWrite(all);
public interface LogExport {
    String getOperator();

    String getOperatorTime();

    String getDataType();

    String getEvent();

    String getEventDescription();


}

我的观测

我debug发现 ExcelWriteAddExecutor#addOneRowOfDataToExcel 方法中判断类型非map和List就使用addJavaObjectToExcel,在addJavaObjectToExcel BeanMap beanMap = BeanMapUtils.create(oneRowData); 时导致的失败

我的临时办法

重新构建了一个返回class类的查询(这样写这没有直接使用projections方便

Solution

No response

Alternatives

No response

Anything else?

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is neededquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions