The annotation-based MyBatis Mapper interface feature is not mapper rich in XML configuration files, and the flexibility of dynamic SQL statements cannot be compared to XML configuration.
Here are just a few notes-based dynamic SQL considerations:
MyBatis provides annotation @InsertProvider, @UpdateProvider, @DeleteProvider, and @SelectProvider to provide dynamic SQL functionality.
There are only 2 possible methods of providing dynamic SQL: No parameters and one parameter. One parameter is divided into 2 cases: The parameter type is the same as the Mapper interface method parameter, and the other is the map<string,object> type parameter. That is to say, you have a lot of mapper interface method parameters, and MyBatis will put them in the map. This method of providing dynamic SQL can be obtained from the map.
The method of providing dynamic SQL differs greatly from the XML configuration of dynamic SQL. The way to provide dynamic SQL is mostly to assemble the SQL yourself (the org.apache.ibatis provided by MyBatis. Jdbc. SQL functionality is also very restrictive, and the XML configuration (MyBatis has its own dynamic SQL syntax) dynamic sql,mybatis resolves and assembles SQL itself.
If there are multiple arguments to the Mapper interface method, you need to @param annotations (no, MyBatis automatically generate Parm{i}, etc.), because the reflection will not get the parameter name until JAVA8 by turning on the compile parameter-parameters. So the mybaitis is only obtained by means of the method parameter annotations. The method parameters in Spring mvc are manipulated by byte code.
Try to combine the Mapper interface with XML configuration.
If you are dynamically creating a table function, use ${}, the string is replaced directly instead of #{} (MyBatis is assigned a value with typehandlers)
If the mybatis corresponding Java type and database type do not have a corresponding mapping relationship (value Assignment), you can only write typehandlers by yourself , to mybatis configuration implementation. For example, the new time type for JAVA8 MyBatis is not supported yet.
It is recommended that you read the English version of Java persistence with MyBatis 3 more times
Posted in: http://www.oschina.net/question/2254200_235052
Annotations-based MyBatis Mapper interface considerations