由于id字段设计为了varchar2,所以实体类字段设置为String类型:
@Data
@TableName(value="testplus")
//注意这里需要根据id字段的类型修改下面的参数 clazz = String.class
//如果id是Integer类型,则用Integer
@KeySequence(value = "SEQ_TESTPLUS_ID", clazz = String.class)
public class TestPlus implements Serializable {
/**
* 主键
* @TableId中可以决定主键的类型,不写会采取默认值,默认值可以在yml中配置
* AUTO: 数据库ID自增
* INPUT: 用户输入ID
* ID_WORKER: 全局唯一ID,Long类型的主键
* ID_WORKER_STR: 字符串全局唯一ID
* UUID: 全局唯一ID,UUID类型的主键
* NONE: 该类型为未设置主键类型
*/
@TableId(value = "ID", type = IdType.INPUT)
private String id;
private String name;
private int age;
private String gender;
private double score;
}
mapper层、service层、serviceImpl层都是继承了公用类:
public interface TestPlusMapper extends BaseMapper<TestPlus> {}
public class TestPlusServiceImpl extends ServiceImpl<TestPlusMapper, TestPlus> implements TestPlusService {}
public interface TestPlusService extends IService<TestPlus> {}
以下是controller调用:
@RequestMapping(value="/insert",method = RequestMethod.POST)
public Object insert(@RequestBody Map<String,Object> map){
String site = (String) map.get("site");
String empNo = (String)map.get("empNo");
TestString testString = new TestString();
testString.setSite(site);
testString.setCreateEdit(empNo);
testString.setCreateTime(new Date());
int a = testStringService.insert(testString);
if(a==1){
return "添加成功";
}
return "添加失败";
}
以下是数据表:
以上是表结构,学习mybatis plus随便建的。
以上代码可以正常运行,哪里不对希望大神指正!