zoukankan      html  css  js  c++  java
  • MyBatis环境搭建配置文件+入门视频下载

    1、MyBatis优点
    操作简单话,代码量少,效率高,成本就降低了
    2、MyBatis缺点
    参数只能限制为一个
    selece语都要手动来写

    3、与JDBC的关系:是对JDBC的扩展
    把sql语句和java代码分离后,改了sql语句不用改动java代码

    <!--SqlMapConfig.xml配置文件-->

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE sqlMapConfig
    PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
    "http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
    <sqlMapConfig>
    <!--导入数据库连接配置信息 -->
    <properties resource="SqlMap.properties"></properties>
    <!-- type="JDBC"表示使用jdbc 进行事务管理SIMPLE 使用简单的方式-->
    <transactionManager type="JDBC">
    <dataSource type="SIMPLE">
    <property name="JDBC.Driver" value="${driver}"></property>
    <property name="JDBC.ConnectionURL" value="${url}"></property>
    <property name="JDBC.Username" value="${username}"></property>
    <property name="JDBC.Password" value="${password}"></property>
    </dataSource>
    </transactionManager>

    <!-- 映射文件 -->
    <sqlMap resource="entity/Student.xml"/>

    </sqlMapConfig>

    <!--SqlMap.properties 文件-->

    driver=oracle.jdbc.driver.OracleDriver
    url=jdbc:oracle:thin:@localhost:1521:ORCL
    username=scott
    password=abc123

    <!-- Student映射文件 -->

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE sqlMap
    PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
    "http://ibatis.apache.org/dtd/sql-map-2.dtd">

    <sqlMap>
    <!-- 给操作的类取个别名 以便下面好用 -->
    <typeAlias alias="Student" type="entity.Student"/>

    <!--selectAllStudent相当于下面查询语句的一个别称 -->
    <select id="selectAllStudent" resultClass="Student">
    select * from Student
    </select>

    <!--parameterClass 传进来的参数类型 -->
    <select id="selectStudentById" parameterClass="int" resultClass="Student">
    select * from Student where sid=#sid#
    </select>

    <!--添加类型要一一对应,不然会类型转换报错 没有返回值类型就不用配置 resultClass属性-->
    <insert id="insertStudent" parameterClass="Student" >
    insert into Student(sid,sname,major,birth,score) values(#sid#,#sname#,#major#,#birth#,#score#)
    </insert>

    <!-- 中间的那个配置表示去查找序列 把序列的下一个值付给Strudent对象中的一个属性 -->
    <insert id="insertStudentBySequence" parameterClass="Student">
    <selectKey resultClass="int" keyProperty="sid">
      select seqenct_student.nextVal from dual
    </selectKey>
      insert into Student(sid,sname,birth,major,score)
      values(#sid#,#sname#,#birth#,#major#,#score#)
    </insert>
    <!--删除对象-->
    <delete id="deleteStudentById" parameterClass="int">
    delete from Student where sid=#sid#
    </delete>

    <!--修改信息-->
    <update id="updateStudentById" parameterClass="Student">
    update Student
    set sname=#sname#,
    major=#major#,
    birth=#birth#,
    score=#score#
    where sid=#sid#
    </update>

    <!-- 模糊查询 -->
    <select id="selectStudentByName" parameterClass="String" resultClass="Student">
    select sid,sname,major,birth,score from Student
    where sname like '%$sname$%'
    </select>
    </sqlMap>

    入门教学视频下载链接:http://pan.baidu.com/s/1laU4m

  • 相关阅读:
    如何打开“USB调试”模式?
    Eclipse常用配置
    【luogu P5363】移动金币(博弈论)(DP)(数位DP)(MTT)
    【luogu P4245】【模板】任意模数多项式乘法(拆系数FFT)(MTT)
    【ybtoj高效进阶 21178】星际大战(并查集)
    【ybtoj高效进阶 21177】小小网格(杜教筛)(数论分块)(莫比乌斯反演)
    【luogu P4213】【模板】杜教筛(Sum)(数学)(整除分块)
    【luogu P6860】象棋与马(数学)(杜教筛)
    【luogu AT2376】Black and White Tree(结论)(博弈论)(二分图)
    SAM入门三题:字符串水题, LCS, P5546 [POI2000]公共串
  • 原文地址:https://www.cnblogs.com/laotan/p/3653142.html
Copyright © 2011-2022 走看看