<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!-- namespce是查找sql映射文件的唯一标识,必须唯一 --> <mapper namespace="org.mybatis.example.BlogMapper"> <!-- id是sql映射文件中方法的唯一标识 --> <!-- parameterType是参数数据类型 --> <!-- resultType是实体类的全类名 --> <select id="getBlog" parameterType="int" resultTYpe="org.mybatis.example.Blog"> select * from Blog where id = #{id} </select> <!--新增时parameterType是对象类型,值为全类名 --> <insert id="addBlog" parameterType="org.mybatis.example.Blog"> <!-- 占位符中的名称要和对象的属性名称一致 --> insert into blog(name,age) values(#{name},#{age}) </insert> <delete id="deleteBlog" parameterType="int"> delete from blod where id=#{id} </delete> <update id="updateBlog" parameterType="org.mybatis.example.Blog"> update blog set name=#{name},age=#{age} where id=#{id} </update> </mapper>
factory.openSession(true);//true会自动自提事物