Mybatis映射文件完整模板參照


Mybatis映射文件完整模板參照

<?xml version="1.0" encoding="UTF-8" ?>  
<!DOCTYPE mapper PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"      
 "http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">

<mapper namespace="test">
	<!-- parameterType:參數類型,填寫實體類的完整名字 -->
	<insert id="save" parameterType="cn.chentging.mybatis.entity.Employee">
		insert into net_t_emp values(net_t_emp_seq.nextval,#{name},#{age})
	</insert>
	
	<select id="findAll" resultType="cn.chentging.mybatis.entity.Employee">
		select * from net_t_emp
	</select>
	
	<select id="findById" parameterType="int" resultType="cn.chentging.mybatis.entity.Employee">
		select * from net_t_emp where id=#{id1}
	</select>
	
	<update id="modify" parameterType="cn.chentging.mybatis.entity.Employee">
		update net_t_emp set name=#{name},age=#{age} where id=#{id}
	</update>
	
	<delete id="delete" parameterType="int">
		delete from net_t_emp where id=#{id1}
	</delete>
	
	<!-- 返回Map類型的結果  map是java.util.Map的簡寫形式-->
	<select id="findById2" parameterType="int" resultType="map">
		select * from net_t_emp where id=#{id1}
	</select>
	
	<!-- 使用resultMap解決表的字段名與實體類的屬性名不一致的情況 -->
	<resultMap type="cn.chentging.mybatis.entity.Emp" id="empRestultMap">
		<result property="empNo" column="id"/>
		<result property="ename" column="name"/>
	</resultMap>
	
	<select id="findById3" parameterType="int" resultMap="empRestultMap">
		select * from net_t_emp where id=#{id1}
	</select>
</mapper>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM