mybatis配置文件

mybatis配置文件可以在测试包里面找,但是总感觉没有自己配置的好看一些,所以放一个在这里

<?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">

 

<mapper namespace="com.ss.mappers.GoodsMapper"><!-- 区分多个文件id重名可写为类名 -->

 

<!--resultMapjava与数据库的映射 typejava类的全名id是取一个名字可以和sql

语句中的id 名一相同也可以不相同只要保证在resultMap这个标签中是唯一的就可以 -->

<!--resultMap子标签就是与sql中对应column是数据库中的名propertyjava

类中的名字jdbcType是java.sql.Type中的 -->

  <resultMap type="Goods"id="GoodsResult">

    <id column="id"jdbcType="INTEGER" property="id"/>

    <result column="Name"jdbcType="VARCHAR" property="name"/>

    <result column="Price"jdbcType="DECIMAL" property="price"/>

    <result column="Count"jdbcType="INTEGER" property="count"/>

  </resultMap>

 

<!--id属性是给这条sql语句起个名字好让java代码找到它,和namespace连用调用的时候用.连接

可以把id属性名可和方法名想同(注 名字唯一性)resultMap表示这条sql语句要用哪一个

resultMap的实体类与sql的对应关系通过id属性名与之相同来确定-->

  <select id="getGoodsById"parameterType="Integer" resultType="Goods">

    SELECT * FROM Goods WHERE id = #{id}

  </select>

 

  <select id="getGoodsByName"parameterType="String" resultMap="GoodsResult">

    SELECT * FROM Goods WHERE Name like #{name}

  </select>

  <!-- 全查询中间类型去掉由resultMap -->

  <select id="getAllGoods"  resultMap="GoodsResult">

    SELECT * FROM Goods

  </select>

  <!-- 添加 -->

  <insert id="addGoods"parameterType="Goods">

    insert into Goods(name,price,count)values(#{name},#{price},#{count})

  </insert>

 

  <update id="updateGoods"parameterType="Goods">

    update Goods setname=#{name},price=#{price},count=#{count} where id=#{id}

  </update>

</mapper>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值