1、Servlet执行原理
1、浏览器根据请求的地址(ip/协议/端口)建立与服务器的连接
2、浏览器将请求数据打包
3、容器将请求解析,封装成俩个对象
请求-HttpServletRequest – 封装的请求数据
响应-HttpServletResponse – 返回给服务器
4、容器根据具体的请求地址—找到对应的servlet创建对象
5、容器将请求和响应作为参数传递,调用对应的请求方法
6、数据写入到输出流
7、容器将响应对象打包发给浏览器
8、浏览器读取到响应的数据,渲染页面
继续完成前面的
Cntroller层
@Slf4j
@RestController
@RequestMapping("/stus")
public class ManageController {
@Autowired
private ManageService manageService;
@GetMapping
public Result page(@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer pageSize,
String name, Short gender
){
log.info("分页查询, 参数: {},{},{},{},{},{}",page,pageSize,name,gender);
//调用service分页查询
PageBean pageBean = manageService.page(page,pageSize,name,gender);
return Result.success(pageBean);
}
@DeleteMapping("/{ids}")
public Result delete(@PathVariable List<Integer> ids){
log.info("批量删除操作, ids:{}",ids);
manageService.delete(ids);
return Result.success();
}
@PostMapping
public Result save(@RequestBody Manage manage){
log.info("新增, emp: {}",manage);
manageService.save(manage);
return Result.success();
}
@GetMapping("/{id}")
public Result getById(@PathVariable Integer id){
log.info("根据ID查询信息, id: {}",id);
Manage manage = manageService.getById(id);
return Result.success(manage);
}
@PutMapping
public Result update(@RequestBody Manage manage){
log.info("更新信息 : {}", manage);
manageService.update(manage);
return Result.success();
}
}
Mapper层
@Mapper
public interface ManageMapper {
/**
* 查询总记录数
* @return
*/
//@Select("select count(*) from checkin")
//public Long count();
/**
* 分页查询,获取列表数据
* @param start
* @param pageSize
* @return
*/
//@Select("select * from emp limit #{start},#{pageSize}")
//public List<Emp> page(Integer start, Integer pageSize);
/**
* 员工信息查询
* @return
*/
//@Select("select * from checkin")
public List<Manage> list(String name, Short gender);
/**
* 批量删除
* @param ids
*/
void delete(List<Integer> ids);
/**
* 新增员工
* @param manage
*/
@Insert("insert into manage(number, name, gender, password,phone,scope) " +
" values(#{number},#{name},#{gender},#{password},#{phone},#{scope})")
void insert(Manage manage);
/**
* 根据ID查询员工
* @param id
* @return
*/
@Select("select * from manage where id = #{id}")
Manage getById(Integer id);
/**
* 更新员工
* @param manage
*/
void update(Manage manage);
@Select("select * from manage where name=#{name} and password=#{password}")
Manage getByUsernameAndPassword(Manage manage);
}
@Service
public class ManageServiceImpl implements ManageService {
@Autowired
private ManageMapper manageMapper;
/*@Override
public PageBean page(Integer page, Integer pageSize) {
//1. 获取总记录数
Long count = empMapper.count();
//2. 获取分页查询结果列表
Integer start = (page - 1) * pageSize;
List<Emp> empList = empMapper.page(start, pageSize);
//3. 封装PageBean对象
PageBean pageBean = new PageBean(count, empList);
return pageBean;
}*/
Service层
@Override
public PageBean page(Integer page, Integer pageSize, String name, Short gender) {
//1. 设置分页参数
PageHelper.startPage(page,pageSize);
//2. 执行查询
List<Manage> manageList = manageMapper.list(name, gender);
Page<Manage> p = (Page<Manage>) manageList;
//3. 封装PageBean对象
PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
return pageBean;
}
@Override
public void delete(List<Integer> ids) {
manageMapper.delete(ids);
}
@Override
public void save(Manage manage) {
manageMapper.insert(manage);
}
@Override
public Manage getById(Integer id) {
return manageMapper.getById(id);
}
@Override
public void update(Manage manage) {
manageMapper.update(manage);
}
@Override
public Manage login(Manage manage){
return manageMapper.getByUsernameAndPassword(manage);
}
}
public interface ManageService {
/**
* 分页查询
* @param page
* @param pageSize
* @return
*/
PageBean page(Integer page, Integer pageSize, String name, Short gender);
/**
* 批量删除
* @param ids
*/
void delete(List<Integer> ids);
/**
* 新增员工
* @param manage
*/
void save(Manage manage);
/**
* 根据ID查询员工
* @param id
* @return
*/
Manage getById(Integer id);
/**
* 更新员工
* @param manage
*/
void update(Manage manage);
Manage login(Manage manage);
}