How to generalize similar namespaces of mappers in MyBatis?

588 Views Asked by At

There is an XML mapping associated with an interface FirstMapper:

<mapper namespace="my.very.long.path.to.package.with.mappers.FirstMapper">
  <select id="selectAll" resultType="map">
    SELECT * FROM my_table
  </select> 
</mapper>

The namespace contains full name including the package name, which has the same long prefix for all mappers. Is there a possibility to generalize (or parameterize) this prefix?

For example, instead of mappers with these declarations

1. <mapper namespace="my.very.long.path.to.package.with.mappers.FirstMapper"> ...
2. <mapper namespace="my.very.long.path.to.package.with.mappers.abc.SecondMapper"> ...
3. <mapper namespace="my.very.long.path.to.package.with.mappers.xyz.ThirdMapper"> ...

it would be good to have something similar to

1. <mapper namespace="FirstMapper"> ...
2. <mapper namespace="abc.SecondMapper"> ...
3. <mapper namespace="xyz.ThirdMapper"> ...

or at least

1. <mapper namespace="${nsPrefix}.FirstMapper"> ...
2. <mapper namespace="${nsPrefix}.abc.SecondMapper"> ...
3. <mapper namespace="${nsPrefix}.xyz.ThirdMapper"> ...
0

There are 0 best solutions below