用到一个客户编码,和注册登记时间,让我在新增客户信息的时候就立刻全部自动生成,代码粘在这里,对你有用的话,也希望可以帮到大家:
1)生成六位数的随记客户编码串,写了一个工具类RandomStringUtil .java,拿走即用:
import java.util.Random;
/**
* 产生随机字符串,长度由参数指定。
* @param length 产生的字符串的长度
* @return 已产生的字符串
* @author Code_小生
*/
public class RandomStringUtil {
public static String getRandString(int length)
{
String charList = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
String rev = "";
Random f = new Random();
for(int i=0;i<length;i++)
{
rev += charList.charAt(Math.abs(f.nextInt())%charList.length());
}
return rev;
}
}
2)生成注册登记时间,其实可以写在时间工具类里面,然后调用工具类哈(后期优化吧):
//新增客户信息
@ResponseBody
@RequestMapping(value="/save",method=RequestMethod.POST)
public R saveCustomer(@RequestBody CrmCustomerVO crmCustomerVO){
logger.info("开始增加新的客户信息");
//自动默认生成用户的注册时间
long time= System.currentTimeMillis();
Date date = new Date(time);
crmCustomerVO.setRegistrationTime(date);
crmCustomerService.save(crmCustomerVO);
return R.ok();
}