MyBatis的注解
基于注解的mybatis和spring整合:http://huangmin001.iteye.com/blog/1185806
这个文章说的很详细,很值得一看.
Mapper中注解(Annotation)的使用示例:http://puras.cn/mybatis-annotation-example
Mapper:
public interface RoleMapper { final String SELECT_ALL = "SELECT * FROM nap_roles"; final String SELECT_BY_ID = "SELECT * FROM nap_roles WHERE id=#{id}"; final String INSERT = "INSERT INTO nap_roles(name, description, ctime, mtime) VALUES(#{name}, #{description}, #{creationTime}, #{modifiedTime})"; final String UPDATE = "UPDATE nap_roles SET name=#{name}, description=#{description}, mtime=#{modifiedTime} WHERE id=#{id}"; final String DELETE = "DELETE FROM nap_roles WHERE id=#{id}"; final String SELECT_BY_PAGE_BEGIN = "SELECT * FROM nap_roles"; final String SELECT_BY_PAGE_END = " limit #{startPosition}, #{maxResult}"; final String COUNT = "SELECT COUNT(id) FROM nap_roles WHERE 1=1 "; @Insert(INSERT) @Options(useGeneratedKeys = true, keyProperty = "id") void create(Role role); @Update(UPDATE) void update(Role role); @Delete(DELETE) void delete(Long id); @Select(SELECT_ALL) @Results(value = { @Result(property="id"), @Result(property="name"), @Result(property="description"), @Result(property="creationTime", column="ctime"), @Result(property="modifiedTime", column="mtime") }) List findAll(); @SelectProvider(type = RoleProvider.class, method = "findByPage") @Results(value = { @Result(property="id"), @Result(property="name"), @Result(property="description"), @Result(property="creationTime", column="ctime"), @Result(property="modifiedTime", column="mtime") }) List findByPage(Map params); @Select(SELECT_BY_ID) @Results(value = { @Result(property="id"), @Result(property="name"), @Result(property="description"), @Result(property="creationTime", column="ctime"), @Result(property="modifiedTime", column="mtime") }) Role findById(Long id); @SelectProvider(type = RoleProvider.class, method = "getCount") int getCount(Role role); @Select(COUNT) int count();}