日期:2014-05-16 浏览次数:20431 次
最近做项目中需要根据输入的各个信息判断是否完善个人资料,如果8个信息:基本信息,履历,头像,风采,行业信息,个人简介,荣誉中有一项没填的话就展示完善个人资料。
?
// home页面样式,如果基本信息的6个模块有一个模块全为空就显示完善个人资料 AccountUser accountuser = userDao.getUserByUidForAccount(uid); boolean idcard = StringUtils.isEmptyOrWhitespaceOnly(accountuser .getIdcard()); boolean qualifyid = StringUtils.isEmptyOrWhitespaceOnly(accountuser .getQualifyid()); boolean agencyid = StringUtils.isEmptyOrWhitespaceOnly(accountuser .getAgencyid()); boolean photo = StringUtils.isEmptyOrWhitespaceOnly(accountuser .getPhoto()); List<ExtInfo> honor = userDao.getListExtinfoForAccount(uid); List<Resume> listresume = userDao.getListResumeByUidForAccount(uid); List<SelfStyle> listself = userDao.getListSelfByUidForAccount(uid); if ((idcard && qualifyid && agencyid) || photo || honor .size()==0 || listresume .size()==0 || listself.size()==0) { this.model.get().addAttribute("styledisplay", "style='display: block'"); } else { this.model.get().addAttribute("styledisplay", "style='display: none'"); }
?
dao:只列出一个dao
?
/** * * 获取用户id获取个人风采相关信息 * * @param uid * @return list */ public List<SelfStyle> getListSelfByUidForAccount(int uid) { if (uid <= 0) { return new ArrayList<SelfStyle>(); } // 获取当前用户的所有个人风采(selfstyle)信息 String sql = "select * from " + AppConstant.DATABASE_SCHEMA_UDB_BB_USER + "." + AppConstant.DATABASE_TABLE_UDB_SELFSTYLE + " where uid = :uid order by id desc"; SqlParameterSource paramSource = new MapSqlParameterSource("uid", uid); List<SelfStyle> selfstyle = new ArrayList<SelfStyle>(); try { selfstyle = this.namedJdbcTemplate.query(sql, paramSource, new BeanPropertyRowMapper(SelfStyle.class)); } catch (EmptyResultDataAccessException e) { // do nothing } return selfstyle; }
?
原来 我是判断查询出来的list是否为空,但是发现查询出来的不为Null 而是 [] ,原来spring jdbc
?
selfstyle = this.namedJdbcTemplate.query(sql, paramSource, new BeanPropertyRowMapper(SelfStyle.class));
?
这个查询方式返回 了一个 对象,所以导致上述情况,注意判断List有没有值要根据 list.size 进行判断这样就不会出现问题了。以后可不能犯这低级错误了 。。。