controller层 #5

Merged
p6jzelshw merged 2 commits from py2tc4x5b/ssm:master into master 2 years ago

@ -0,0 +1,43 @@
package com.controller;
import com.dao.ITestDao;
import com.entity.TestEntity;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import com.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;
/**
* @ClassName TestController
* @Description TODO
* @Author YHT
* @Date 2021/5/31 15:19
*/
@Controller
public class TestController {
@Autowired
private ITestDao testDao;
@RequestMapping("/getTest")
public ModelAndView getTest(Page page){
ModelAndView mav = new ModelAndView();
//从数据库中获取记录
List<TestEntity> cs = testDao.list(page);
//获取记录总数
int total = testDao.total();
//计算得到总页数
int pageIndex = total / page.getCount();
pageIndex = total % page.getCount() == 0 ? pageIndex : pageIndex+1;
page.setTotalIndex(pageIndex);
page.calculateLast(total);
//将数据返回前端页面
mav.addObject("testList",cs);
mav.addObject("page",page);
mav.addObject("total",total);
mav.setViewName("test");
return mav;
}
}

@ -0,0 +1,76 @@
package com.controller;
import com.entity.Department;
import com.entity.Visitor;
import com.service.IVisitorService;
import com.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;
/**
* @ClassName VistorController
* @Description TODO
* @Author YHT
* @Date 2021/5/30 12:17
*/
@Controller
public class VistorController {
@Autowired
private IVisitorService visitorService;
/**
* 访
* @param page
* @return
*/
@RequestMapping("/toVisitor")
public ModelAndView toVisitor(Page page){
ModelAndView mv = new ModelAndView();
//得到所有访客列表信息
List<Visitor> visitorList = visitorService.listVisitor(page);
//得到记录总数
int total = visitorService.getVisitorTotal();
//得到页数
int pageIndex = total / page.getCount();
pageIndex = total % page.getCount() == 0 ? pageIndex : pageIndex+1;
page.setTotalIndex(pageIndex);
page.calculateLast(total);
//返回数据至页面
mv.addObject("visitorList",visitorList);
mv.addObject("page",page);
mv.addObject("total",total);
mv.setViewName("visitor");
return mv;
}
/**
* 访
* @param name
* @param page
* @return
*/
@RequestMapping("/searchVisitor")
public ModelAndView searchDept(String name, Page page){
ModelAndView mv = new ModelAndView();
//根据部门名称查找部门信息,并进行分页显示
List<Visitor> visitorList = visitorService.searchByName(name, page);
//得到总记录数
int total = visitorList.size();
//每页显示三条,总共显示的页数
int pageIndex = total / page.getCount();
pageIndex = total % page.getCount() == 0 ? pageIndex : pageIndex+1;
page.setTotalIndex(pageIndex);
page.calculateLast(total);
//添加信息到modelview。
mv.addObject("visitorList",visitorList);
mv.addObject("page",page);
mv.addObject("total",total);
//返回部门信息列表页面
mv.setViewName("visitor");
return mv;
}
}
Loading…
Cancel
Save