首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Spring拾掇

2013-12-05 
Spring整理TestController@Controller@RequestMapping(/test)public class TestController {@Autowiredp

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>&nbsp;<a name="sp2" href="#">数据监控</a>&nbsp;<a name="sp3" href="#">注销</a>&nbsp;");list.add(map);}p.setResultList(list);return p;}}


TestService
@Transactionalpublic interface TestService {TestTable doSomeBusinessStuff(String userId);//分页List<TestTable> getMemberListPage(@Param("page") PageInfo page);}


TestServiceImpl
@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);}}



热点排行