在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. iOS 使用Method Swizzling隐藏Status Bar

    在iOS 6中,隐藏Status Bar很的简单. // iOS 6及曾经,隐藏状态栏 [[UIApplication sharedApplication] setStatusBarHidden:YE ...

  2. VisualStudio中的代码段

    VS很强大,在这里就不过多说了,在平时码代码时应用代码段会提高我们的编写速度. 举个例子: 比如输入Console.WriteLine (); 传统方法就是一个字母一个字母的输入进去. 如果大家掌握了 ...

  3. notepad++ 必装插件

    nppftp ;FTP客户端,你懂的: explorer:设置常用文件链接:打开当前文件路径:

  4. hive j简单邮件过滤

    select min(call_log), a.mail_subject from (select mail_to,mail_subject from dw_user_deviler_201408 w ...

  5. mysql 的not null 与 null的区别(转,恍然大悟)

    相信很多用了mysql很久的人,对这两个字段属性的概念还不是很清楚,一般会有以下疑问: 1.我字段类型是not null,为什么我可以插入空值 2.为毛not null的效率比null高 3.判断字段 ...

  6. Toast的替代者Snackbar

    在Android design support library中,SnackBar的使用: Part 2 – Welcome Snackbar, Goodbye Toast! BY PARESH MA ...

  7. Anndroid 开发架构读书笔记

    市面上大部分应用不外乎就是颠过来倒过去地做以下这些事情: --------------- --------------- --------------- --------------- | | | | ...

  8. ThinkPHP第二十三天(Category表结构、PHPExcel导入数据函数)

    1.category分类表表结构id,name,pid,sort,结合category.class.php类使用. 2.PHPExcel导入数据函数示例 function excel_to_mysql ...

  9. Lavarel(-) windows 部署

    使用 Lavarel 开发完全可以抛开wamp,phpstudy等一键环境.因为lavarel 内置的artisan 整合了php5.4 内置的webserver ,甚至可以使用artisan 命令指 ...

  10. 经常使用的时间同步server地址

    转载出处http://www.minunix.com/2013/03/ntpserver/ 感谢原作者,一切的权利都属于原作者,假设有所不适,我会马上删除 中国大概能用的NTP时间server地址 s ...