后台用户管理的源码来啦

效果图

后台用户管理的源码来啦_第1张图片

后台用户管理的源码来啦_第2张图片 

前端代码【User.vue】





后端代码【java】

实体类

package jkw.pojo;

import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;

import java.io.Serializable;

/**
 * 用户
 */
@Data
public class User implements Serializable {
    @TableId
    private Integer userId;

    private String userImg; // 头像
    private String nickname; // 昵称

    private String username; // 账号
    private String password; // 密码
    private String phone; // 手机号

    private String email;//邮箱
    private String userSex; // 性别
    private String signature;//个性签名
    private String userIntroduce;//自我介绍

    private String userStatus; // 用户状态(1激活 0未激活)

}

mapper

package jkw.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import jkw.pojo.User;

public interface UserMapper extends BaseMapper {
}

service

package jkw.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jkw.pojo.User;

public interface UserService {
    void add(User user);
    void update(User user);
    void delete(Integer id);
    User findById(Integer id);
    Page search(int page,int size);
    void updateStatus(Integer id);
}

serviceImpl

package jkw.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jkw.mapper.UserMapper;
import jkw.pojo.User;
import jkw.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public void add(User user) {
        userMapper.insert(user);
    }

    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }

    @Override
    public void delete(Integer id) {
        userMapper.deleteById(id);
    }

    @Override
    public User findById(Integer id) {
        return userMapper.selectById(id);
    }

    @Override
    public Page search(int page, int size) {
        return userMapper.selectPage(new Page<>(page, size), null);
    }

    @Override
    public void updateStatus(Integer id) {
        User user = userMapper.selectById(id);
        if(user.getUserStatus().equals("1")){
            user.setUserStatus("0");
            userMapper.updateById(user);
        }else {
            user.setUserStatus("1");
            userMapper.updateById(user);
        }
    }
}

controller

package jkw.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jkw.pojo.User;
import jkw.service.UserService;
import jkw.vo.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RequestMapping("/user")
@RestController
public class UserCon {
    @Autowired
    private UserService userService;

    /**
     * 新增
     *
     * @param user
     * @return
     */
    @PostMapping("/add")
    //@PreAuthorize("hasAnyAuthority('/user')")
    public BaseResult add(User user) {
        userService.add(user);
        return BaseResult.ok();
    }

    /**
     * 修改
     *
     * @param user
     * @return
     */
    @PostMapping("/update")
    public BaseResult update(User user) {
        userService.update(user);
        return BaseResult.ok();
    }

    /**
     * 删除
     *
     * @param userId
     * @return
     */
    @DeleteMapping("/delete")
    public BaseResult delete(Integer userId) {
        userService.delete(userId);
        return BaseResult.ok();
    }

    /**
     * 根据id查询
     *
     * @param userId
     * @return
     */
    @GetMapping("/findById")
    public BaseResult findById(Integer userId) {
        User user = userService.findById(userId);
        return BaseResult.ok(user);
    }

    /**
     * 分页查询
     *
     * @param page
     * @param size
     * @return
     */

    @GetMapping("/search")
    //@PreAuthorize("hasAnyAuthority('/user')")
    public BaseResult search(int page, int size) {
        Page brandPage = userService.search(page, size);
        return BaseResult.ok(brandPage);
    }

    /**
     * 修改状态
     * @param userId
     * @return
     */
    @PostMapping("/updateStatus")
    public BaseResult updateStatus(Integer userId) {
        userService.updateStatus(userId);
        return BaseResult.ok();
    }
}

你可能感兴趣的:(vue.js,javascript,elementui)