1. 使用mybatis generater自动生成entity、service、mapper
1.1 entity:ExpenseAccount
注意entity的LocalDateTime都改成Date
在create_time和update_time前分别加 @TableField(fill = FieldFill.INSERT)
和 @TableField(fill = FieldFill.UPDATE)
1.2 sevice:ExpenseAccountService
1.2.1 生成流水号serialNumberUtil
package com.realdd.medcost.common.utils;
import cn.hutool.core.date.format.FastDateFormat;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
* Created by duanduan on 2020/11/8 17:42
*/
@Component
public class SerialNumberUtil {
public String getSerialNumber(){
//1.获取当前时间
String t=FastDateFormat.getInstance("yyyyMMddHHmmssSSS").format(new Date());
//2.获取3位随机数
int x=(int)(Math.random()*900)+100;
return t+x;
}
}
1.2.2 ExpenseAccountServiceImpl
@Autowired
SerialNumberUtil serialNumberUtil;
@Override
public boolean create(ExpenseAccount expenseAccount) {
expenseAccount.setSerialNum(serialNumberUtil.getSerialNumber());
return save(expenseAccount);
}
1.3controller:ExpenseAccountController
@Autowired
ExpenseAccountService expenseAccountService;
@ApiOperation("添加报销单")
@PostMapping(value = "/create")
public CommonResult create(ExpenseAccount expenseAccount){
boolean success=expenseAccountService.create(expenseAccount);
if(success){
return CommonResult.success(null);
}
return CommonResult.failed();
}