智慧社区管理系统03(用户列表增删查改)

目录

后端部分

mapper层

 mapper sql文件

Service层 

接口

Controller层

前端部分 

源码

 效果图​编辑

 


后端部分

mapper层

package com.woniu.community.mapper;

import com.woniu.community.entity.User;

import java.util.List;

public interface UserMapper {
    User selectByNameAndPwd(String username, String passwd);

    List<User> selectAll(int start, int size);

    int  selectCount();

    int insertUser(User user);

    int updateUser(User user);

    int deleteUser(int id);

    User selectUserById(int id);
}

 mapper sql文件

 <insert id="insertUser">
    insert into userinfo(username,password) values(#{username},#{password})
    </insert>
    <update id="updateUser">
        update userinfo set username=#{username},password=#{password} where id=#{id}
    </update>
    <delete id="deleteUser">
        delete from userinfo where id=#{id}
    </delete>
    <select id="selectUserById" resultMap="userResult">
        select * from userinfo where id=#{id}
    </select>

Service层 

接口

 /**
     * 添加用户
     * @param user
     * @return
     */
    HttpResult addUser(User user);

    /**
     * 删除用户,根据id
     * @param id
     * @return
     */
    HttpResult removeUser(int id);

    /**
     * 修改用户
     * @param user
     * @return
     */
    HttpResult updateUser(User user);

    /**
     * 查询用户,根据id
     * @param id
     * @return
     */
    HttpResult getUserInfo(int id);
@Override
    public HttpResult addUser(User user) {
        int count = userMapper.insertUser(user);//添加用户
        HttpResult result = null;
        if (count > 0 ) {
            result = new HttpResult(null, 0, 200, "新增成功");
        } else {
            result = new HttpResult(null, 0, 500, "新增失败");
        }
        return result;
    }

    @Override
    public HttpResult removeUser(int id) {
        int count = userMapper.deleteUser(id);//添加用户
        HttpResult result = null;
        if (count > 0 ) {
            result = new HttpResult(null, 0, 200, "删除成功");
        } else {
            result = new HttpResult(null, 0, 500, "删除失败");
        }
        return result;
    }

    @Override
    public HttpResult updateUser(User user) {
        int count = userMapper.updateUser(user);//添加用户
        HttpResult result = null;
        if (count > 0 ) {
            result = new HttpResult(null, 0, 200, "修改成功");
        } else {
            result = new HttpResult(null, 0, 500, "修改失败");
        }
        return result;
    }

    @Override
    public HttpResult getUserInfo(int id) {
        User user = userMapper.selectUserById(id);
        HttpResult result = null;
        if (user != null ) {
            result = new HttpResult(user, 0, 200, null);
        } else {
            result = new HttpResult(null, 0, 500, "没有更多数据");
        }
        return result;
    }

Controller层

@PostMapping("/add")
    public HttpResult addUser(@RequestBody UserVO vo) {
        User user = new User();
        user.setUsername(vo.getUsername());
        user.setPassword(vo.getPassword());
        return userService.addUser(user);
    }

    @RequestMapping("/remove")
    public HttpResult removeUser(int id) {
        return userService.removeUser(id);
    }
    @PostMapping("/update")
    public HttpResult updateUser(@RequestBody User user) {
        return userService.updateUser(user);

    }
    @RequestMapping("/info")
    public HttpResult getUserInfo(int id) {
        return userService.getUserInfo(id);
    }

前端部分 

源码

列表(增加和修改的跳转,删除功能)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="assets/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="assets/css/right.css" rel="stylesheet">
    <script src="assets/jquery-3.5.1.min.js"></script>
    <script src="assets/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
    <script src="assets/vue.min-v2.5.16.js"></script>
    <script src="assets/vue-router.min-2.7.0.js"></script>
    <script src="assets/axios.min.js"></script>
</head>
<body>
<div id="app" class="container">
    <div class="row">
        <div class="col-md-12" style="height: 50px; line-height: 50px;">
            <button class="btn btn-info"@click="doAdd">新增</button>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            <table class="table table-striped">
                <caption>用户列表</caption>
                <thead>
                <tr>
                    <th>ID</th>
                    <th>用户名</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr v-for="u in userList">
                    <td>{{u.id}}</td>
                    <td>{{u.username}}</td>
                    <td>
                        <button class="btn btn-link"@Click="doUpdate(u.id)">修改</button>
                        <button class="btn btn-link"@Click="doDelete(u.id)">删除</button>
                    </td>
                </tr>
                </tbody>
            </table>
            <ul class="pagination" v-for="p in pageNum">
                <li v-if="p==pageIndex" class="active"><a @click="doGo(p)">{{p}}</a></li>
                <li v-else="p==pageIndex" ><a @click="doGo(p)">{{p}}</a></li>
            </ul>
        </div>
    </div>
</div>
<script>
    new Vue({
        el: '#app',
        data: {
            userList: null,//用户列表
            //用于分页
            pageIndex: 1,//当前页数
            pageSize: 10,//每页显示的条数
            pageTotle: 0,//总条数
            pageNum: 0,//页数(分页器)
        },
        methods: {
            //请求用户列表
            requestUserList(p) {
                //通过axios发送请求获取用户列表
                axios.get("http://localhost:8080/user/list?pageIndex=" + p + "&pageSize=" + this.pageSize).then(response => {
                    console.log(response.data);
                    this.userList = response.data.data;//给用户列表赋值
                    this.pageTotle = response.data.pageTotle;//给总条数赋值
                    //计算页数,通过Math.ceil函数,小数取整,向上取整
                    this.pageNum = Math.ceil(this.pageTotle / this.pageSize);
                });
            },
            //点击分页按钮
            doGo(p){
                this.pageIndex=p;
                this.requestUserList(p);//调用请求用户列表的函数
            },
            //点击添加按钮时执行
            doAdd() {
                //页面跳转
                window.parent.main_right.location.href="user_add_update.html";
            },
            //点击修改按钮时执行
            doUpdate(id) {
                window.parent.main_right.location.href="user_add_update.html?id="+id;
            },
            //点击删除按钮时执行
            doDelete(id) {
                //通过axios发送请求
                axios.get("http://localhost:8080/user/remove?id="+id).then(response=>{
                    if (response.data.code==200){//删除成功
                        this.pageIndex=1;//返回第一页
                        this.requestUserList(this.pageIndex);//调用请求用户列表的函数
                    }else{//删除失败
                        alert(response.data.msg)
                    }
                });
            }
        },


        created: function () {
            this.requestUserList(this.pageIndex);//调用请求用户列表的函数
        }
    });
</script>
</body>
</html>

删除功能当删除成功的时候直接返回到第一页 

修改和增加功能

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="assets/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="assets/css/right.css" rel="stylesheet">
    <script src="assets/jquery-3.5.1.min.js"></script>
    <script src="assets/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
    <script src="assets/vue.min-v2.5.16.js"></script>
    <script src="assets/vue-router.min-2.7.0.js"></script>
    <script src="assets/axios.min.js"></script>
    <script src="assets/date_picker.js"></script>
</head>
<body>
<div id="app" class="container">
    <div class="row">
        <div class="col-md-8 col-md-offset-2">
            <div class="row">
                <div class="col-md-12"
                     style="text-align: center; font-weight: bold; font-size: 18px; height: 80px; line-height: 80px;">
                    {{title}}
                </div>
            </div>
            <div class="row">
                <div class="col-md-6 col-md-offset-3" style="height: 80px;">
                    <label>用户名</label>
                    <input type="text" class="form-control" v-model="userName">
                </div>
            </div>
            <div class="row">
                <div class="col-md-6 col-md-offset-3" style="height: 80px;">
                    <button class="btn btn-primary" @Click="doSave">保存</button>
                    <button class="btn btn-default" @Click="doCancel">取消</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    new Vue({
        el: '#app',
        data: {
            title: null,
            userId: null,//接受页面跳转传参
            userName: null,
            passwd: null,
        },
        methods: {
            //保存按钮
            doSave() {
                if (this.userId == null) {//添加
                    axios.post("http://localhost:8080/user/add", {
                        username: this.userName,
                        password: "12345",
                    }).then(response => {
                        if (response.data.code == 200) {//添加成功
                            //跳转到用户列表页面
                            window.parent.main_right.location.href="user_list.html";
                        } else {//添加失败
                            alert(response.data.msg);
                        }
                    });
                } else {//修改
                //通过axios发送请求,修改用户
                    axios.post("http://localhost:8080/user/update",{
                        id:this.userId,
                        username: this.userName,
                        password: this.passwd,
                    }).then(response => {
                if (response.data.code == 200) {//添加成功
                    //跳转到用户列表页面
                    window.parent.main_right.location.href="user_list.html";
                } else {//添加失败
                    alert(response.data.msg);
                }
            });
                }
            },
            //取消按钮
            doCancel() {
                //返回上一个页面
                history.go(-1);
            },
        },
        created: function () {
            //获取页面跳转传的id
            var url = window.location.href;
            if (url.indexOf("id") != -1) {//是否传递了id
                this.userId = url.substring(url.indexOf("=") + 1);
            }
            console.log(this.userId);
            if (this.userId == null) {//添加
                this.title = "添加用户";
            } else {//修改
                this.title = "修改用户";
                //发送请求获取用户信息,回显数据
                axios.get("http://localhost:8080/user/info?id="+this.userId).then(response=>{
                    this.userName=response.data.data.username;
                    this.passwd=response.data.data.password;
                });
            }
        }
    });
</script>
</body>
</html>

先判断我们是点击的新增还是修改,之后当我们新增和修改取消的时候,我们直接返回上一级 

 效果图

 

 

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 基于Java智慧社区管理系统是一种通过使用Java编程语言进行开发的系统,旨在提高小区物业管理的效率和便捷性。该系统主要包括以下功能和特点: 1. 住户信息管理:系统可以管理小区内的住户信息,包括业主姓名、电话号码、车辆信息等。通过该功能,物业管理人员可以轻松地获取住户信息,方便与住户进行沟通和联系。 2. 缴费管理:系统可以管理小区住户的各种费用缴纳情况,如物业费、水费、电费等。住户可以通过系统在线缴费,系统可以实时更新缴费记录,方便管理人员进行查看和统计。 3. 报修管理:住户可以通过系统提交报修请求,并且可以上传相关图片或文字描述。物业管理人员可以及时获取报修信息,分配维修人员进行处理,提高报修的处理效率。 4. 访客登记管理:系统可以记录和管理小区内的访客信息,包括来访人员姓名、来访事由、来访时间等。住户可以通过系统进行访客登记,管理人员可以随时查询访客信息,保障小区的安全管理。 5. 社区活动管理:系统可以发布小区内的活动公告和信息,住户可以通过系统报名参加活动。通过系统的管理,物业管理人员可以方便地组织和安排社区活动,提高小区居民之间的互动和交流。 基于Java智慧社区管理系统采用模块化设计,具有良好的扩展性和可维护性。该系统能够提高物业管理人员的工作效率,提供便捷的服务给住户,使小区管理更加智慧化和高效化。 ### 回答2: 基于Java智慧社区管理系统是一种专门为小区物业管理而设计开发的软件系统。这个系统的目的是为小区提供高效、便捷、智能的物业管理服务。 首先,该系统在小区居民入住管理方面具备强大的功能。它可以将小区居民的入住信息进行登记和管理,包括住户信息、合同信息、缴费情况等。居民入住后可以通过系统进行业主认证,享受到系统提供的各种服务,例如在线缴费、报修等。 其次,该系统提供了全面的物业管理功能。物业管理人员可以通过系统实时掌握小区各种设施设备的运行情况,并进行维修保养。同时,系统还提供了安全巡查、小区保洁等相关功能。居民可以通过系统提交报修工单,物业人员也可以及时处理并跟进这些工单。 此外,该系统还提供了一些便捷的居民服务功能。例如,居民可以通过系统进行在线缴费,包括物业费、水费、电费等。居民还可以通过系统进行报事报修,系统会将报修信息及时发送给物业管理团队。另外,系统还提供了小区公告、活动推送等功能,居民可以随时了解小区的最新动态。 综上所述,基于Java智慧社区管理系统是一种可靠、高效的小区物业管理系统。它提供了全面的管理、服务功能,能够大大提升小区物业管理的效率和质量,为居民提供更好的居住体验。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值