zoukankan      html  css  js  c++  java
  • 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">
    <!--绑定一个对应的Dao/Mapper接口-->
    
    <mapper namespace="com.liu.dao.StudentMapper">
        <select id="getStudents" resultType="student">
            select s.id,s.u_name,s.tid,t.t_name from student s,teacher t  where s.tid=t.id;
        </select>
    
    
    
        <resultMap id="studentTeacher" type="Student">
            <result column="id" property="id" />
            <result column="u_name" property="u_name" />
            <result column="tid" property="tid" />
            <association property="teacherss" column="tid" javaType="Teacher" select="getTeacher" />
        </resultMap>
        <select id="getStudents2" resultMap="studentTeacher">
            select * from student;
        </select>
        
        
        
    
        <resultMap id="studentTeacher3" type="Student">
            <result column="sid" property="id" />
            <result column="uname" property="u_name" />
            <result column="tid" property="tid" />
            <association property="teacherss"  javaType="Teacher">
                <result property="t_name" column="tname"></result>
            </association>
        </resultMap>
        <select id="getStudents3" resultMap="studentTeacher3">
            select s.id sid ,s.u_name uname,s.tid tid,t.t_name tname from student s,teacher t  where tid=t.id;
        </select>
    
    
    
    
    
        
        <select id="getTeacher" resultType="Teacher">
            select * from teacher  where id= #{id};
        </select>
    
    </mapper>
    <?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>
        <properties resource="db.properties" />
    
        <settings>
            <setting name="logImpl" value="STDOUT_LOGGING"/>
        </settings>
        <typeAliases>
            <package name="com.liu.pojo" />
        </typeAliases>
    
    
        <environments default="development">
            <environment id="development">
                <transactionManager type="JDBC"/>
                <dataSource type="POOLED">
                    <property name="driver" value="${driver}"/>
                    <property name="url" value="${url}"/>
                    <property name="username" value="${username}"/>
                    <property name="password" value="${password}"/>
                </dataSource>
            </environment>
        </environments>
    <!--绑定接口-->
        <mappers>
            <package name="com.liu.dao"/>
        </mappers>
    
    </configuration>
  • 相关阅读:
    学习Android有感!
    使用PHP-Barcode轻松生成条形码(一)
    php利用redis实现分页列表,新增,删除功能
    JS验证input输入框(字母,数字,符号,中文)正则实现
    mac 安装swoole扩展
    git 配置本地SSH秘钥
    lnmp 一键安装
    lnmp php版本升级
    NATAPP内网穿透,本地进行微信开发,支付开发,对象存储回调信息
    微信公众号二维码
  • 原文地址:https://www.cnblogs.com/zywf/p/14934586.html
Copyright © 2011-2022 走看看