@Value("${factory.url.send}") private String sendurl; http://8.8.8.8888:9999/Service/SendDuanXinService.asmx?wsdl /** * soap方式调用 * @param pA * @param pB * @return * @throws Exception */ public boolean send2(String pA,String pB) throws Exception { SendMessageService smsService = new SendMessageService(new URL(sendurl)); SendMessageServiceSoap smsSoap = smsService.getSendMessageServiceSoap(); SmsMessageData messageData = new SmsMessageData(); messageData.setMobile(pA); messageData.setMessageContent(pB); logger.info(Request->" + GsonUtils.toJson(messageData)); boolean result = smsSoap.sendSmsMessage(messageData); return result; } /** * Post方法查询 * @param A * @param B * @param pC * @return * @throws Exception */ public boolean send3(String pA, String pB, String pC) throws Exception{ Map<String,Object> paramMap = new HashMap<String,Object>(); paramMap.put("pA", pA); paramMap.put("pB", pB); paramMap.put("pC", pC); String jsonContent = GsonUtils.toJson(paramMap);//map对象 logger.info("request->" + jsonContent); StringEntity entity = new StringEntity(jsonContent,"UTF-8"); entity.setContentType("application/json"); String respJson = HttpClientUtils.getMethodPostResponse(sendurl, entity); if (StringUtils.isBlank(respJson)) { throw new RuntimeException("自定义异常提示语"); } logger.info("response->" + respJson); JSONObject json = JSONObject.parseObject(respJson); String msg = json.getString("msg"); String status = json.getString("status"); String data = json.getString("data"); if("1".equals(status)){ return true; } return false; } /** * post方法调用 * @param paramA * @param paramB * @return * @throws Exception */ public TestDto send(String paramA, String paramB) throws Exception { TestDto request = new TestDto(); request.setParamA("A"); request.setParamB("B"); //content String content = GsonUtils.toJson(request);//实体对象 List<NameValuePair> paramList = new ArrayList<NameValuePair>(); paramList.add(new BasicNameValuePair("smsJsonString", content)); UrlEncodedFormEntity paramEntity = new UrlEncodedFormEntity(paramList, "utf-8"); String responseJson = HttpClientUtils.getMethodPostResponse(sendurl, paramEntity); String result = XmlUtils.xml2Obj(responseJson, String.class); if (StringUtils.isBlank(result)) { throw new RuntimeException("自定义异常提示语"); } return GsonUtils.convertObj(result, TestDto.class); } /** * Get方法查询 */ @Value("${sku.pdf.download.url}") private String getPdfUrl; //获取服务器类型文件PDF(以base64字节流的形式) public SkuEntity getRemoteFileInfo(String sid, String nameValueStr) throws Exception { String address = getPdfUrl+"?skuid="+sid+"&filetype="nameValueStr; String respJson = HttpClientUtils.getMethodGetResponse(address); return GsonUtils.convertObj(respJson, SkuEntity.class); }
重定向
@Controller @RequestMapping(value = "/callBack") public class CallBackController { private static final Logger logger = LoggerFactory.getLogger(CallBackController.class); @Value("${xyxc.app.homepage}") private String homePageUrl; @RequestMapping(value = "/forwarda", method = RequestMethod.POST, headers = "Content-Type=application/x-www-form-urlencoded") public void frontRecv(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { response.sendRedirect(homePageUrl); } @RequestMapping(value = "/forwardb", method = RequestMethod.GET) public void frontRecv2(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { response.sendRedirect(homePageUrl); } }
Controller--Service--Dao
@Path("/stu") @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8") @Consumes(MediaType.APPLICATION_JSON + ";charset=utf-8") public class StudentController { private static final Logger logger = LoggerFactory.getLogger(StudentController.class); @Autowired public AService aService ; @Autowired public StudentService studentService ; @Autowired private EntryManager entryManager; @Autowired private RedisManager redisManager; @POST @Path("/doSearch/list") public Response doSearchFun(Map<String, Object> paramMap) throws Exception{ ...} } @Component @Transactional(rollbackFor = Exception.class) public class EntryManager { @Autowired public RedisManager redisManager; public String doPutEntryIntoRedis(String appId) throws Exception{ String entry = getStr(); cacheManager.set(entry, appId, 1800);//1800s return entry; } @MyBatisRepository public class StudentDao extends BaseDao<StudentEntity, Long> { public StudentEntity getResultById(Long sid) { return getSqlSession().selectOne(entityClassName + ".getResultById", sid); } public List<StudentEntity> getListByCondition(StudentEntity query) { return getSqlSession().selectList(entityClassName + ".getListByCondition", query); } public int updateByCondtion(StudentEntity entity) { return getSqlSession().update(entityClassName + ".updateByCondtion", entity); } public StudentEntity getStudentByCondition(Long sid,Long cid){ Map<String, Object> map = new HashMap<String, Object>(); map.put("sid", sid); map.put("cid", cid); return getSqlSession().selectOne(entityClassName + ".getStudentByCondition", map); } }