校园商铺-2项目设计和框架搭建-10验证controller
作者:互联网
1.新建package:com.csj2018.o2o.web.superadmin
2.建立AreaController.java
package com.csj2018.o2o.web.superadmin;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.csj2018.o2o.entity.Area;
import com.csj2018.o2o.service.AreaService;
@Controller
@RequestMapping("/superadmin")
public class AreaController {
@Autowired
private AreaService areaService;
@RequestMapping(value="/listarea", method=RequestMethod.GET)
@ResponseBody
private Map<String, Object> listArea(){
Map<String, Object> modelMap = new HashMap<String, Object>();
List<Area> list = new ArrayList<Area>();
try {
list = areaService.getAreaList();
modelMap.put("rows", list);
modelMap.put("total",list.size());
}catch(Exception e) {
e.printStackTrace();
modelMap.put("success",false);
modelMap.put("errMsg",e.toString());
}
return modelMap;
}
}
访问URL:http://localhost:18080/oto/superadmin/listarea
标签:10,java,web,商铺,modelMap,springframework,controller,import,org 来源: https://www.cnblogs.com/csj2018/p/11564147.html