java - Mybatis 参数类型问题,应该是Map,结果报错.
阿神
阿神 2017-04-18 10:51:33
0
5
884

我写了个查询接口,传入的参数是个Map,写SQL的时候,我在parameterType填写java.util.Map,调用居然报错,类型转换错误,String转map失败.我把parameterType改为String就没报错,结果出来了,但是我传入的是2个值啊!!!!!真崩溃~!
代码如下:
接口:

报错的XML:

修改为这样就正常了:

但是我SQL里是多个参数啊,不应该用Map么???求大神解答疑惑

阿神
阿神

闭关修行中......

reply all(5)
Peter_Zhu

Your map is null. You can post the error

Ty80

Because you did not specify @Param 注解,当此时只有一个参数的时候,会自动拆开。Map 类型会按 <String, Object> 拆开。复杂数据类型会根据 getter to disassemble it in the method of mapper interface.

You can refer to this: https://my.oschina.net/triday... .

巴扎黑

You specify the key value of the Map in the interface

PHPzhong

It may be that the interface Map does not have a specified type. It is recommended to make some modifications:

public Module selectByMap(Map<String, Object> map)
Peter_Zhu

Owner, I am encountering the same problem as you. According to your comment reply, the parameter type in the mapper file is changed to hashMap. The DAO layer does not need any annotations. The value syntax in the sql statement is the same as yours, but it still does not work. Get the value and solve

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template