zoukankan      html  css  js  c++  java
  • MyBatis探究-----为实体类Bean取别名,配置typeAliases

       1.单个实体类设置别名

    1.1 不使用alias

    <typeAliases>
            <!-- typeAlias:为某个java类型起别名 ; type:指定要起别名的类型全类名; 默认别名就是类名小写(大小写都可以) -->
            <typeAlias type="com.mybatis.entity.Employee" />
        </typeAliases>
    <?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="com.mybatis.dao.EmployeeMapper">
        <insert id="addEmployee" parameterType="Employee">
            insert into
            t_employee(empId,empName,empSex,empAge)
            values(#{empId},#{empName},#{empSex},#{empAge})
        </insert>
    </mapper>

    1.2 使用alias

    <typeAliases>
            <!-- alias:指定新的别名-->
            <typeAlias type="com.mybatis.entity.Employee" alias="emp" />
        </typeAliases>
    <?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="com.mybatis.dao.EmployeeMapper">
        <insert id="addEmployee" parameterType="emp">
            insert into
            t_employee(empId,empName,empSex,empAge)
            values(#{empId},#{empName},#{empSex},#{empAge})
        </insert>
    </mapper>

       2.多个实体类设置别名

    2.1 不使用注解@Alias

        <typeAliases>
            <!--package:为某个包下的所有类批量起别名 name:指定包名(为当前包以及下面所有的后代包的每一个类都起一个默认别名(类名小写),) -->
            <package name="com.mybatis.entity" />
        </typeAliases>
    <?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="com.mybatis.dao.EmployeeMapper">
        <insert id="addEmployee" parameterType="Employee">
            insert into
            t_employee(empId,empName,empSex,empAge)
            values(#{empId},#{empName},#{empSex},#{empAge})
        </insert>
    </mapper>

    2.2 使用注解@Alias

    <typeAliases>
            <!--package:为某个包下的所有类批量起别名 name:指定包名(为当前包以及下面所有的后代包的每一个类都起一个默认别名(类名小写),) 
                 批量起别名的情况下,使用@Alias注解为某个类型指定新的别名-->
            <package name="com.mybatis.entity" />
        </typeAliases>
    <?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="com.mybatis.dao.EmployeeMapper">
        <insert id="addEmployee" parameterType="emp">
            insert into
            t_employee(empId,empName,empSex,empAge)
            values(#{empId},#{empName},#{empSex},#{empAge})
        </insert>
    </mapper>
    package com.mybatis.entity;
    
    import org.apache.ibatis.type.Alias;
    
    /**
     * 雇员类
     * 
     * @author yyx 2019年3月23日
     */
    @Alias("emp")
    public class Employee {
        /**
         *雇员ID 
         */
        private String empId;
        /**
         * 雇员姓名
         */
        private String empName;
        /**
         * 雇员性别: 0 女,1 男
         */
        private Integer empSex;
        /**
         * 雇员年龄
         */
        private Integer empAge;
    
        public Employee() {
            super();
        }
    
        public Employee(String empId, String empName, Integer empSex, Integer empAge) {
            super();
            this.empId = empId;
            this.empName = empName;
            this.empSex = empSex;
            this.empAge = empAge;
        }
    
        public String getEmpId() {
            return empId;
        }
    
        public void setEmpId(String empId) {
            this.empId = empId;
        }
    
        public String getEmpName() {
            return empName;
        }
    
        public void setEmpName(String empName) {
            this.empName = empName;
        }
    
        public Integer getEmpSex() {
            return empSex;
        }
    
        public void setEmpSex(Integer empSex) {
            this.empSex = empSex;
        }
    
        public Integer getEmpAge() {
            return empAge;
        }
    
        public void setEmpAge(Integer empAge) {
            this.empAge = empAge;
        }
    
    }
  • 相关阅读:
    HDU 5171
    HDU 3709
    HDU 3652
    HDU 3555
    【10】梯度消失和爆炸;梯度检验
    【9】归一化输入与标准化
    【8】正则化
    【7】偏差、方差;过拟合、欠拟合
    【6】深层神经网络的前向与反向传播
    【5】激活函数的选择与权值w的初始化
  • 原文地址:https://www.cnblogs.com/fengfuwanliu/p/10589614.html
Copyright © 2011-2022 走看看