mybatis笔记
2015-12-24 10:28
323 查看
总配置文件sqlMapConfig.xml
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<typeAliases>
<typeAlias type="com.lrq.vo.User"
alias="User"/>
<typeAlias type="com.lrq.vo.Order"
alias="Order"/>
<typeAlias
type="com.lrq.vo.Customer" alias="Customer"/>
</typeAliases>
<environments
default="development">
<environment
id="development">
<transactionManager type="JDBC"
/>
<dataSource
type="POOLED">
<property name="driver"
value="com.mysql.jdbc.Driver" />
<property name="url"
value="jdbc:mysql://127.0.0.1:3306/mybatis" />
<property name="username"
value="root" />
<property name="password"
value="123456" />
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="sql/User.xml"
/>
<mapper resource="sql/Order.xml"
/>
<mapper
resource="sql/Customer.xml" />
</mappers>
</configuration>
sql语句映射文件:User.xml
<?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">
<!-- namespace不可以使用别名
-->
<mapper
namespace="com.lrq.vo.User">
<!--
使用sql块而不是*,实际开发中不建议使用*
-->
<sql id="userField">
uid,username,age,address
</sql>
<!-- <include refid="userField"
/>表示引用上面定义的sql块;
-->
<select id="selectUserById" parameterType="int"
resultType="User">
select
<include refid="userField" />
from user
where uid=#{uid}
</select>
<select id="selectUserByIdForMap"
parameterType="int"
resultType="map">
select
<include refid="userField" />
from user
where uid=#{uid}
</select>
<select id="selectAll"
resultType="User">
select
<include refid="userField" />
from
user
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<typeAliases>
<typeAlias type="com.lrq.vo.User"
alias="User"/>
<typeAlias type="com.lrq.vo.Order"
alias="Order"/>
<typeAlias
type="com.lrq.vo.Customer" alias="Customer"/>
</typeAliases>
<environments
default="development">
<environment
id="development">
<transactionManager type="JDBC"
/>
<dataSource
type="POOLED">
<property name="driver"
value="com.mysql.jdbc.Driver" />
<property name="url"
value="jdbc:mysql://127.0.0.1:3306/mybatis" />
<property name="username"
value="root" />
<property name="password"
value="123456" />
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="sql/User.xml"
/>
<mapper resource="sql/Order.xml"
/>
<mapper
resource="sql/Customer.xml" />
</mappers>
</configuration>
sql语句映射文件:User.xml
<?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">
<!-- namespace不可以使用别名
-->
<mapper
namespace="com.lrq.vo.User">
<!--
使用sql块而不是*,实际开发中不建议使用*
-->
<sql id="userField">
uid,username,age,address
</sql>
<!-- <include refid="userField"
/>表示引用上面定义的sql块;
-->
<select id="selectUserById" parameterType="int"
resultType="User">
select
<include refid="userField" />
from user
where uid=#{uid}
</select>
<select id="selectUserByIdForMap"
parameterType="int"
resultType="map">
select
<include refid="userField" />
from user
where uid=#{uid}
</select>
<select id="selectAll"
resultType="User">
select
<include refid="userField" />
from
user
相关文章推荐
- Spring定时器的使用
- 数据结构课程设计——学生成绩管理系统
- struts总结完整整理版
- struts2总结:草稿
- Spring的总结
- struts2中默认拦截器栈中的拦截器…
- 动态代理模式--自定义数据源的终极…
- Git reset 回退项目某个节点版本
- kali postgress connection
- Ajax—初识
- 装饰设计模式---自定义数据源
- 读《结网》
- 关于tomcat服务器getParameter对ge…
- dom4j和xpath解析带名称空间的xml…
- 【转载】Linux下的javaee开发环境…
- oracle数据库之sql查询语句笔记
- oracle数据库笔记之数据库基本管理
- 前端规范(html5,js)
- 关于不变模式和String,StringBuff…
- 关于String、StringBuffer、String…