MyBatis与Hibernate更改schema的方…

Hibernate需要在xml文件里面注释~~
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <!--
        一个class标签对应一个实体类
        name属性指定实体类名称
        table属性指定关联的数据库表
       schema属性指定了具体table所在的数据库(schema)
        所属schema:student_manager
        所属table:STUDENT_TBL
    -->
    <class name="table.student.StudentEntity" table="student_tbl" schema="student_manager">
       <!-- 主键 -->
        <id name="studentID" column="STUDENT_ID">
            <generator class="native"></generator><!-- 主键的生成策略 -->
        </id>
        <!--
            其他属性
            name对应实体类的属性 
            column对应关系型数据库表的列
        -->
        <property name="studentName" column="STUDENT_NAME"/>
        <property name="studentSex" column="STUDENT_SEX"/>
        <property name="studentBirthday" column="STUDENT_BIRTHDAY"/>

    </class>
</hibernate-mapping>



Mybatis因为本来就是SQL语句,所以直接在SQL里面加就可以啦~~
<?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="table.student.Student2Mapper">
    
<resultMap type="StudentEntity2" id="studentResultMap">
<id property="id" column="stu_id"/>
<result property="name" column="stu_name"/>
<result property="age" column="stu_age"/>
</resultMap>
        <!--
            当表格不在默认的数据库(schema)里面的时候
            直接在from后面添加指定的数据库(schema),就像操作普通SQL一样
            这里使用newschema.stu_tab来代替stu_tab即可
        -->
<select id="getStudentAll"  resultType="StudentEntity2" resultMap="studentResultMap">
<![CDATA[
SELECT * fromnewschema.stu_tab
]]> 
</select>
</mapper>






版权声明:本文为u010770993原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。