Spring整理
TestController
@Controller @RequestMapping("/test") public class TestController { @Autowired private 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") @ResponseBody public 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; } }
TestService
@Transactional public interface TestService { TestTable doSomeBusinessStuff(String userId); //分页 List<TestTable> getMemberListPage(@Param("page") PageInfo page); }
TestServiceImpl
@Service public class TestServiceImpl implements TestService { // DAO private UserMapper userMapper; @Autowired public void setUserMapper(UserMapper userMapper) { this.userMapper = userMapper; } @Autowired public TestTable doSomeBusinessStuff(String userId) { return this.userMapper.getUser(userId); } @Override public List<TestTable> getMemberListPage(PageInfo page) { return this.userMapper.getMemberListPage(page); } }
相关推荐
yupi0 2020-10-10
spring 2020-08-18
编程点滴 2020-07-29
幸运小侯子 2020-07-05
itjavashuai 2020-07-04
qingjiuquan 2020-06-29
shushan 2020-06-25
小鱿鱼 2020-06-22
咻pur慢 2020-06-18
melonjj 2020-06-17
qingjiuquan 2020-06-13
neweastsun 2020-06-05
小鱿鱼 2020-06-05
mxcsdn 2020-05-31
吾日五省我身 2020-05-27
牧场SZShepherd 2020-05-27
sweetgirl0 2020-05-14