基于注解的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();
}
在使用比较复杂的SQL时,会用到各种Provider来处理。
虽然都改用Annotation了,但还有些地方不是特别的爽。
1、ResultMap,不知道怎么来定义一个对象,所有的都引用一个;
2、所有的SQL都写到JAVA里了,修改起来,也是件麻烦事。
分享到:
相关推荐
mybatis注解
spring mvc mybatis 注解版 可直接使用
mybatis 注解+配置文件方式完整例子 包含数据库的sql文件. 所有方法都有注解, 很明了.不知道为啥这个所需积分竟然逐步增长了,描述文字也50起步了。。
【MyBatis学习笔记五】——MyBatis注解的简单使用.zip 博客地址:https://blog.csdn.net/weixin_43817709/article/details/117407621
java工程,练习通过MyBatis注解的方式配置SQL映射器,实现动态SQL.
基于MyBatis注解的学生管理程序-ssm彻底掌握的练手项目 1.包含项目所有需要的离线jar junit-4.7 log4j-1.2.16 mybatis-3.2.2-sources mybatis-3.3.0 mysql-connector-java-5.1.0-bin mysql-connector-java-8.0.26 2....
在做基于SSM框架时,因用的是全注解模式开发,在做些查询+分页工作时Mybatis注解并不能很好的进行sql编写,因而用到了这个java类,对实现了sql语句的拼接。
springboot与mybatis集成,注解版与配置版,下载可运行。集成过程可参考博客https://blog.csdn.net/m0_37984249/article/details/80923212
Cause: java.lang.ClassNotFoundException: Cannot find class: student 当你使用mybatis注解别名找不到文件时,在你的mybatis配置文件中加入 注意标签一定要放在标签下面
idea的一个demo,里面包含了一个测试方法。----------------------------------------------------------------------------------------------------------------------------------------------------------------...
2、工具主要针对SpringMvc+Mybatis注解+Mysql生成对象,dao、sqlDao、interface、实现接口 3、根据表生成Excel 4、生成成功后倒入到自己对应的项目中,然后Ctrl+Shipt+O(Eclipse快速倒入包)实现 5、里面因为运用的...
Mybatis系列教程Mybatis注解开发共9页.pdf.zip
MyBatis注解基本使用
简单的MyBatis开发案例,内含增加,删除,修改,列表查询,数量查询等等,有改进的地方,请多指正。
springboot + mybatis 注解实现操作
Mybatis注解开发源代码下载
mybatis 注解方式实现数据的加解密。目前仅支持使用了TkMapper和MyBatis Plus框架的项目
采用eclipse tomcat8.0 以及jdk1.8快速整合的SpringBoot+maven+MyBatis注解框架包含操作文档( https://blog.csdn.net/qq_34492495/article/details/82992094)
ssm+maven+mybatis注解+mysql+restful,Java1.7,tomcat8.0.6以上。我实在是被各种版本不兼容恶心到了,如果你也一样,恭喜你找到了这个项目,此项目各种兼容性已经被调整到最佳。而且已经写了分页,数据库在src目录...
Spring+Springmvc+Mybatis注解开发配置,简单实现增删改差,访问路径为 http://localhost:8080/项目名/student/loadList.do,就可以实现效果,