MyBatis——3
MyBatis错误:Parameter 'xxx' not found.Available parameters are [1,0,param1,param2]
原本用的是名称匹配发现不了,换成0,1,2这样的方式序列匹配;如果还是解决不了的话可能是参数类型不一致或者其中参数为NULL。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="src.bonc.lbs.wt.dao.business.UserDao" >
<!-- Result Map-->
<resultMap type="src.bonc.lbs.wt.entity.business.User" >
<result column="id" property="id"/>
<result column="username" property="username"/>
<result column="password" property="password"/>
<result column="gmt_create" property="gmt_create"/>
<result column="gmt_modify" property="gmt_modify"/>
</resultMap>
<!-- Result Map -->
<resultMap type="src.bonc.lbs.wt.entity.business.User" >
<id column="id" property="id"/>
<result column="username" property="username"/>
<result column="password" property="password"/>
<collection property="roles" javaType="java.util.List" ofType="src.bonc.lbs.wt.entity.business.Role">
<id column="r_id" property="id" jdbcType="VARCHAR" />
<result column="r_name" property="name" jdbcType="VARCHAR" />
</collection>
</resultMap>
<!-- user table all fields -->
<sql >
id,username,password,gmt_create,gmt_modify
</sql>
<!-- 查询条件 -->
<sql >
where 1=1
<trim suffixOverrides="," >
<if test="id != null and id != ''" >
and id = #{id}
</if>
<if test="username != null and username != ''" >
and username = #{username}
</if>
<if test="password != null and password != ''" >
and password = #{password}
</if>
</trim>
</sql>
<!-- 插入记录 -->
<insert parameterType="Object" >
insert into user(id,username,password)
values(#{id},#{username},#{password})
</insert>
<!-- 根据id,修改记录-->
<update parameterType="Object" >
update user set username=#{username},password=#{password} where id=#{id}
</update>
<!-- 修改记录,只修改只不为空的字段 -->
<update parameterType="Object" >
update user set
<trim suffixOverrides="," >
<if test="username != null ">
username=#{username},
</if>
<if test="password != null ">
password=#{password},
</if>
<if test="gmt_create != null ">
gmt_create=#{gmt_create},
</if>
<if test="gmt_modify != null ">
gmt_modify=#{gmt_modify},
</if>
</trim> where id=#{id}
</update>
<!-- 删除记录 -->
<delete parameterType="Object">
delete from user where id = #{id}
</delete>
<!-- 根据id查询 用户 -->
<select resultMap="BaseResultMap" parameterType="Object">
select <include ref />
from user where id = #{id}
</select>
<!-- 用户 列表总数-->
<select resultType="java.lang.Integer" parameterType="Object">
select count(1) from user
<include ref/>
</select>
<!-- 查询用户列表 -->
<select resultMap="BaseResultMap" parameterType="Object">
select
<include ref/>
from user
<include ref/>
<if test="pager.orderCondition != null and pager.orderCondition != ''" >
${pager.orderCondition}
</if>
<if test="pager.mysqlQueryCondition != null and pager.mysqlQueryCondition != ''" >
${pager.mysqlQueryCondition}
</if>
</select>
<select resultMap="queryForListMap">
SELECT u.id,u.username,u.password,r.id r_id,r.name r_name FROM user u LEFT JOIN role r ON u.id = r.userid
</select>
<select resultMap="queryForListMap">
SELECT u.id,u.username,u.password,r.id r_id,r.name r_name FROM user u LEFT JOIN role r ON u.id = r.userid
WHERE u.gmt_create > #{0} AND u.gmt_create < #{1}
</select>
</mapper>
package src.bonc.lbs.wt.dao.business;
import java.util.List;
import src.bonc.com.base.dao.BaseDao;
import src.bonc.lbs.wt.entity.business.User;
/**
*
* <br>
* <b>功能:</b>UserDao<br>
* <b>作者:</b>bonc<br>
* <b>日期:</b> Feb 2, 2017 <br>
* <b>版权所有:<b>版权所有(C) 2017,bonc.com.cn<br>
*/
public interface UserDao<T> extends BaseDao<T> {
List<User> queryForList();
List<User> queryForListByCT(String startTime, String endTime);
}
最后更新:2017-07-12 22:05:00