Mybaits注解方式 There is no getter for property named 'name' in 'class java.lang.String'

时间:2022-02-02 14:28:50

接口层的代码:

@Select("select cid,rl.companyName `name`,(select IFNULL(companyLogo,'') from company cp where cp.cid = rl.cid) as companyLogo,merRealStatus "
+ "from RealNameAuditingFromJDJR rl where 1=1 "
+ "<if test='name != null and name != \"\" '>"
+ "and rl.companyName like '${name}' "
+ "</if>"
+ "order by createTime desc")
@Options(statementType=StatementType.CALLABLE)
List<Map<String, Object>> getAllCompanyList(String name);

Mybaits注解方式 There is no getter for property named 'name' in 'class java.lang.String'

解决办法:

加一个@Param("name")就好了:

@Select("select cid,rl.companyName `name`,(select IFNULL(companyLogo,'') from company cp where cp.cid = rl.cid) as companyLogo,merRealStatus "
+ "from RealNameAuditingFromJDJR rl where 1=1 "
+ "<if test='name != null and name != \"\" '>"
+ "and rl.companyName like '${name}' "
+ "</if>"
+ "order by createTime desc")
@Options(statementType=StatementType.CALLABLE)
List<Map<String, Object>> getAllCompanyList(@Param("name")String name);



关于参数是否参与过滤的写法:

1、if test中的参数名称不需要加${};

2、${}和#{}的区别

      #{}是占位符,比${}更安全

      如果是in查询,一定需要用${},注意构造参数的格式如单引号