zoukankan      html  css  js  c++  java
  • mybatis优化配置

    在src下建立db.properties

    driver=com.mysql.jdbc.Driver
    url=jdbc:mysql://localhost:3306/mybatis
    name=root
    password=123456

    在conf.xml中导入,在configuration中加入

    <properties resource="db.properties">
        </properties>

    然后引用

    <dataSource type="POOLED">
                    <property name="driver" value="${driver}" />
                    <property name="url" value="${url}" />
                    <property name="username" value="${name}" />
                    <property name="password" value="${password}" />
                </dataSource>

    优化为,给有些全类名太长的类取别名

    在conf.xml中,configuration中加入

    <typeAliases>
            <typeAlias type="test.User" alias="_User"/>
    </typeAliases>

    同理userMapper.xml中修改

    <select id="getUser" parameterType="int" resultType="_User">
            select * from users where id=#{id}
        </select>

    此外也可以这样配置

    <typeAliases>
            <package name="test"/>
        </typeAliases>

    这时直接使用类名就可以

    <select id="getUser" parameterType="int" resultType="User">
            select * from users where id=#{id}
        </select>
  • 相关阅读:
    [SUCTF 2019]Pythonginx
    [极客大挑战 2019]BuyFlag
    [GXYCTF2019]Ping Ping Ping
    git 常用命令记录
    webpack4.X + react-router 路由跳转
    webpack4.X + react搭建
    windows 下 node 安装 react
    valueOf()、toString()
    isFinite()
    Javascript 闭包
  • 原文地址:https://www.cnblogs.com/tuifeideyouran/p/4346362.html
Copyright © 2011-2022 走看看