mybatis一简单one2one关系xml配置
user类
<?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.mapper.UserMapper">
<resultMap id="userMap" type="User"> //user对象映射
<id property="userId" column="user_id" javaType="int"></id>//user的Id
<result property="userName" column="user_name" javaType="string"/> //user的属性
<result property="userMoney" column="user_money" javaType="string"/>
</resultMap>
<resultMap id="userAndInfoMap" type="User">
<id property="userId" column="user_id" javaType="int"></id>
<result property="userName" column="user_name" javaType="string"/>
<result property="userMoney" column="user_money" javaType="string"/>
<!-- <association property="info" resultMap="com.mapper.UserInfoMapper.infoMap" javaType="UserInfo"/> --> // user对象包含的对象的配置方式一(user的sql里面写join连接info表)
<association property="info" column="user_id" javaType="UserInfo" //user对象包含的对象的配置方式一(各查各的互补影响)
select ="com.mapper.UserInfoMapper.findUserInfoByUserId">
</association>
</resultMap>
<insert id="addUser" parameterType="User">
insert into user values(null,#{user.userName},#{user.userMoney})
</insert>
<delete id="deleteUserByuserId">
delete from user where user_id = #{id}
</delete>
<update id="updateUser" parameterType="User"> //parameterType="User" 表示传递的参数的类型 //id="updateUser"使用的方法名
update user set user_name=#{user.userName},user_money=#{user.userMoney
} where user_id=#{user.userId}
</update>
<select id="selectUserByuserId" resultMap="userAndInfoMap"> // resultMap="userAndInfoMap"返回值的类型,如果返回值是List<UserInfo>也用这个类型
select * from user u left join userInfo i on u.user_id = i.user_id where u.user_id = #{id}
</select>
<select id="findAllUser" resultMap="userMap">
select * from user
</select>
<select id="findUserCount" resultType="int">
select count(*) from user where user_id !=2
</select>
<select id="findUserByuserNameLike" resultMap="userMap">
select * from user where user_name like '%${userName}%'
</select>
</mapper>
userInfo类
<?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.mapper.UserInfoMapper">
<resultMap id="infoMap" type="UserInfo">//对象映射
<id property="infoId" column="info_id" javaType="int"></id>
<result property="infoName" column="info_name" javaType="string"/>
</resultMap>
<select id="findUserInfoByid" resultMap="infoMap">
select * from userInfo where info_id =#{id}
</select>
<select id="findUserInfoByUserId" resultMap="infoMap">
select * from userInfo where user_id =#{id}
</select>
</mapper>
mybatis一简单one2one关系xml配置的更多相关文章
- MyBatis入门程序(基于XML配置)
创建一个简单的MyBatis入门程序,实现对学生信息的增删改查功能(基于XML配置) 一.新建一个Java工程,导入MyBatis核心jar包.日志相关的jar包以及连接Oracle数据库所需驱动包, ...
- Spring Boot 框架下使用MyBatis访问数据库之基于XML配置的方式
MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.MyBatis 可以使用简单的 XML ...
- android动画(1)各种动画属性表,简单代码,xml配置
1.动画的属性表 1.1 常用属性 它们可以通过代码setXXX,getXXX,也可在xml中配置. 属性[类型] 功能 备注 Duration[long] 属性为动画持续时间 时间以毫秒为单位 fi ...
- MyBatis学习笔记3--使用XML配置SQL映射器
<resultMap type="Student" id="StudentResult"> <id property="id&quo ...
- Spring和mybatis整合后的mybais-config.xml配置
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE configuration PUBLIC & ...
- struts2 mybatis spring hibernate 框架 pom.xml配置 下载地址
访问以下地址:搜索需要框架的配置 选择需要的版本 http://mvnrepository.com
- 单独使用MyBatis的简单示例
单独使用MyBatis的简单示例:mybaties-config.xml:MyBatis配置文件 <?xml version="1.0" encoding="UTF ...
- Spring注解配置和xml配置优缺点比较
Spring注解配置和xml配置优缺点比较 编辑 在昨天发布的文章<spring boot基于注解方式配置datasource>一文中凯哥简单的对xml配置和注解配置进行了比较.然后朋 ...
- springboot中xml配置之@ImportResource
springboot中进行相关的配置往往有java配置和xml配置两种方式. 使用java的方式配置只需要使用@configuration注解即可,而使用xml的方式配置的话需要使用@ImportRe ...
随机推荐
- C++ 中的sort()排序函数用法
sort(first_pointer,first_pointer+n,cmp) 该函数可以给数组,或者链表list.向量排序. 实现原理:sort并不是简单的快速排序,它对普通的快速排序进行了优化,此 ...
- ltp-ddt emmc_dd_rw
emmc_dd_rw EMMC_M_FUNC_DD_RW_500M source "common.sh"; install_modules.sh "emmc"; ...
- Python包管理工具——pip
目录 Python pip pip相关命令 解决pip相关问题 Python pip Python最让人的喜欢的就是它有丰富的类库和各种第三方的包,而对于这些包的下载.删除等管理操作,就要用到包管理工 ...
- 题解 Luogu P3623 [APIO2008]免费道路
[APIO2008]免费道路 题目描述 新亚(New Asia)王国有 N 个村庄,由 M 条道路连接.其中一些道路是鹅卵石路,而其它道路是水泥路.保持道路免费运行需要一大笔费用,并且看上去 王国不可 ...
- Tomcat在Window控制台下启动时乱码的两种解决办法
在命令提示符中启动Tomcat时,日志窗口出现乱码: 乱码的原因肯定是日志解码错误引起的,因此就有一系列问题: 1.这个窗口的文本编码是什么? 窗口的文本编码查看:右击窗口>选项 可以看到窗口的 ...
- linux准备工具VMware以及ubuntu
链接:https://pan.baidu.com/s/1j7DZCmzOcC2rPAciHtZgkA 密码:et5s
- 正则表达式,js里的正则应用
我爱撸码,撸码使我感到快乐!大家好,我是Counter.好吧已经到凌晨了,其实还是蛮困的,体力不支了,想了想还是把今天任务结束掉吧,为期5天,又重新把JavaScript以及jQuery给大致过了一遍 ...
- Star in Parentheses
问题 A: Star in Parentheses 时间限制: 1 Sec 内存限制: 128 MB 题目描述 You are given a string S, which is balanced ...
- win10 右键添加“在此打开powershell”
计算机\HKEY_CLASSES_ROOT\Directory\Background\shell\ 上图中的字符串,直接去下图中的位置复制过来就好
- credential for git
1, 编辑~/.gitconfig文件怎加如下配置 [credential] helper = store 2,执行 git pull.输入username, password. 3.检查~/.git ...