mybatis注解插入返回主键走过的坑

//keyProperty 放的是对象的属性,如果用@Param注解传递参,则要p.id选择属性,否则返回不了主键值
@Options(useGeneratedKeys = true,keyProperty = "p.id",keyColumn = "id")

//@SelectKey注解也是一样
@SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="p.id", before=false, resultType=Integer.class)


int addProjectContract(@Param("p") ProjectContract projectContract);

//两种注解选择一种就可以了

拿值:

        int i = projectContractService.addProjectContract(p);
        System.out.println(i);//返回的是执行数
        System.out.println(p.getId());//通过对象获取主键值

 

你可能感兴趣的:(框架)