1 @Override 2 public UserInfo login(String tel, String password) { 3 4 if (!DataValidate.isTelephone(tel)) { 5 6 return null; 7 } 8 9 password = MD5Util.MD5Password(password); 10 BusinessInfo bi = new BusinessInfo(); 11 bi.setTel(tel); 12 bi.setPassword(password); 13 BusinessInfo ir = businessInfoDao.login(bi); 14 System.out.println("result=" + ir); 15 16 if (ir == null) { 17 System.out.println("LLF.BusinessInfo.true"); 18 return null; 19 } 20 System.out.println("LLF.BusinessInfo.false"); 21 UserInfo ui = new UserInfo(); 22 ui.setId(ir.getId()); 23 ui.setUser(ir.getName()); 24 return ui; 25 }
1 @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 2 public class UserInfo { 3 private String user; 4 private int id; 5 private String tel; 6 public String getUser() { 7 return user; 8 } 9 public void setUser(String user) { 10 this.user = user; 11 } 12 public int getId() { 13 return id; 14 } 15 public void setId(int id) { 16 this.id = id; 17 } 18 public String getTel() { 19 return tel; 20 } 21 public void setTel(String tel) { 22 this.tel = tel; 23 } 24 25 }
你的控制层呢?
public ActionResult Fun() { return Json(user); } public string Fun() { //将user序列化为字符串返回 return JsonSerialization.Serialize(user); }
已经参悟其中正道....在控制层用Map类型,UserInfo类型的变量去接收方法返回,return modeMap。Ajax就正常data.data.id就可以正常获取值,不为空则成功。
控制器可以返回Json给前端啊!