在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>

mybatis优化配置的更多相关文章

  1. SpringMVC+Mybatis+MySQL配置Redis缓存

    SpringMVC+Mybatis+MySQL配置Redis缓存 1.准备环境: SpringMVC:spring-framework-4.3.5.RELEASE-dist Mybatis:3.4.2 ...

  2. 05_ssm基础(二)之mybatis优化

    06.mybatis优化之Mybatis工具类提取 优化原则(见官方文档): mybatis工具类存放位置: mybatis工具类代码: package com.day01.ssm.mybatisDe ...

  3. MyBatis项目配置案例详解与Web下的增删改查实现[附项目源码]

    MyBatis项目案例 项目图示: 项目源码地址:https://github.com/JluTiger/mybatispro 1.项目功能 项目案例:后台管理系统用户数据维护平台 所有用户数据查询 ...

  4. Mybatis XML配置

    Mybatis常用带有禁用缓存的XML配置 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE ...

  5. MyBatis Cache配置

    @(MyBatis)[Cache] MyBatis Cache配置 MyBatis提供了一级缓存和二级缓存 配置 全局配置 配置 说明 默认值 可选值 cacheEnabled 全局缓存的开关 tru ...

  6. nginx + SSL优化配置

    nginx + SSL优化配置: #http段添加如下配置项: http { ssl_prefer_server_ciphers on; #设置协商加密算法时,优先使用我们服务端的加密套件,而不是客户 ...

  7. Linux下jvm、tomcat、mysql、log4j优化配置笔记

    小菜一直对操作系统心存畏惧,以前也很少接触,这次创业购买了Linux云主机,由于木有人帮忙,只能自己动手优化服务器了.... 小菜的云主机配置大致为:centeos6(32位),4核心cpu,4G内存 ...

  8. spring和mybatis整合配置

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  9. SSM ( Spring 、 SpringMVC 和 Mybatis )配置详解

    使用 SSM ( Spring . SpringMVC 和 Mybatis )已经有三个多月了,项目在技术上已经没有什么难点了,基于现有的技术就可以实现想要的功能,当然肯定有很多可以改进的地方.之前没 ...

随机推荐

  1. 227. Basic Calculator

    1. 问题描述 Implement a basic calculator to evaluate a simple expression string. The expression string c ...

  2. GridView合并多行列值

    )                    {                        gvr.Cells[cellNum].RowSpan = rowSpanNum;               ...

  3. java 对象数组定义

    下面代码实现了定义一个数组对象 public class Student { private String username; private int num; public Student(Stri ...

  4. telnet测试端口号

    telnet Ip 端口号 如:telnet localhost 1433 详见此链接(转) http://www.3lian.com/edu/2012/11-08/43232.html

  5. JavaScript中的构造函数

    目录: constructor & prototype 为构造函数添加属性和方法的多种不同方法 组合使用this和prototype关键字创建构造函数(常用方法) 用对象直接量作为构造函数的参 ...

  6. mina学习资料整合

    最好的资料当然是官方文档:https://mina.apache.org/mina-project/userguide/user-guide-toc.html 官方文档,配合源码中的example例子 ...

  7. js命名空间的使用

    js命名空间的使用: test.html 代码如下: <!DOCTYPE HTML><html lang="en-US"><head>    & ...

  8. windows下搭建python+selenium环境

    1.安装python https://www.python.org/ 2.安装setuptools(python的基础包工具) 下载地址:https://pypi.python.org/pypi/se ...

  9. Mysql笔记之 -- 开启Mysql慢查询

    Mysql慢查询日志_1--如何开启慢查询日志 Windows下开启MySQL慢查询 MySQL在Windows系统中的配置文件一般是是my.ini找到[mysqld]下面加上 log-slow-qu ...

  10. Linux系统学习笔记之 1 一个简单的shell程序

    不看笔记,长时间不用自己都忘了,还是得经常看看笔记啊. 一个简单的shell程序 shell结构 1.#!指定执行脚本的shell 2.#注释行 3.命令和控制结构 创建shell程序的步骤 第一步: ...