加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xxxMapper.xml简单crud

发布时间:2020-12-16 02:21:34 所属栏目:百科 来源:网络整理
导读:?xml version="1.0" encoding="UTF-8" ?!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"!-- namespce是查找SQL映射文件的唯一标识,必须唯一 --mapper namespace="org.mybatis.example.BlogMappe
<?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会自动自提事物

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读