在spring boot项目中进行数据库模糊查询操作,传递参数:realName
在这之前也有过类似情况出现,在传递方法中加一个:@Param(value=“realName”)注解,正常就能解决这个问题。
/**【在 Service 中添加注解,模糊查询、获取所有用户信息】**/
@Override
public List<Tuser> ListUser(@Param(value = "realName") String realName) {
return userMapper.ListUser(realName);
}
/**【在 Interface 方法中也加上去获取所有用户信息】**/
public List<Tuser> ListUser(@Param(value = "realName")String realName);
试着在控制器中打印传递的数据,可以拿到数据,但结果就是依然报错!!!
然后在网上找解决方法,在数据库语句中判断,在if test=里面加:_parameter!= null
<!--原本我的查询语句-->
<select id="ListUser" resultMap="userResult">
select * from Tuser
<where>
<if test="realName!= null and realName != '' ">
AND realName like '%' + #{realName} + '%'
</if>
</where>
</select>
<!--修改后-->
<select id="ListUser" resultMap="userResult">
select * from Tuser
<where>
<if test="_parameter!= null">
AND realName like '%' + #{realName} + '%'
</if>
</where>
</select>
完美解决我的问题。
在找解决方案是找到了一遍讲解比较详细的博客,有兴趣的可以看一下:
源码分析 There is no getter for property named ‘*’ in 'class