開發筆記手冊(二)

接口原生開發
開發工具: eclipse + win 10
開發框架: springmvc + hibernate
如何開發用戶個人簡歷,下面用戶個人簡歷的接口的邏輯代碼。

 @RequestMapping("/user/personalMsg")
    public String personalMsg(HttpServletRequest request, ModelMap modelMap, String callback){

        if(user != null) {
            JSONObject jsonObject = new JSONObject();
            user = commUserBiz.findModel(user.getId());//重查用戶信息
            long userId = user.getId();
            String  sql = "select a.real_name, " + " b.imgId" + " from  vitae b, user a where  a.id = b.user_id and a.id = " + userId;    //聯合查詢
            System.out.println(sql);            
            List<Object> objList = vitaeBiz.queryListByNative(sql);
            String sqlImg = "select path from asg_resource where id = nike_img_id";
            if(objList.size()!=0){
                if(objList.size()==1){
                  for(Object obj: objList){
                     Object[] objs = (Object[]) obj;
                     long realName= CommUtil.null2Long(objs[0]);
                     long message= CommUtil.null2Long(objs[1]);   
                     String sqlResource = "select path from resource where id ="+ ImgId;
                     String imgResource =  (String)resourceBiz.queryByNative(sqlResource);
                     if(imgResource!=null)
                        imgResource = CommUtil.getStaticDomainImgUrl() + imgResource;//頭像圖片 
                     jsonObject.put("nikeImg",imgResource);
                     jsonObject.put("realName", realName);
             ret = CommUtil.jsonResult(true);
             ret.put("contents", jsonObject);
                    }               
                }     
         }
         } 
補充:
 1   @Autowired      //autowired註解插入dao層
      private ResourceBiz resourceBiz;
     @Autowired
      private VitaeBiz vitaeBiz;    
 2  @Controller    //controller 
    @RequestMapping("/mobile")
     public class CurrentUserManageAction
 3  @Service("VitaeBizWeb")      public class VitaeBiz extends CrudBiz<VitaeDao,Vitae> 
4     原生查詢方法. 
      public List<Object> queryListByNative(String sql) {
           return dao.findListByNative(sql);
    }
      原生查詢方法.        
    public List<Object> findListByNative(String sql) {
        Query query = entityManager.createNativeQuery(sql);
        return query.getResultList();
    }
  如果出現Null value was assigned to a property of primitive type setter of錯誤,那是由於類型不匹配,將實體類字段的屬性由hibernate的int類型改爲java.lang.Integer類型就行。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章