Giter Site home page Giter Site logo

Comments (8)

CorvusYe avatar CorvusYe commented on May 20, 2024 1

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

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

}

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

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

from ngbatis.

CorvusYe avatar CorvusYe commented on May 20, 2024 1

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

from ngbatis.

CorvusYe avatar CorvusYe commented on May 20, 2024

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

from ngbatis.

CorvusYe avatar CorvusYe commented on May 20, 2024

判断条件如下:

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

参考 ObjectResultHanlder.java

from ngbatis.

btbox avatar btbox commented on May 20, 2024

加了但是没起效

@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;
    }

}

from ngbatis.

btbox avatar btbox commented on May 20, 2024

好的,解决了感谢

from ngbatis.

CorvusYe avatar CorvusYe commented on May 20, 2024

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

from ngbatis.

CorvusYe avatar CorvusYe commented on May 20, 2024

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

from ngbatis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.