java的mapper接收Mysql的select group_concat
时间: 2023-05-14 11:04:11 浏览: 530
函数返回的结果时,如何将结果映射到Java对象中?
可以使用@Results注解和@Result注解来映射结果到Java对象中。例如:
@Results({
@Result(property = "id", column = "id"),
@Result(property = "name", column = "name"),
@Result(property = "age", column = "age"),
@Result(property = "hobbies", column = "hobbies", javaType = List.class, typeHandler = StringListTypeHandler.class)
})
@Select("SELECT id, name, age, GROUP_CONCAT(hobby) as hobbies FROM user GROUP BY id")
List<User> getUsers();
其中,@Results注解用于定义映射规则,@Result注解用于定义每个属性的映射规则。在这个例子中,我们使用了StringListTypeHandler来将字符串转换成List类型。
阅读全文