在MyBatis的ResultMap中映射List<String>通常需要使用<collection>标签。<collection>标签用于处理Java对象中的集合属性,当集合中的元素是简单类型(如String)时,可以通过<constructor>标签来指定如何将数据库列的值注入到集合中。 3. 提供一个简单的MyBatis ResultMap示例,用于映射List<Stri...
<resultMap id="dictMap" type="com.wf.indexmetrics.IndexMetricsDictionary"> <result column="indexId" property="indexId"/> <collection property="cnNames" javaType="list" ofType="java.lang.String"> <!--虽然配置多个字段, 但是只会返回第一个, 但是聚合的时候会加入其他字段作为key--> <result ...
></result></association></resultMap>六、collection标签常用参数详解例子演示- 实体类演示@Data//班级类publicclassClass{private String id;private String name;private List<Student> students;//---重点在这里,一个班级对应多个学生}@DatapublicclassStudent{privateint id;private String name;privateint age;}-...
parameterType 主要指定参数类型,可以是int, short, long, string等类型,也可以是复杂类型(如对象) --> parameterType="int" <!-- 3. resultType (resultType 与 resultMap 二选一配置) resultType用以指定返回类型,指定的类型可以是基本类型,可以是java容器,也可以是javabean --> resultType="hashmap" <!-- 4...
private String teamName;//小组名字 private Double teamGrade;//小组成绩 private List<String> userNames; private Integer teamId; }) dao层 dao层返回的是上面那个对象的集合 List<TeamRanking> selectTeamRanking(); mybatis的mapper 在Mapper中,使用了ResultMap的collection标签,并且: ...
@Data public class User { private Long userId; private String phone; private String username; private List<String> roles; } 2.resultMap <resultMap id="BaseResultMap" type="com.moon.model.User" > <id column="user_id" property="userId" jdbcType="BIGINT" /> <result column="phone" propert...
为此我们需要在 Employee 类中增加一个 int类型的 employeeType属性来区分正式工和临时工,其中 1代表正式工,而 0代表临时工。然后我们来编写查询 DepartmentAndTypeEmployees 的 resultMap : 切记一定是先声明 DepartmentAndTypeEmployees的两个 List ,然后在 collection 标签内部使用 discriminator 标签。
private String cname;private List<String> sname;// getter、setter } MyBatis中的xml <resultMap id="StudentMap" type="ClassRoom"> <result column="cname" property="cname" /> <collection column="sname" ofType="string"> <result column="sname" javaType="string" /> </collection> </resultMap>...
@Data //出版社 public class Publisher { private String id; private String name; private String phone; private String address; } - xml演示 代码语言:javascript 代码运行次数:0 运行 AI代码解释 <resultMap id="rMap_book" type="com.wang.test.demo.entity.Book"> <!-- 主键property为实体类属性 col...
collection – 一个复杂类型的集合 2.5 代码演示 实体类,配置文件同上 (1)mapper接口 public interface TUserMapper { List<TUser> selectTestResultMap(); } (2)Mapper.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis...