1. 程式人生 > >java springboot 處理函式 JsonResult JSONArray 以及JsonResult JSONArray複雜字串形式 資料庫形式的方法

java springboot 處理函式 JsonResult JSONArray 以及JsonResult JSONArray複雜字串形式 資料庫形式的方法

後臺java處理函式 JsonResult 形式
public JsonResult deleteReUser(String accountId) {
JsonResult result = new JsonResult<>();
。。。
try {

    } catch (Exception e) {
        e.printStackTrace();
        result.setMessage(e.getMessage());
        result.setSuccess(false);
    }
    return result;
}

後臺java處理JSONArray形式
@GetMapping("/getStreetData")
public JSONArray getStreetData(String areaCode) {
JSONArray array = new JSONArray();
BaseStreetExample baseStreetExample = new BaseStreetExample();
BaseStreetExample.Criteria criteria = baseStreetExample.createCriteria();
criteria.andAreacodeEqualTo(areaCode);
Collection baseStreets = baseStreetMapper.selectByExample(baseStreetExample);
for(BaseStreet baseStreet : baseStreets) {
JSONObject object = new JSONObject();
object.put(“name”, baseStreet.getName());
object.put(“value”, baseStreet.getCode());
array.add(object);
}
return array;
}

後臺Java返回JsonResult 複雜字串形式 資料庫複雜比較等功能
@PostMapping("/login")
public JsonResult login(@RequestBody Account account)
{
//JsonResult result = new JsonResult<>();
JsonResult result = new JsonResult<>();
result.setSuccess(false);
try{
JSONObject object = new JSONObject();
AccountExample accountExample = new AccountExample();
AccountExample.Criteria criteria = accountExample.createCriteria();
criteria.andMobileEqualTo(account.getMobile());
List accountList = accountMapper.selectByExample(accountExample);
object.put(“account”,accountList==null||accountList
.size()==0 ? null:accountList.get(0));
result.setData(object);
}catch (Exception e){
e.printStackTrace();
result.setMessage(“登入異常!”);
}
return result;
}

後臺java處理函式 GridResult形式

public GridResult<Map<String, Object>> getReUser(can1,can2) {
List<Map<String, Object>> list = mybatisService.selectList(“SANLIAN_MAPPER.getQueryRecoveryUser”, new LinkedHashMap<>());
return new GridResult<>(list, list == null ? 0 : list.size());
}