mybatis中当一张表关联另一张表时需要注入另一张表的id
来源:互联网 发布:色系shipin软件下载 编辑:程序博客网 时间:2024/06/04 20:09
1.一个实体类名字叫做WithDraw
1)新建实体类:
public class WithDraw extends BaseModel{
/**
* 取款完成时间
*/
private Date finishtime;
/**
* 取款用户
*/
private User user;
@JsonSerialize(using = JasonDateFieldFormatter.class)
@JsonIgnore(value = false)
public Date getFinishtime()
{
return finishtime;
}
public void setFinishtime(Date finishtime)
{
this.finishtime = finishtime;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
@Override
public String toString() {
return "WithDraw [ finishtime=" + finishtime + ", user=" + user"]";
}
}
2.创建接口:
public interface WithDrawalsMapper {
/**
* 根据传递过来的 条件查找
* @param params
* @return
*/
public WithDraw findByWithDraw(Map<String,Object> params);
}
创建xml文件:WithDrawalsMapper.xml
1)resultMap是MyBatis中最重要最强大的元素。resultMap封装查询的结果集,type可以是Bean、Object、Primitive type。
2)parameterType用来指定传入参数的类型,比如Bean或Map\List。
文件内容:
<?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.p2p.core.mapper.withdrawals.WithDrawalsMapper"><resultMap id="withdrawals" type="com.p2p.core.model.funds.WithDraw" >//构建<span style="font-family: Arial, Helvetica, sans-serif;">WithDraw实体类</span><result property="id" column="id"/>//字段<result property="finishtime" column="finishtime"/><association property="user" resultMap="user" />//注入User实体类</resultMap><resultMap id="user" type="com.p2p.core.model.user.User" ><result property="user_name" column="user_name"/><result property="useable_funds" column="useable_funds"/><result property="frozen_funds" column="frozen_funds"/><result property="realName" column="realName"/><result property="mobile" column="mobile"/><result property="idCart" column="idCart"/></resultMap><select id="searchWithDraw" resultMap="withdrawals" parameterType="java.util.Map">select t1.*,user.*from t_withdraw t1 left join t_user user on t1.user_id = user.id where t1.status>0 ${whereClause}order by${sortBy} ${order}limit#{rowNum},#{rowCount}</select><select id="count" resultType="java.lang.Integer">select count(*) from t_withdraw t1 left join t_user user on t1.user_id = user.id where t1.status>0</select><select id="findByIdWithDraw" resultMap="withdrawals" parameterType="Integer">select t1.*,user.*from t_withdraw t1 left join t_user user on t1.user_id = user.id where t1.status>0 and t1.id=#{id} </select><update id="updataWithDraw">update t_withdraw <set><if test="status != null">status =#{status},</if><if test="agreetime != null">agreetime =#{agreetime},</if><if test="approvaluser != null">approvaluser =#{approvaluser},</if></set>where id=#{id}</update></mapper>
- mybatis中当一张表关联另一张表时需要注入另一张表的id
- oracle一张表的id关联另一张表中的字段
- 两张表关联,根据一张表更新另一张表
- mysql一张表id重新录入,另一张表的id也跟着改变
- MySQL中update一张表到另一张表
- 一张表替换另一张表
- mysql 一张表update另一张表
- 一张表的某列值去更新另一张表的某列值。
- 由一张表的内容UPDATE到另一张表
- 复制mysql数据库的一张表到另一张表
- oracle 把一张表的数据放入另一张表
- mysql 一张表的数据存入另一张表
- 根据一张表去更新另一张表的数据
- SQL使用一张表的数据更新另一张表
- 查询一张表的数据去更新另一张表
- mysql插入一张表里的数据到另一张表
- MySQL数据库中,将一张表的数据插入到另一张表的各种情况
- 如何用一条语句把一张表的数据插入到另一张数据库表中
- 半年工作总结
- hdu1052
- C/C++ 结构体做函数参数的小成程序
- Tomcat控制台和输出日志文件中文乱码
- ARM 的指令集
- mybatis中当一张表关联另一张表时需要注入另一张表的id
- android 学习笔记 Pull 解析XML 格式数据。
- Hibernate 缓存机制
- IIS日志-网站运维的好帮手
- iOS pch文件配置
- CSS绘制三角形
- 【内存泄露/C++】基于重载new运算符的内存泄露检测工具
- Lucene学习笔记
- 更改angular $http post 默认json