Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map<String, Object> 作为返回值没数据抛出 返回结果处理异常:null #56

Closed
btbox opened this issue Oct 9, 2022 · 8 comments
Labels
bug Something isn't working

Comments

@btbox
Copy link

btbox commented Oct 9, 2022

  • 当我使用一下语句查询的时候,Map<String, Object> 作为返回值,有值的时候正常,但是没值的时候为 org.nebula.contrib.ngbatis.exception.ResultHandleException: 返回结果处理异常:null

  • 语句

FETCH PROP ON tag_case "test_1" YIELD properties(vertex) AS v;
@CorvusYe CorvusYe added the bug Something isn't working label Oct 9, 2022
CorvusYe added a commit to CorvusYe/ngbatis that referenced this issue Oct 9, 2022
@CorvusYe
Copy link
Collaborator

CorvusYe commented Oct 9, 2022

刚刚提交一个版本,如果你用的是1.1.0-rc版本,可以自己先继承一个AbstractResultHandler<Map, Map>,参考MapResultHandler,加一个rowsSize为0的判断

@CorvusYe
Copy link
Collaborator

CorvusYe commented Oct 9, 2022

判断条件如下:

    if (result.rowsSize() == 0) {
      return null;
    }

参考 ObjectResultHanlder.java

@btbox
Copy link
Author

btbox commented Oct 9, 2022

加了但是没起效

@Component
public class MyMapResultHandler extends AbstractResultHandler<Map, Map> {

    @Override
    public Map handle(Map newResult, ResultSet result, Class resultType) {
        if (result.rowsSize() == 0) {
            return null;
        }
        List<String> columnNames = result.getColumnNames();
        ResultSet.Record record = result.rowValues(0);
        for (int i = 0; i < columnNames.size(); i++) {
            ValueWrapper valueWrapper = record.values().get(i);
            newResult.put( columnNames.get(i ), ResultSetUtil.getValue( valueWrapper ));
        }
        return newResult;
    }

}

@CorvusYe
Copy link
Collaborator

CorvusYe commented Oct 9, 2022

那你在 springboot 的入口,scanBasePackages 把 ngbatis 的包往前放

@SpringBootApplication(scanBasePackages = {"org.nebula.contrib", "your.domain"})
public class NgbatisDemoApplication {

}

修改 scanBasePackages 的顺序即可,其他保持你原来的样子。
让 ngbatis 的 bean 先加载,自己域下的 bean 后加载,这样就能覆盖掉有 bug 的 MapResultHandler

等下个版本发布,到时候再来回复这个issue,你把刚刚创建的文件删掉即可。

@btbox
Copy link
Author

btbox commented Oct 9, 2022

好的,解决了感谢

@btbox btbox closed this as completed Oct 9, 2022
@CorvusYe
Copy link
Collaborator

CorvusYe commented Oct 9, 2022

不用这么客气的~
拓展自己项目里比较个性的类型,也可以用继承AbstractResultHandler的方法,第一个泛型是dao方法的返回值类型,第二个是xml的resultType(xml没有写默认与dao方法返回值类型一致)

@CorvusYe CorvusYe pinned this issue Oct 11, 2022
@CorvusYe
Copy link
Collaborator

If this bug occurs in your project,
The following can be used as temporary solutions:

  1. Create a class in your project, for example:

    @Component
    public class MyMapResultHandler extends AbstractResultHandler<Map, Map> {
    
        @Override
        public Map handle(Map newResult, ResultSet result, Class resultType) {
            if (result.rowsSize() == 0) {
                return null;
            }
            List<String> columnNames = result.getColumnNames();
            ResultSet.Record record = result.rowValues(0);
            for (int i = 0; i < columnNames.size(); i++) {
                ValueWrapper valueWrapper = record.values().get(i);
                newResult.put( columnNames.get(i ), ResultSetUtil.getValue( valueWrapper ));
            }
            return newResult;
        }
    
    }
  2. In scanBasePackages array, confirm that the package of ngbatis is before the project package :

    @SpringBootApplication(scanBasePackages = {"org.nebula.contrib", "your.domain"})
    public class NgbatisDemoApplication {
    
    }
  3. Comment on this issue to receive notification when the next version is released, and then delete MyMapResultHandler

CorvusYe added a commit that referenced this issue Oct 17, 2022
fix: #56 make it work well when returnType is Map and result is null
@CorvusYe
Copy link
Collaborator

@zb139407 @hejiahuichengxuyuan
新版本1.1.1已经发布,如果maven还下载不下来,应该是多个仓库还没同步的问题,可以明天再试试。
切换版本后,MyMapResultHandler可以从项目中移除了。

@CorvusYe CorvusYe unpinned this issue Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants