맵 사용 실례

3837 단어 map
1. ibatis 층

 
2. Dao층
 
  @SuppressWarnings("unchecked")
    public Map gets(String uid) {
        Map params = new HashMap();
        params.put("uid", uid);
        params.put("namespace", namespaceContext.getNamespace());
        return (Map) this.getSqlMapClientTemplate().
queryForMap("UserComment.getByUid", params,"friendId");
    }
3. 서비스 층
 MapgetComments(String uid);
4. 실현층
 
 public Map getComments(String uid) {
        if (StringUtil.isBlank(uid)) return  null;
        Map commentList = userCommentDao.gets(uid);
        if (commentList == null || commentList.isEmpty()) return null;
   return commentList;
    }
5. rpc층 테스트
 
  @SuppressWarnings("all")
    @ResourceMapping(value = "/getCommentsByUid", method = HttpMethod.GET)
    public Map getCommentsByUid(ErrorContext errorContext) {
        String uid = (String) session.getAttribute(SessionConstants.UID);
        if (uid == null) return null;
        try {
       
    return (Map) this.userService.getComments(uid);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            errorContext.addError(ErrorItem.create("get", "603", "친구 설명 조회 실패");
            return null;
        }
    }
 
결과를 반환하려면 다음과 같이 하십시오.

{"content":{"22001":{"uid":"585012","aliasNamePinyin":"ce^shi^a^a^a^a^a","friendId":"22001","aliasName":"\u6D4B\u8BD5\u554A\u554A\u554A\u554Aa"},"22002":{"uid":"585012","aliasNamePinyin":"ce^shi^b^b","friendId":"22002","aliasName":"\u6D4B\u8BD5bb"},"22003":{"uid":"585012","aliasNamePinyin":"ce^shi^c^2","friendId":"22003","aliasName":"\u6D4B\u8BD5c2"}},"resubmitToken":"035d0af2a6ab8add7204335c66fee974","submitToken":"035d0af2a6ab8add7204335c66fee974","hasError":false}


6、   map       

 Map<String, UserComment> comments = this.lwUserService.getComments(securityContext.getCurrentUserId());             List<ConnectionVO> users = new ArrayList<ConnectionVO>(friends.size());             UserComment uc = null;             for (BaseProfile friend : friends) {                 ConnectionVO connectionVO = new ConnectionVO();                 connectionVO.setName(friend.getName());                 connectionVO.setAvatar(friend.getAvatar());                 connectionVO.setPinyin(friend.getNamePinyin());                 connectionVO.setId(friend.getUid());               uc = comments.get(friend.getUid()); connectionVO.setAliasName(uc == null ? null : uc.getAliasName());                 connectionVO.setAliasNamePinyin(uc == null ? null : uc.getAliasNamePinyin());                 users.add(connectionVO);             }// end for        

 

좋은 웹페이지 즐겨찾기