mybatis 在构造函数中使用输入参数作为参数

mybatis use input param as argument in constructor

在mybatis中,我可以在resultMap构造函数中使用输入@Param对象吗?

int test(@Param("param1") someObj obj, @Param("str") String str);

 <resultMap id="testResultMap" type="com.test.someOtherObject">
   <constructor>
      <idArg column="id" javaType="String"/>
      <arg column="<use the input param obj of type someObj>"   javaType="com.test.someObj"/>

否:参数和结果图是两个不同的东西。您不能直接从参数提供结果图。

如果你想让输入参数在结果Map中,那么它必须在结果集中,所以你必须select对应的列,如果你过滤那个列:SELECT col FROM t WHERE col = #{param} 或将其添加为伪列:SELECT '${param}' AS "colName" FROM t 并根据需要使用参数化构造函数照常映射它。

如果构造函数参数是复杂类型,则使用 <arg resultMap="anotherResultMap" /> 而不是 <arg column="col" />