一、2018年12月1日23:38:18 dao层接口 public interface AreaDao { /** * 列出区域列表List * @return List<Area> */ public List<Area> queryArea(); } mapper dao层接口的实现 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.imooc.dao.AreaDao"> <!--查询出的结果转化为Area对象的列表,每一个实体类--> <select id="queryArea" resultType="com.imooc.entity.Area"> SELECT area_id,area_name,priority,create_time,last_edit_time FROM tb_area ORDER BY priority DESC </select> </mapper> service层接口 public interface AreaService { public List<Area> getAreaList(); } service层接口的实现 @Service public class AreaServiceImpl implements AreaService { @Autowired private AreaDao areaDao; public List<Area> getAreaList() { return areaDao.queryArea(); } } controller层 @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(); //前端使用的是easyUI modelMap.put("rows",list); modelMap.put("total",list.size()); }catch ( Exception e ){ e.printStackTrace(); modelMap.put("success",true); modelMap.put("errMsg",e.toString()); } return modelMap; } } 测试 //http://localhost:8080/money/superadmin/listarea 返回json格式的数据库数据 {"total":2, "rows":[{"areaId":2,"areaName":"西苑","priority":2,"createTime":null,"lastEditTime":null}, {"areaId":1,"areaName":"东苑","priority":1,"createTime":null,"lastEditTime":null}]}
点击查看更多内容
1人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦