u012503756
bulidfer
采纳率35.8%
2019-03-04 17:20

mybatis 修改关联表报错

5
已采纳

软件环境

spring springmvc mybatis

数据库:mysql

报错信息:
mybatis 修改关联表报错Parameter 'key_dm' not found. Available parameters are [0, member, param1, param2]
图片说明

代码提示:

//mybatis.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">
<mapper namespace="com.app.dao.mapper.MemberPermissionMapper">
    <resultMap type="MemberPermission" id="MemberPermission">
        <id column="id" property="id"/>
        <result column="member_id" property="member_id"/>
        <result column="ttys" property="ttys"/>
        <result column="key_dm" property="key_dm"/>
        <result column="lose_time" property="lose_time"/>
        <result column="note" property="note"/>
        <result column="update_time" property="update_time"/>
        <!-- 关联member表 -->
        <association property="member" javaType="com.app.bean.Member">
            <id column="member_id" property="id"/>
            <result column="phone" property="phone"/>
            <result column="name" property="name"/>
            <result column="password" property="password"/>
        </association>
    </resultMap>

    <update id="updateMemberLoginPermission" parameterType="MemberPermission">
        UPDATE dt_member_permission AS t1
        LEFT JOIN dt_member AS t2 ON t1.member_id=t2.id
        <set>
            <if test="key_dm!=null and key_dm !=''">t1.key_dm=#{_key_dm},
            </if>
        </set>
        WHERE t1.ttys=#{ttys}
        AND t2.phone=#{phone}
        AND t2.password=#{password}
    </update>

//service业务层实现类代码

   @Override
    public int updateMemberLoginPermission( @Param("ttys") String ttys, @Param("phone") String phone, @Param("newpwd") String newpwd, @Param("key_dm") String key_dm) {

       MemberPermission memberPermission= new MemberPermission();
        memberPermission.setTtys(ttys);
        memberPermission.setKey_dm(key_dm);

        Member member = new Member();
        member.setPhone(phone);
        member.setPassword(newpwd);
        return memberPermissionDao.updateMemberLoginPermission(memberPermission,member);
    }

//dao层代码

public interface MemberPermissionDao {


    public int updateMemberLoginPermission(MemberPermission memberPermission, @Param("member") Member member);//根据终端类型 用户手机号密码修改动态key 关联表
}

//mapper.java接口代码

package com.app.dao.mapper;

import com.app.bean.Member;
import com.app.bean.MemberPermission;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

public interface MemberPermissionMapper {

    public int updateMemberLoginPermission(MemberPermission memberPermission, @Param("member")Member member);//根据终端类型 用户手机号密码修改动态key 关联表
}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • qq_43242099 ThompJie 2年前

    你别用实体类传参,使用map。
    Map map = new HashMap();
    map.put("ttys",ttys);
    map.put("phone",phone);
    map.put("key_dm",key_dm);
    map.put("password",password);
    xml中的update语句修改成:

    UPDATE dt_member_permission AS t1
    LEFT JOIN dt_member AS t2 ON t1.member_id=t2.id

    t1.key_dm=#{key_dm}


    WHERE t1.ttys=#{ttys}
    AND t2.phone=#{phone}
    AND t2.password=#{password}

    肯定就行了!

    点赞 评论 复制链接分享
  • zhongsan123 才沐木 2年前

    t1.key_dm=#{_key_dm},这里有问题吧,参数应该是key_dm啊,怎么多了一个下划线?

    点赞 评论 复制链接分享

相关推荐