@Mapper role that can automatically generate a class that implements an interface to the mapper, so spring for bean mapper interface to manage, and can be omitted to write complex xml file
Here borrow a piece of code
/ UserDAO Import org.apache.ibatis.annotations.Mapper; Import org.apache.ibatis.annotations.Param; Import org.apache.ibatis.annotations.Select; Import ; entity.User / ** * After adding a comment @Mapper this interface will be generated at compile time corresponding implementation class * * Note that: this interface can not define a method with the same name, as it will generate the same of the above mentioned id * that is not supported by this interface is overloaded * / @Mapper public interface the UserDAO { @Select ( "SELECT * WHERE name from User name = # {}" ) public the User Find (String name); @Select ( "SELECT * WHERE from User name {name = # = # {} and pwd pwd } " ) / ** * For multiple parameters, it should be added @Param comment before each parameter, * or else will not find the corresponding parameters and then error * / public the User the Login (@Param ( "name") String name, @Param ( "pwd" ) String pwd); }
However, been to their own test, used to write xml, xml file using @mapper will come in, but if xml and @select exist, will complain, can only use one