天天看點

添加之前查詢資料庫是否已經添加過(去空格後存儲到資料庫)!

public Map<String,Object> TcarinfoInsert(TCarInfo tCarInfo){
    Map<String,Object> result=  new HashMap<>();
    //車牌号去空
    String plateNo=tCarInfo.getPlateNo().replaceAll(" ","");
    //根據車牌号查詢車資訊
    TCarInfo _tCarInfo=commondao.findOne(TCarInfo.class,"where tcarinfo.plateNo = ? ", plateNo);
    if(_tCarInfo==null){
        tCarInfo.setPlateNo(plateNo);
        try {
            commondao.insert(tCarInfo);
        } catch (Exception e) {
            e.printStackTrace();
            result.put("code",0001);
            result.put("msg","添加失敗");
        }
        result.put("code",0000);
        result.put("msg","添加成功");
    }else{
        //生成驗證碼
        new Random();
        result.put("code",0002);
        result.put("msg","添加成功");
        // 調短信驗證接口,目前手裡沒有接口
    }
    return result;
}      

繼續閱讀