I want to know how to use inner class in MyBatis

Asked 2 years ago, Updated 2 years ago, 98 views

<select id="testSql" parameterType="ParameterInfo" resultType="ResultDataInfo">
      SELECT
        col1,
        col2,
        col3
      FROM TEST_TABLE
      WHERE REG_DATE >= date_add(now(), INTERVAL -1 DAY)
            AND co1 = #{col1}
      LIMIT 10
    </select>

I usually map the resultType or parameterType by passing the vo.

Is it possible to use inner class for resultType or parameterType in Mybatis?

mybatis inner-classes

2022-09-22 15:16

1 Answers

It's possible.

However, I think the inner class should be declared static.

package namespace.to
public class Outer {
   public static class InnerA {
      //...
   }
   public static class InnerB {
      //...
   }
   //...
}

If it's the same as above, you can write it as follows.

<select id="testSql" parameterType="namespace.to.Outer$InnerA" resultType="namespace.to.Outer$InnerB">
<!-- ... -->
</select>

When you write Inner class, you can express it by writing $ instead of punctuation (.).


2022-09-22 15:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.