1、jdbcType=“int"和jdbcType=”_int"的区别
<resultMap id="Application" type="org.bean.Application">
<constructor>
<idArg column="id" javaType="_int"/>
<arg column="project_id" javaType="_int"/>
<arg column="name" javaType="string"/>
<arg column="description" javaType="string"/>
<arg column="deleted" javaType="_int"/>
</constructor>
</resultMap>
public class Application {
private int id;
private int projectId;
private String name;
private int deleted;
public Application(int id, int projectId, String name, String description, int deleted) {
this.id = id;
this.projectId = projectId;
this.name = name;
this.description = description;
this.deleted = deleted;
}
}
上面代码中mybatis的jdbcType=“int"须和Application中Integer类型对应,jdbcType=”_int"需和Application中int类型对应,任何一方不对应都会报java.lang.NoSuchMethodException: com.common.bean.Application.(int, int, java.lang.String, java.lang.String, int)错误。
2、报错:
The error may involve defaultParameterMap.
The error occurred while setting parameters.
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure.
解决:我出现的原因是在写mybatis的mapper文件时在sql语句后面用/**/写了注释,删掉就好了。
原来:<select id="retrieveAll" resultMap="Event"> select * from event_definition /*where type='HD'*/ </select>
改成:<select id="retrieveAll" resultMap="Event"> select * from event_definition </select>
就成功了。
还有一个解决方案,我在网上找到的,将jdbc:mysql://127.0.0.1:3306/hr?useUnicode=true&characterEncoding=UTF-8&useSSL=false中的useSSL=false配置去掉也能成功。
注:我用的mysql是8.0.11版本,mybatis是3.5.0版本。