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") //我们想调用Controller下面的方法必须在/superadmin这个路径下去调用
public class AreaController {
	@Autowired
	private AreaService areaService;
	@RequestMapping(value="/listarea", method=RequestMethod.GET)//加一个路由指定方法名和请求类型。约定:凡是前端访问的方法都是小写,便于URL编写
	@ResponseBody //指定返回值将modelMap对象自动转换成json对象返回给前端
	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;
	}
}

浏览器访问:http://localhost:18080/o2o/superadmin/listarea
校园商铺-2项目设计和框架搭建-10验证controller

相关文章:

  • 2021-06-15
  • 2022-01-27
  • 2021-07-24
  • 2021-11-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
猜你喜欢
  • 2021-10-12
  • 2021-05-21
  • 2021-10-22
  • 2021-05-27
  • 2021-09-12
  • 2022-12-23
  • 2021-05-23
相关资源
相似解决方案