package com.yiya.action; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import com.yiya.bean.SiteMain; import com.yiya.bean.SiteType; import com.yiya.bean.BaseBean.DELETED; import com.yiya.model.SiteMainModel; import com.yiya.service.SiteMainService; import com.yiya.service.SiteTypeService; import com.yiya.utils.HtmlUtil; @Controller @RequestMapping("/siteMain") public class SiteMainAction extends BaseAction{ @Autowired private SiteMainService<SiteMain> siteMainService; @Autowired private SiteTypeService<SiteType> siteTypeService; /** * * @param url * @param classifyId * @return * @throws Exception */ @RequestMapping("/list") public ModelAndView list(SiteMainModel model,HttpServletRequest request) throws Exception{ Map<String,Object> context = getRootMap(); return forword("siteMain/siteMain",context); } /** * ilook 首页 * @param url * @param classifyId * @return * @throws Exception */ @RequestMapping("/dataList") public void datalist(SiteMainModel model,HttpServletResponse response) throws Exception{ model.setDeleted(0); List<SiteMain> dataList = siteMainService.queryByList(model); for(SiteMain bean: dataList){ String types = getTypeStr(bean.getId()); bean.setTypes(types); } //设置页面数据 Map<String,Object> jsonMap = new HashMap<String,Object>(); jsonMap.put("total",model.getPager().getRowCount()); jsonMap.put("rows", dataList); HtmlUtil.writerJson(response, jsonMap); } /** * 添加或修改数据 * @param url * @param classifyId * @return * @throws Exception */ @RequestMapping("/save") public void save(SiteMain bean,Integer[] typeIds,HttpServletResponse response) throws Exception{ Map<String,Object> context = new HashMap<String,Object>(); bean.setDeleted(DELETED.NO.key); if(bean.getId() == null){ siteMainService.add(bean); }else{ siteMainService.update(bean); } siteMainService.addTypeRel(typeIds, bean.getId()); sendSuccessMessage(response, "保存成功~"); } @RequestMapping("/getId") public void getId(Integer id,HttpServletResponse response) throws Exception{ Map<String,Object> context = new HashMap(); SiteMain bean = siteMainService.queryById(id); if(bean == null){ sendFailureMessage(response, "没有找到对应的记录!"); return; } List<SiteType> types= siteTypeService.queryBySiteId(bean.getId()); if(types != null && !types.isEmpty()){ int[] typeIds = new int[types.size()]; for(int i=0;i< types.size() ;i++){ typeIds[i] = types.get(i).getId(); } bean.setTypeIds(typeIds); } context.put(SUCCESS, true); context.put("data", bean); HtmlUtil.writerJson(response, context); } @RequestMapping("/delete") public void delete(Integer[] id,HttpServletResponse response) throws Exception{ siteMainService.delete(id); sendSuccessMessage(response, "删除成功"); } private String getTypeStr(Integer siteId) throws Exception{ List<SiteType> types= siteTypeService.queryBySiteId(siteId); if(types == null || types.isEmpty()){ return null; } StringBuffer str = new StringBuffer(); int i=1; for(SiteType type : types){ str.append(type.getName()); if(i < types.size()){ str.append(","); } i++; } return str.toString(); } }

sjwc88 LV3
1月25日
hefeng LV2
2024年5月27日
goccgoccgocc LV4
2024年5月9日
1303891 LV1
2024年4月14日
n2352441 LV4
2024年3月3日
quartz LV8
2024年1月22日
大鹏秀秀鹏鹏 LV14
2023年12月13日
ICEneco LV1
2023年10月21日
oulingqiao LV13
2023年10月7日
张朕朕 LV3
2023年9月8日

15578157792 LV7
4月26日
charles0908
4月25日
暂无贡献等级
1203767407 LV1
4月18日
dj710857819
4月15日
暂无贡献等级
dylyc13
4月15日
暂无贡献等级
chengguo123
4月2日
暂无贡献等级
luhong LV3
3月31日
小宋敲代码
3月25日
暂无贡献等级
billy-zuidaima LV1
3月24日
calm_z LV2
3月23日