最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

詳解Mybatis(五)Mapper接口

 更新時(shí)間:2019年04月09日 11:55:06   作者:bettermanZYQ  
這篇文章主要介紹了Mybatis Mapper接口,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

(1)Mapper接口和原理

Mapper組建

  1. 1、Mapper文件和Mapper接口應(yīng)該放在同一個(gè)接口中
  2. 2、Mapper文件中的namespace應(yīng)該設(shè)置為Mapper接口的全限定名稱
  3. 3、Mapper文件中的操作元素ID對(duì)應(yīng)Mapper接口的方法名稱

Mapper原理:
動(dòng)態(tài)代理

(2)配置文件

userMapper.xml

<?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">
<!-- 為這個(gè)mapper指定一個(gè)唯一的namespace,namespace的值習(xí)慣上設(shè)置成包名+sql映射文件名,這樣就能夠保證namespace的值是唯一的
例如namespace="me.gacl.mapping.userMapper"就是me.gacl.mapping(包名)+userMapper(userMapper.xml文件去除后綴)
 -->
<mapper namespace="Mybatis.domain.Mapper.UserMapper">

  <resultMap type="User" id="BaseResultMap">
  	<result column="t_id" property="id"/>
  	<result column="t_name" property="name"/>
  	<result column="t_salary" property="salary"/>
  </resultMap>
  
  <!-- 保存操作 -->
  <insert id="save" useGeneratedKeys="true" keyProperty="id">
	  INSERT INTO t_user (name , salary) 	VALUES (#{name},#{salary}) 	
  </insert>
  
  <!-- 更改操作 -->
  <update id="update">
  	update t_user where name=#{name},salary=#{salary} where id=#{id}
  </update>
  
  <!-- 刪除操作 -->
  <delete id="delete" >
  	delete from t_user where id=#{id}
  </delete>
  
  <!-- 查詢單個(gè)操作 --> 
  <select id="select" parameterMap="java.lang.Long" resultType="Mybatis.domain.User">
    select * from t_user where id = #{id}
  </select>

	<!-- 查詢多個(gè)操作 -->
	<select id="selectAll" resultType="User">
		select id,name,salary from t_user
	</select>  
</mapper>

UserMapper.java

import java.util.List;

import Mybatis.domain.User;

public interface UserMapper {
	void save(User u);
	
	void update(User u);
	
	void delete(Long id);
	
	User select(User u);
	
	List<User> selectAll();
}

以上所述是小編給大家介紹的Mybatis Mapper接口詳解整合,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論

旬阳县| 射阳县| 涟源市| 台湾省| 淮阳县| 涡阳县| 锦屏县| 简阳市| 水城县| 宣威市| 郴州市| 盐津县| 长葛市| 鄂州市| 芜湖市| 桦甸市| 崇信县| 玛沁县| 吴旗县| 马山县| 铁岭县| 明光市| 清镇市| 交口县| 汕头市| 合作市| 咸宁市| 赫章县| 霞浦县| 余干县| 南部县| 沧源| 于都县| 新竹市| 汾阳市| 福建省| 高台县| 河东区| 壶关县| 九台市| 张北县|