模板自增主键代码是写在每个模板中的,是被注释掉的。需要把注释去掉,把原来的返回语句注释掉。
~~~
// 插入
public int insert(Book entity) throws DataAccessException {
// 这段注释代码是“返回自增主键”的方法
String entityName = entity.getClass().getSimpleName();
ResultMo mo = this.mlinktemplate.executeTemplate(ITemplate.FUNC_INSERT, entityName, null, entity);
if (mo != null) {
Integer auto = mo.getAutoIncrementId();
if (auto != null) {
return auto.intValue();
}
return -1;
}
return -1;
//return this.mlinktemplate.insert(entity);
}
~~~
public void billInsert() throws DataAccessException {
System.out.println("---------------------------------");
int random = (int)(1+Math.random()*(9999-1+1));
Bill entity = new Bill();
entity.setBillId(5337L);
entity.setHid(random);
entity.setMemo("d7777ddyyyyyddddddddddddddd");
BillTemplate billtemplate = new BillTemplate(mlinktemplate);
billtemplate.insert(entity);
Bill bill = billtemplate.get(5337L, 55577767);
System.out.println("bill>>"+bill);
}
public void bookInsert2() throws DataAccessException {
System.out.println("---------------------------------");
BookTemplate template = new BookTemplate(mlinktemplate);
Book entity = new Book();
entity.setBookName("MLINK模板的应用");
Long auto = new Long(template.insert(entity));
System.out.println("auto>>"+auto);
Book Book = template.get(5);
System.out.println("Book>>"+Book);
}