mybatis小结

application.xml

<context:property-placeholder location="config.properties" />-----------加载properties文件

<bean id="c3p0DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"-----配置据库属性
destroy-method="close">

</bean>

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">----读取mybatis.xml配置文件

<property name="dataSource" ref="c3p0DataSource" />
<property name="configLocation" value="MyBatis-Configuration.xml" />
</bean>



MyBatis-Configuration.xml

<configuration>  
    <typeAliases>  
        <typeAlias alias="user" type="daisy.com.Student"/>  
    </typeAliases>       
    <!-- 指定映射文件 -->  
    <mappers>  
        <mapper resource="StudentDaoMapper.xml" />  
    </mappers>  
</configuration> 


映射文件


<?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="daisy.com.StudentMapper">
  <parameterMap type="daisy.com.Student" id="parameterMapStudent">
    <parameter property="id"/>
    <parameter property="name"/>
    <parameter property="classId"/>
  </parameterMap>
  
  <resultMap type="daisy.com.Student" id="resultMapStudent">
    <result property="id" column="id"/>
    <result property="name" column="name"/>
    <result property="classId" column="classId"/>
  </resultMap>
  
  <insert id="insertStudent" parameterMap="parameterMapStudent">
    INSERT INTO Student(id,name,classId)
    VALUES(?,?,?)
  </insert>
  <select id="countAll" resultType="int">
        select count(*) c  from Student;
  </select>
  <select id="getAllStudent"  resultMap="resultMapStudent">
    SELECT * FROM Student
  </select>
  <select id="getById" parameterType="int" resultMap="resultMapStudent">
    SELECT * FROM Student
    WHERE id=#{value}
  </select>
  <delete id="deleteStudent" parameterType="int">
    DELETE FROM Student 
    WHERE id=#{value}
  </delete>
  <update id="updateStudent" parameterType="java.util.Map">
    UPDATE Student
    SET name=#{name}
    WHERE id=#{id}
  </update>
</mapper>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值