SSM 管理员删除功能

mapper层:AdminMapper

public interface AdminMapper {
    //根据id删除
    int remove(Integer id);
}

mapper层:AdminMapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.lyc.mapper.AdminMapper">
    <resultMap id="BaseResultMap" type="com.lyc.pojo.Admin">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="login_acct" jdbcType="VARCHAR" property="login_acct"/>
        <result column="user_pswd" jdbcType="CHAR" property="user_pswd"/>
        <result column="user_name" jdbcType="VARCHAR" property="user_name"/>
        <result column="email" jdbcType="VARCHAR" property="email"/>
        <result column="create_time" jdbcType="CHAR" property="create_time"/>
    </resultMap>
    <delete id="remove" parameterType="java.lang.Integer">
        delete
        from t_admin
        where id = #{id,jdbcType=INTEGER}
    </delete>
</mapper>

service层:AdminService

package com.lyc.service;

import com.github.pagehelper.PageInfo;
import com.lyc.pojo.Admin;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

public interface AdminService {
    int remove(Integer id);
}

service层:AdminServiceImpl

package com.lyc.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lyc.mapper.AdminMapper;
import com.lyc.pojo.Admin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.support.PagedListHolder;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
@Service("adminService")
public
class AdminServiceImpl implements AdminService{
    @Autowired
    private AdminMapper adminMapper;

    public void setAdminMapper(AdminMapper adminMapper) {
        this.adminMapper = adminMapper;
    }

    @Override
    public int remove(Integer id) {
        return adminMapper.remove(id);
    }
}

controller层:AdminController

@Controller
public class AdminController {
    @Autowired
    private AdminService adminService;
    
    /**
     * 删除功能
     * @param id 要删除的用户ID
     * @return 返回用户查询页面
     */
  @RequestMapping("/admin/remove/{id}/{pageNum}/{keyword}.html")
    public String remove(
            @PathVariable("id") Integer id,
            @PathVariable("pageNum") Integer pageNum,
            @PathVariable("keyword") String keyword
            ) {
        // 执行删除
        adminService.remove(id);
        // 页面跳转回到分页页面
        return "redirect:/admin/get/page.html?pageNum="+pageNum+"&keyword="+keyword;
    }

}

jsp层:admin-page.jsp

<a href="admin/remove/${admin.id}/${requestScope.pageInfo.pageNum}/${param.keyword}.html" class="btn btn-danger btn-xs">
                                                <i class=" glyphicon glyphicon-remove"></i></a>

posted on 2021-05-20 11:20  liuyunche  阅读(264)  评论(0编辑  收藏  举报