小编Har*_*han的帖子

主报表中的多个子报表使用相同的数据源

我有一个主报告和两个子报告。我正在使用自定义数据源来获取报告内容。但在 jasper studio 中预览主报表时,仅显示一个子报表(以先出现的子报表为准)。

例如。仅显示report1.jrxml。如果我删除该子报表,则会显示report2.jrxml。

主.jrxml

<detail>
    <band height="250">
        <subreport runToBottom="true">
            <reportElement positionType="Float" x="0" y="130" width="1960" height="120" uuid="89a9f872-756e-4c82-922d-537cfde30cca"/>
            <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>
            <subreportExpression><![CDATA["report1.jrxml"]]></subreportExpression>
        </subreport>
    </band>
    <band height="250">
        <subreport runToBottom="true">
            <reportElement positionType="Float" x="0" y="90" width="1960" height="120" uuid="892c0849-9532-48cb-94c0-f2e87528232a"/>
            <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>
            <subreportExpression><![CDATA["report2.jrxml"]]></subreportExpression>
        </subreport>
    </band>
</detail>
Run Code Online (Sandbox Code Playgroud)

我已经尝试过以下方法:

  1. 将子报表放置在不同的详细信息区域中。
  2. 将“头寸类型”设置为“浮动”。
  3. 将“运行到底部”属性设置为“True”。

jasper-reports

5
推荐指数
1
解决办法
7029
查看次数

使用PowerMockito模拟最终类中的私有静态方法

我有一个带有私有静态方法的final类,它在另一个静态方法中调用

public final class GenerateResponse{
      private static Map<String, String> getErrorDetails(JSONObject jsonObject) {
         // implementation
      }

      public static String method1(params...){
         Map<String, String> map = getErrorDetails(new JsonObject());

         // implementation
      }
}
Run Code Online (Sandbox Code Playgroud)

我需要模拟私有静态方法调用getErrorDetails(),但我的测试是调用实际方法.这是我的代码:

@RunWith(PowerMockRunner.class)
@PrepareForTest(GenerateResponse.class)
public class GenerateResponseTest{

@Test
public void testFrameQtcErrorResponse() throws Exception {
    Map<String, String> errorDtls = new HashMap<String, String>();

    PowerMockito.spy(GenerateResponse.class);
    PowerMockito.doReturn(errorDtls).when(GenerateResponse.class, "getErrorDetails", JSONObject.class);
    String response = GenerateResponse.method1(params...);
}
Run Code Online (Sandbox Code Playgroud)

java junit mockito powermockito

3
推荐指数
1
解决办法
2983
查看次数

标签 统计

jasper-reports ×1

java ×1

junit ×1

mockito ×1

powermockito ×1