@RequestMapping("/addplan")
public @ResponseBody OnlineAddplanWithBLOBs insertOnlineAddplan(OnlineAddplanWithBLOBs plan) throws Exception{
//plan是添加的数据,planid为数据主键,此时对象中主键为null
int n = service.insertOnlineAddplan(plan);
//获取对象主键
System.out.println("返回的主键值是"+plan.getPlanid());
return plan;
}
在mapperx.xml中
<insert id="insert" parameterType="com.online.pojo.OnlineAddplanWithBLOBs" >
//获取序列值,并赋值到对象的planid字段;keyProperty与实体类名称保持一直
<selectKey keyProperty="planid" resultType="DECIMAL" order="BEFORE">
select online_sequence.nextval from dual
</selectKey>
insert into ONLINE_ADDPLAN (PLANID, COMPLETETIME, PERSON,OPERATION, USERNAME, EVENTNODE, WORKPLAN, CHENGGUOMIAOSHU)
//获取上面对象中planid字段的值
values (#{planid,jdbcType=DECIMAL}, #{completetime,jdbcType=TIMESTAMP}, #{person,jdbcType=VARCHAR},
#{operation,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR}, #{eventnode,jdbcType=CLOB},
#{workplan,jdbcType=CLOB}, #{chengguomiaoshu,jdbcType=CLOB})
</insert>