zoukankan      html  css  js  c++  java
  • Mybatis之配置文件

    Mybatis_config.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE configuration
    PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-config.dtd">

    <configuration>
    <environments default="Mybatis_a">

    <environment id="Mybatis_a">
    <transactionManager type="jdbc"></transactionManager>
    <dataSource type="pooled">
    <property name="driver" value="com.mysql.cj.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost:3306/mybatis?serverTimezone=Asia/Shanghai&amp;useUnicode=true&amp;characterEncoding=utf8&amp;useSSL=true"/>
    <property name="username" value="root"/>
    <property name="password" value="wpy581"/>
    </dataSource>
    </environment>

    </environments>


    <!--注册-->
    <mappers>
    <mapper resource="cn/scitc/Mapper/StudentMapper.xml"/>
    <mapper resource="cn/scitc/Mapper/TeacherMapper.xml"/>
    </mappers>

    </configuration>


    //StudentMapper.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">

    <mapper namespace="cn.scitc.Mapper.StudentMapper">
    <resultMap id="Student" type="cn.scitc.pojo.Student">
    <result property="id" column="id"/>
    <result property="name" column="name"/>
    <association property="teacher" column="tid" select="TselectInfo" javaType="cn.scitc.pojo.Teacher"/>
    </resultMap>

    <select id="SelectInfo" resultMap="Student">
    select * from student
    </select>

    <select id="TselectInfo" resultType="cn.scitc.pojo.Teacher">
    select * from teacher where id = #{id}
    </select>


    <select id="SelectInfo1" resultMap="Student1">
    select s.id sid,s.name sname,t.id tid,t.name tname from student s,teacher t where s.tid=t.id;
    </select>

    <resultMap id="Student1" type="cn.scitc.pojo.Student">
    <result property="id" column="sid"/>
    <result property="name" column="sname"/>
    <association property="teacher" javaType="cn.scitc.pojo.Teacher">
    <result property="name" column="tname"/>
    <result property="id" column="tid"/>
    </association>
    </resultMap>

    </mapper>





  • 相关阅读:
    C#生成静态两方法
    ASP.NET C# 生成静态页面简单方法
    sql日期格式化
    Div+Css+JS做多个显示/隐藏内容块
    Request获取url各种信息的方法
    asp.net遍历页面所有的按钮(或控件)
    Donews.com:SpyMac.com也提供了1G的Email.
    再见 Swagger UI!国人开源了一款超好用的 API 文档生成框架,Star 4.7K+,真香!!
    面试官:new Object[5] 一共创建了几个对象?
    面试官:select......for update 会锁表还是锁行?别答错了!
  • 原文地址:https://www.cnblogs.com/wpy188/p/12375415.html
Copyright © 2011-2022 走看看