Spring整理
TestController
@Controller@RequestMapping("/test")public class TestController {@Autowiredprivate TestService testService;@RequestMapping("/init")public ModelAndView init(HttpServletRequest request,HttpServletResponse response) {Map<String, Object> resultMap = null;try{resultMap = new HashMap<String, Object>();//查询实体类TestTable o = testService.doSomeBusinessStuff("1");System.out.println(o.getId());PageInfo page = new PageInfo();page.setCurrentPage(1);//分页List<TestTable> oList = testService.getMemberListPage(page);System.out.println(oList.size());resultMap.put("list", oList);}catch (Exception e) {// TODO: handle exception}return new ModelAndView("/sample", resultMap);}@RequestMapping("/list")@ResponseBodypublic Object list(@RequestParam String data,@RequestParam String pager, HttpServletRequest request,HttpServletResponse response) {JSONObject jData=JSONObject.fromObject(data);//查询条件JSONObject jPager=JSONObject.fromObject(pager);//分页条件List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();Pager p = new Pager();int total=99;//从service层获取p.setTotal(total);p.setPageNo(jPager.optInt("pageNo",1));p.setPageSize(jPager.optInt("pageSize",10));int len=p.getPageSize();if(len>p.getTotal()-(p.getPageNo()-1)*p.getPageSize()){len=p.getTotal()-(p.getPageNo()-1)*p.getPageSize();}for(int i=(p.getPageNo()-1)*p.getPageSize();i<(p.getPageNo()-1)*p.getPageSize()+len;i++){Map<String, Object> map = new HashMap<String, Object>();map.put("id", i);map.put("key1", i*2);map.put("key2", i*3);//自定义标签内容map.put("key3", "<a name="sp1" href="#">编辑</a> <a name="sp2" href="#">数据监控</a> <a name="sp3" href="#">注销</a> ");list.add(map);}p.setResultList(list);return p;}}
@Transactionalpublic interface TestService {TestTable doSomeBusinessStuff(String userId);//分页List<TestTable> getMemberListPage(@Param("page") PageInfo page);}
@Servicepublic class TestServiceImpl implements TestService {// DAOprivate UserMapper userMapper;@Autowiredpublic void setUserMapper(UserMapper userMapper) {this.userMapper = userMapper;} @Autowiredpublic TestTable doSomeBusinessStuff(String userId) {return this.userMapper.getUser(userId);}@Overridepublic List<TestTable> getMemberListPage(PageInfo page) {return this.userMapper.getMemberListPage(page);}}