mybatis中delete语句里xml参数有错误Parameter 'id' not found

报错信息如下所示:
nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘id’ not found.
Available array

**

解决办法:让item的值与#{}中的值保持一致。

**
mapper.xml中
原先为item=ids #{id}
修改代码处为item=id #{id}

<delete id="deleteMDatabaseByIds" parameterType="String">
        delete from m_database where id in
        <foreach collection="array" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
</delete>

mapper.java中

/**
     * 批量删除数据库管理
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    public int deleteMDatabaseByIds(String[] ids);

serviceImp.java中

/**
     * 删除数据库管理对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteMDatabaseByIds(String ids)
    {
        return mDatabaseMapper.deleteMDatabaseByIds(Convert.toStrArray(ids));
    }

Controller.java中

/**
     * 删除数据库管理
     */
    @RequiresPermissions("datamodel:database:remove")
    @Log(title = "数据库管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        try {
            this.printMsg("delete ids="+ids);
            return toAjax(mDatabaseService.deleteMDatabaseByIds(ids));
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
    }
    protected void print(Map params){
        System.out.println("------------------------------------");
        String key="";
        Set keys=params.keySet();
        Iterator iter=keys.iterator();
        while(iter.hasNext())
        {
            key=iter.next().toString();
            System.out.println(key+"="+params.get(key));
        }
        System.out.println("------------------------------------");
    }
    protected void printMsg(String msg){
        System.out.println(msg);
    }

—the—end—

已标记关键词 清除标记
如下图所示,mybatis删除数据异常: ![图片说明](https://img-ask.csdn.net/upload/201609/20/1474378279_172915.png) log4j调试的信息表示SQL语句应该是对的,然而数据库并没有删除信息。 相关的配置文件及代码如下: 配置文件: ``` <?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="Message"> <!-- 命名空间不能省略,类似于package --> <resultMap type="model.Message" id="MessageResult"> <id column="ID" jdbcType="VARCHAR" property="id"/> <!-- id是查找结果集的主键 --> <result column="COMMAND" jdbcType="VARCHAR" property="command"/> <result column="DESCRIPTION" jdbcType="VARCHAR" property="description"/> <result column="CONTENT" jdbcType="VARCHAR" property="content"/> </resultMap> <select id="Message.queryAll" resultMap="MessageResult"> SELECT ID,COMMAND,DESCRIPTION,CONTENT FROM message WHERE 1=1 <if test="command != null and !"".equals(command.trim())">and COMMAND LIKE '%' #{command} '%'</if> <if test="description != null and !"".equals(description.trim())">and DESCRIPTION LIKE '%' #{description} '%'</if> </select> <delete id="deleteOne" parameterType="java.lang.Integer"> DELETE FROM message WHERE ID=#{_parameter} </delete> </mapper> ``` DAO层方法: ``` public void deleteOne(int id){ DBAccess dbAccess = new DBAccess(); SqlSession sqlSession = null; try{ sqlSession = dbAccess.getSqlSession();//实例化并打开数据库会话 sqlSession.delete("Message.deleteOne",id);//message.xml配置文件对应ID号的SQL语句 }catch(IOException e){ e.printStackTrace(); }finally{ if(sqlSession!=null){ sqlSession.close(); } } } ``` service层方法 ``` package service; import dao.MessageDAO; public class MaintainService { public void deleteOne(String id){ if(id != null && !"".equals(id.trim())){ MessageDAO messageDao = new MessageDAO(); messageDao.deleteOne(Integer.valueOf(id)); } } } ``` Servlet ``` public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); //获取页面的值 String id = request.getParameter("id"); MaintainService maintainService = new MaintainService(); maintainService.deleteOne(id); //dao方法和跳转页面 try { request.getRequestDispatcher("/servlet/ShowServlet").forward(request,response); } catch (Exception e) { e.printStackTrace(); } } ``` 求各路大神解答,谢谢!
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页