mybatis XML文件写法

<?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">
<!-- namespace必须指向Dao接口 -->
<mapper namespace="com.ted.safeweb.dao.AdminDao">
    
    <!-- 告诉mybatis,实体类的属性名和表的字段名之间的对应关系 -->
    <resultMap type="com.ted.safeweb.entity.Admin" id="adminMap">
        <result property="id" column="a_id"/>
        <result property="ename" column="a_ename"/>
        <result property="name" column="a_name"/>
        <result property="pwd" column="a_pwd"/>
        <result property="isRoot" column="a_isRoot"/>
    </resultMap>


    <select id="findAdminByName" parameterType="string" resultType="com.ted.safeweb.entity.Admin" resultMap="adminMap">
        SELECT a_id, a_ename,a_name,a_pwd ,a_isRoot FROM a_admin WHERE a_ename=#{string}
    </select>
   
    
    <select id="findAllAdmin"  resultType="com.ted.safeweb.entity.Admin" resultMap="adminMap">
        SELECT a_id, a_ename,a_pwd ,a_name,a_isRoot FROM a_admin WHERE a_isRoot !=1  limit #{0},10 ;
        

    </select>

--LIKE使用

    <select id="findAllAdminT"  resultType="com.ted.safeweb.entity.Admin" resultMap="adminMap">
        SELECT a_id, a_ename,a_pwd ,a_name,a_isRoot FROM a_admin WHERE a_isRoot !=1 and a_name like CONCAT('%',#{1},'%' )   limit #{0},10 ;
        
    </select>
    
    <update id="upadteAdmin" parameterType="com.ted.safeweb.entity.Admin" >
        UPDATE a_admin SET  a_ename =#{ename},a_pwd=#{pwd} ,a_name=#{name} WHERE a_id=#{id}
    </update>
    
    <delete id="deleteAdmoinById" parameterType="int">
        DELETE FROM a_admin WHERE a_id=#{id1};
    </delete>
    
    <insert id="saveAdmin" parameterType="com.ted.safeweb.entity.Admin" >
        INSERT INTO a_admin (a_ename,a_pwd ,a_name,a_isRoot) VALUES(#{ename},#{pwd},#{name},2);

    </insert>

--foreach用法

<insert id="savewtpyList"  parameterType="java.util.List">
        
        insert into xt_wtpy(setup_time,cd,jc_jg,fc_jg ,qm,creator,uuid,delete_mark,createtime) values
            <foreach collection ="list" item="wypy" separator =",">
                 (#{wypy.setup_time},#{wypy.cd} ,#{wypy.jc_jg},#{wypy.fc_jg},#{wypy.qm},#{wypy.creator},#{wypy.uuid},0,current_timestamp)
            </foreach >

    </insert>



</mapper>
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值