web第十二次

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);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值