Java寫一個介面(包括token),第三方調用

來源:互聯網
上載者:User
@RequestMapping(value = "/advertListAction", produces = "text/html;charset=UTF-8")
@ResponseBody
public String advertListAction(HttpServletRequest request,
HttpServletResponse response) {
JSONArray jsonArray = new JSONArray();
JSONObject jsonObject = new JSONObject();
JSONObject jsonData = new JSONObject();
try {


List<Advert> adverts = advertDao.selectAdvert(0,0);
int i = 1;
for (Advert ad : adverts) {
if (ad.getStatus() != 1) {
continue;
}
JSONObject json = new JSONObject();
json.put("sort", i);
json.put("name", ad.getName());
json.put("createdate", DateUtils.formatDateTimeToString(ad
.getCreatedate()));
json.put("desc", ad.getDescs());
json.put("imgUrl", ServerStaticData.imgPath + "?imgId="
+ ad.getImgIds());
json.put("did", ad.getDid());
jsonArray.put(json);
i++;
}
jsonData.put("advert", jsonArray);
JSONArray menuJsonArray = new JSONArray();
String startDate = DateUtils.getMondayOfThisWeek();
String endDate = DateUtils.getSundayOfThisWeek();
String order = "asc";
List<GoodsCategoryMenu> weekMenus = menuDao.selectWeekMenu(
startDate, endDate, 0, 0, Constants.GOODS_TYPE_MENU, order);
for (GoodsCategoryMenu menu : weekMenus) {
JSONObject json = new JSONObject();
json.put("did", menu.getDid());
json.put("menuName", Constants.WEEK_MENU.get(menu.getName()));
json.put("menuDate", DateUtils.formatDateToString(menu
.getStartDate()));
json.put("tagline", menu.getTagline());
json.put("desc", menu.getDescs());
menuJsonArray.put(json);
}
JSONObject orderTimeJson = new JSONObject();
orderTimeJson.put("morningStart", Constants.ORDER_TYPE_MORNING_START);
orderTimeJson.put("morningEnd", Constants.ORDER_TYPE_MORNING_END);
orderTimeJson.put("noonStart", Constants.ORDER_TYPE_NOON_START);
orderTimeJson.put("noonEnd", Constants.ORDER_TYPE_NOON_END);
orderTimeJson.put("nightStart", Constants.ORDER_TYPE_NIGHT_START);
orderTimeJson.put("nightEnd", Constants.ORDER_TYPE_NIGHT_END);
jsonData.put("orderTime", orderTimeJson);
jsonData.put("menu", menuJsonArray);
jsonObject.put("data", jsonData);


jsonObject.put("code", Constants.COMMON_SUCCESS_CODE);
jsonObject.put("msg", Constants.COMMON_SUCCESS_CODE_MSG);
} catch (Exception e) {
jsonObject.put("code", Constants.COMMON_FAIL_ERROR_CODE);
jsonObject.put("msg", Constants.COMMON_FAIL_ERROR_CODE_MSG);
e.printStackTrace(LogUtil.getErrorStream(logger));
}


return jsonObject.toString();

}


註:通過json進行解析,給對方一個第三方介面。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.