To initiate a query I use :
org.apache.ibatis.session.SqlSession.seleteList("myquery");
myquery itself is defined within an XML configuration file.
With Spring JDBC as the query statements is defined with the class itself it is very easy find the query associated with a given method call. But with mybatis once I reach the query call I have to search for the argument (in this case "myquery") to discover where the actual query is defined.
Is there an easier method of finding a query associated with a method call instead of manually searching for references ? I'm thinking there isn't as since the query itself is within an XML file not a .java file and IDE maintains a "linking" of methods, constants etc between the files.
There are two ways to do that but you will need to use mapper interfaces.
The first approach is to use IDE plugin. There are several plugins for IntelliJ and some for eclipse. Plugin for IntelliJ says it has
Proxy interfaces support, "Go to Implementaion" jumps right into mapper xml
Another way is to define queries using annotations. In this case queries will be directly in java file.
Define query in mapper interface
interface MyMapper {
@Select("Select * from myentity where id = #id")
MyEntity selectMyEntity(@Param("id") Long id);
}
And then use mapper like usually:
MyMapper mapper = session.getMapper(MyMapper.class);
MyEntity myEntity = mapper.selectMyEntity(101);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments