一.对myibatis的认知
我也是刚接触ibatis的,作为数据持久层的框架相比于ibatis我对于hibernate更加的熟悉。 先说说ibatis与hibernate的区别吧。两者都是数据持久层的框架用来表示ORM(对象的关系映射)。而hibernate是一款全自动的ORM,提供了从POJO到数据库表的全套映射机制。程序员往往只需定义好了POJO 到数据库表的映射关系,即可通过 Hibernate 提供的方法完成持久层操作。程序员甚至不需要对 SQL 的熟练掌握,Hibernate 会根据制定的存储逻辑,自动生成对应的 SQL 并调用 JDBC 接口加以执行。到数据库表的全套映射机制,ibatis是一款半自动的ORM,batis 的着力点,则在于POJO 与 SQL之间的映射关系。也就是说,ibatis并不会为程序员在运行期自动生成 SQL 执行。具体的 SQL 需要程序员编写,然后通过映射配置文件,将SQL所需的参数,以及返回的结果字段映射到指定 POJO。
二.ibatis的SQL语句的书写
1.这是xml文件的DTD约束:
2.对应dao层和javaBEAN
3.对应于数据库表的字段名和数据类型
fake_id, create_datetime, update_datetime, employee_uuid, delete_at, approval_uuid,
approval_title, approval_type, approval_status, missions_status, missions_title,
missions_uuid, missions_creator_uuid, approval_creator_uuid, event_todo_uuid
4.查询语句
模糊查询
删除语句
delete from event_todo_info
where fake_id = #{fakeId,jdbcType=INTEGER}
插入语句
insert into event_todo_info (fake_id, create_datetime, update_datetime,
employee_uuid, delete_at, approval_uuid,
approval_title, approval_type, approval_status,
missions_status, missions_title, missions_uuid,
missions_creator_uuid, approval_creator_uuid,
event_todo_uuid)
values (#{fakeId,jdbcType=INTEGER}, #{createDatetime,jdbcType=TIMESTAMP}, #{updateDatetime,jdbcType=TIMESTAMP},
#{employeeUuid,jdbcType=VARCHAR}, #{deleteAt,jdbcType=VARCHAR}, #{approvalUuid,jdbcType=VARCHAR},
#{approvalTitle,jdbcType=VARCHAR}, #{approvalType,jdbcType=VARCHAR}, #{approvalStatus,jdbcType=VARCHAR},
#{missionsStatus,jdbcType=VARCHAR}, #{missionsTitle,jdbcType=VARCHAR}, #{missionsUuid,jdbcType=VARCHAR},
#{missionsCreatorUuid,jdbcType=VARCHAR}, #{approvalCreatorUuid,jdbcType=VARCHAR},
#{eventTodoUuid,jdbcType=VARCHAR})
insert into event_todo_info
fake_id,
create_datetime,
update_datetime,
employee_uuid,
delete_at,
approval_uuid,
approval_title,
approval_type,
approval_status,
missions_status,
missions_title,
missions_uuid,
missions_creator_uuid,
approval_creator_uuid,
event_todo_uuid,
#{fakeId,jdbcType=INTEGER},
#{createDatetime,jdbcType=TIMESTAMP},
#{updateDatetime,jdbcType=TIMESTAMP},
#{employeeUuid,jdbcType=VARCHAR},
#{deleteAt,jdbcType=VARCHAR},
#{approvalUuid,jdbcType=VARCHAR},
#{approvalTitle,jdbcType=VARCHAR},
#{approvalType,jdbcType=VARCHAR},
#{approvalStatus,jdbcType=VARCHAR},
#{missionsStatus,jdbcType=VARCHAR},
#{missionsTitle,jdbcType=VARCHAR},
#{missionsUuid,jdbcType=VARCHAR},
#{missionsCreatorUuid,jdbcType=VARCHAR},
#{approvalCreatorUuid,jdbcType=VARCHAR},
#{eventTodoUuid,jdbcType=VARCHAR},
更新语句
update event_todo_info
create_datetime = #{createDatetime,jdbcType=TIMESTAMP},
update_datetime = #{updateDatetime,jdbcType=TIMESTAMP},
employee_uuid = #{employeeUuid,jdbcType=VARCHAR},
delete_at = #{deleteAt,jdbcType=VARCHAR},
approval_uuid = #{approvalUuid,jdbcType=VARCHAR},
approval_title = #{approvalTitle,jdbcType=VARCHAR},
approval_type = #{approvalType,jdbcType=VARCHAR},
approval_status = #{approvalStatus,jdbcType=VARCHAR},
missions_status = #{missionsStatus,jdbcType=VARCHAR},
missions_title = #{missionsTitle,jdbcType=VARCHAR},
missions_uuid = #{missionsUuid,jdbcType=VARCHAR},
missions_creator_uuid = #{missionsCreatorUuid,jdbcType=VARCHAR},
approval_creator_uuid = #{approvalCreatorUuid,jdbcType=VARCHAR},
event_todo_uuid = #{eventTodoUuid,jdbcType=VARCHAR},
where fake_id = #{fakeId,jdbcType=INTEGER}
update event_todo_info
set create_datetime = #{createDatetime,jdbcType=TIMESTAMP},
update_datetime = #{updateDatetime,jdbcType=TIMESTAMP},
employee_uuid = #{employeeUuid,jdbcType=VARCHAR},
delete_at = #{deleteAt,jdbcType=VARCHAR},
approval_uuid = #{approvalUuid,jdbcType=VARCHAR},
approval_title = #{approvalTitle,jdbcType=VARCHAR},
approval_type = #{approvalType,jdbcType=VARCHAR},
approval_status = #{approvalStatus,jdbcType=VARCHAR},
missions_status = #{missionsStatus,jdbcType=VARCHAR},
missions_title = #{missionsTitle,jdbcType=VARCHAR},
missions_uuid = #{missionsUuid,jdbcType=VARCHAR},
missions_creator_uuid = #{missionsCreatorUuid,jdbcType=VARCHAR},
approval_creator_uuid = #{approvalCreatorUuid,jdbcType=VARCHAR},
event_todo_uuid = #{eventTodoUuid,jdbcType=VARCHAR}
where fake_id = #{fakeId,jdbcType=INTEGER}