@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.