mybatis中resultMap引发的吐血bug
简单的讲:
问题背景:如果在写mybatis中的resultMap时,不下心将resultMapde id写成映射接口的名字,会发生什么?
结论:单元测试进度条卡住但不报错, Tomcat运行不报错,但是不加载项目
以下是详细的:
需求:从数据库中加载之前插入log日志,打印在某一页面上。
如:
Java中的pojo:
package pojo;
import java.io.Serializable;
import java.util.Date;
/**
* 系统日志
*
* @author Administrator
*/
public class Log implements Serializable {
private static final long serialVersionUID = -7372303516713218870L;
private int id;//
private int userId;//
private String userName;
private Date createDate;//创建日期
private String content;//日志内容
private String operation;//用户所做的操作
private String url;//用户所做的操作
public Log() {
}
public Log(int id, int userId, String userName, Date createDate, String content, String operation, String url) {
this.id = id;
this.userId = userId;
this.userName = userName;
this.createDate = createDate;
this.content = content;
this.operation = operation;
this.url = url;
}
public static long getSerialVersionUID() {
return serialVersionUID;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getOperation() {
return operation;
}
public void setOperation(String operation) {
this.operation = operation;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
@Override
public String toString() {
return "Log{" +
"id=" + id +
", userId=" + userId +
", userName='" + userName + '\'' +
", createDate=" + createDate +
", content='" + content + '\'' +
", operation='" + operation + '\'' +
", url='" + url + '\'' +
'}';
}
}
利用mybatis读取数据时,发生不可理解的事情:
public List<Log> listAll();
<resultMap id="LogMapper" type="Log">
<id column="userid" property="userId"/>
<result column="username" property="userName"/>
<result column="content" property="content"/>
<result column="operation" property="operation"/>
<result column="createdate" property="createDate"/>
<result column="url" property="url"/>
</resultMap>
<select id="listAll" resultMap="LogMapper">
SELECT * FROM t_log
</select>
程序一旦单元测试就会进入这样的状态,
无限循环,没有结束。不仅这个方法,所有的测试方法都进入这种“阻塞”的状态,关键还没有异常的提示(哭~)
不仅如此,重启tomcat会进入这样
一方面tomcat不再加载项目,同时释放了几个看起来像是bug的坑,其实这些都时正常的信息,没有其他的东西!
期间重新导过jar包,删除过tomcat,重新部署项目,但只有一添加上述代码,就会崩溃。最后发现,原来和接口名字重复了,重复了。。。。。