Mybatis select 多输入语句映射
Mybatis select statement mapping with multiple inputs
项目spring-mybatis.I使用了@Param注解,但是传值无法传递给它
使用以下界面
findPage(@Param("start") Integer start, @Param("pageSize") Integer pageSize, @Param("delFlag") Integer delFlag);
工具
findPage(@Param("start") Integer start, @Param("pageSize") Integer pageSize,@Param("delFlag")Integer delFlag) {
return this.getSqlSession().selectList(getNs() + ".findPage");
}
映射器
<select id="findPage" parameterType="map" resultMap="sysUserRM">
SELECT
*
FROM
sys_user
WHERE
del_falg = #{delFlag,jdbcType=INTEGER}
LIMIT #{start,jdbcType=INTEGER},#{pageSize,jdbcType=INTEGER}
错误
### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE
del_falg = null
LIMIT null,null' at line 6
为什么收不到输入?
为了让你的参数名称传递给 mybatis 执行器,你不能自己编写映射器接口的实现,而是让 mybatis 使用以下方法生成代理:
YourMapper yourMapper = this.getSqlSession().getMapper(YourMapper.class);
YourPage yourPage = yourMapper.findPage(....);
项目spring-mybatis.I使用了@Param注解,但是传值无法传递给它
使用以下界面
findPage(@Param("start") Integer start, @Param("pageSize") Integer pageSize, @Param("delFlag") Integer delFlag);
工具
findPage(@Param("start") Integer start, @Param("pageSize") Integer pageSize,@Param("delFlag")Integer delFlag) {
return this.getSqlSession().selectList(getNs() + ".findPage");
}
映射器
<select id="findPage" parameterType="map" resultMap="sysUserRM">
SELECT
*
FROM
sys_user
WHERE
del_falg = #{delFlag,jdbcType=INTEGER}
LIMIT #{start,jdbcType=INTEGER},#{pageSize,jdbcType=INTEGER}
错误
### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE
del_falg = null
LIMIT null,null' at line 6
为什么收不到输入?
为了让你的参数名称传递给 mybatis 执行器,你不能自己编写映射器接口的实现,而是让 mybatis 使用以下方法生成代理:
YourMapper yourMapper = this.getSqlSession().getMapper(YourMapper.class);
YourPage yourPage = yourMapper.findPage(....);