Passing multiple columns in myBatis

前端 未结 2 1900
后悔当初
后悔当初 2021-02-04 11:48

I want to know, how do we pass multiple columns in a myBatis association tag.

For example, I have the following xml snippet in one my mapper.xml file:

&l         


        
2条回答
  •  再見小時候
    2021-02-04 12:38

    Multiple column names can be passed as key value pairs

    @Results(value = { @Result(property = "CourseSubscription", column = "{courseId=id,userId=user_id}
    

    For more info, you can refer the

    org.apache.ibatis.builder.MapperBuilderAssistant.parseCompositeColumnName(String).columnName -- API which parses the meta-data of @Result.column()

    private List parseCompositeColumnName(String columnName) {
        List composites = new ArrayList();
        if (columnName != null && (columnName.indexOf('=') > -1 || columnName.indexOf(',') > -1)) {
          StringTokenizer parser = new StringTokenizer(columnName, "{}=, ", false);
          while (parser.hasMoreTokens()) {
            String property = parser.nextToken();
            String column = parser.nextToken();
            ResultMapping.Builder complexBuilder = new ResultMapping.Builder(configuration, property, column, configuration.getTypeHandlerRegistry().getUnknownTypeHandler());
            composites.add(complexBuilder.build());
          }
        }
        return composites;
      }
    

提交回复
热议问题