mybatis中需要加两个参数
<insert id="addChannel" parameterType="cn.tcmp.entity.Channel_list" useGeneratedKeys="true" keyProperty="ChannelID">
INSERT INTO `channel_list`(ChanneltypeID,CorporateName,introduce,ContactName,ContactTelephone,ContactEmail,DocumentType,IdentificationNumber,Enclosure,CreationDate)
VALUES(#{chaId},#{Corporatename},#{introduce},#{ContactName},#{Contacttelephone},#{ContactEmail},#{Documenttype},#{IdentificationNumber},#{Enclosure},NOW())
</insert>
useGeneratedKeys="true"
keyProperty="ChannelID" 实体中的主键字段名
Controller层需要注意
//新增公司渠道信息
@RequestMapping(value = "doAddChannel")
@ResponseBody
public Integer doAddChannel(Channel_list channel_list){
channel_type_service.addChannel(channel_list);
return channel_list.getChannelID();
}
不能直接返回新增方法,直接返回的是受影响的行数,需要返回当前参数中的实体中的主键字段名