There is no getter for property named 'states' in 'class com.xingguo.model.User'
或 _frch_item_0 not found,通常發生在 `
collection 指定錯誤關鍵方法:DefaultSqlSession.wrapCollection()
private Object wrapCollection(final Object object) {
if (object instanceof Collection) {
StrictMap<Object> map = new StrictMap<>();
map.put("collection", object); // 默認 key: "collection"
if (object instanceof List) {
map.put("list", object); // List 額外 key: "list"
}
return map;
} else if (object != null && object.getClass().isArray()) {
StrictMap<Object> map = new StrictMap<>();
map.put("array", object); // 數組 key: "array"
return map;
}
return object; // 單個對象直接返回
}
// Mapper 接口
List<User> selectByIds(@Param("ids") List<Long> ids);
// XML
<select id="selectByIds" resultType="User">
SELECT * FROM user
<where>
<foreach collection="ids" item="id" separator="," open="id IN (" close=")">
#{id}
</foreach>
</where>
</select>
public class QueryParam {
private List<Long> ids; // getter/setter
}
// Mapper
List<User> selectByParam(QueryParam param);
// XML - 必須指定 collection="ids"
<foreach collection="ids" item="id" ...> #{id} </foreach>
// 錯誤:無 @Param,參數名丟失
List<User> select(User user, List<Long> ids);
// 正確
List<User> select(@Param("user") User user, @Param("ids") List<Long> ids);
// XML 引用
<foreach collection="ids" ...>
<if test="user.name != null">...