Mybatis中insert中返回主键ID的方法

1、XyzMapper.xml

2、XyzMapper.java

public int doSomething(Map<String, Object> parameters);

or

public int doSomething(YourClass c);

3、要在map或c中有一个字段名为yourId,Mybatis会自动把主键值赋给这个字段。

Map<String, Object> parameters = new HashMap<String, Object>();

parameters.put(“yourId”, 1234);

mapper.doSomething(parameters);

System.out.println(“id of the field that is primary key” + parameters.get(“yourId"));

YourClass c = new YourClass();

mapper.doSomething(c);

System.out.println(“id of the field that is primary key” + c.yourId);

,读书须用意,一字值千金。

Mybatis中insert中返回主键ID的方法

相关文章:

你感兴趣的文章:

标签云: