Java writes an interface (including token), and third party calls

Source: Internet
Author: 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 ();

}


Note: Parse through JSON and give each other a third party interface.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.