用mybatis的时候,实体类字段基本类型最好是包装类,最好不要设置默认值,否则 xml 里处理会很尴尬。
如果出现这种情况了,实体类里建一个设置初始值为null 的构造函数。
package com.bugyun.test; public class Student { /** * 这两个字段最好不要设置初始值 */ private Integer id = 0; private Integer clzssId = 0 ; /** * 如果设置初始值了,建议用置空的构造函数 */ public Student(Integer id, Integer clzssId) { super(); this.id = null; this.clzssId = null; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public Integer getClzssId() { return clzssId; } public void setClzssId(Integer clzssId) { this.clzssId = clzssId; } }