通过HttpClient调用接口,并使用mongoDB对数据库进行查询新增

 


@RequestMapping("queryEmp")
	@ResponseBody
	public String queryEmp(String expNo) {
		HashMap params = new HashMap<>();
		params.put("expNo", expNo);
		String string = HttpClientUtil.get("http://localhost:8080/emp/queryEmp.do", params);
                                    //JSON格式转换注意导包  alibaba
		List parseArray = JSON.parseArray(string,ExpBean.class); 
		Query query = new Query();
		query.addCriteria(Criteria.where("expNo").is(expNo));  
		long count = mongoTemplate.count(query, ExeBean.class);
		if (count == 0) {
			for (ExpBean expBean : parseArray) {  //新增到mongodb数据库
				ExeBean exeBean = new ExeBean();
				exeBean.setExpNo(expBean.getExpNo());
				exeBean.setExpTime(expBean.getExpTime());
				exeBean.setExpStatus(expBean.getExpStatus());
				exeBean.setExpContext(expBean.getExpContext());
				mongoTemplate.save(exeBean);
			}
		}
		return string;
	}

 

你可能感兴趣的:(通过HttpClient调用接口,并使用mongoDB对数据库进行查询新增)