原文章不小心被删了 只好再写一篇了。。。
ps: 删除竟然没有确认 而且没有还原 csdn坑啊
实体类
public class EventInfo{
private Long id;
private String name;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
}
xml文件
<insert id="insert" useGeneratedKeys="true" keyProperty="id" keyColumn="ID" parameterType="com.model.EventInfo">
insert into T_EVENT_INFO (NAME)
values (#{name,jdbcType=VARCHAR}
</insert>
keyProperty为EventInfo对象中属性名称,keyColumn为数据库中对应字段名称 如果对象中的id值不是int或者Integer类型,则必须制定keyColumn列,否则报错
public int insert(record) {
this.getSqlSessionTemplate().insert(getSqlName(INSERT), record);
System.out.println(record.getId());
return count;
}