IDEA+springboot+jpa+Layui+Mysql销售考评系统源码

  • 一、系统介绍
  • 1.环境配置
  • 二、系统展示
  • 1. 管理员登录
  • 2.评分结果
  • 3.评分管理
  • 4.添加评分
  • 5.用户管理
  • 6.添加用户
  • 7.角色管理
  • 8.添加角色
  • 8.销售管理
  • 9.添加销售
  • 三、部分代码
  • UserDao.java
  • UserController.java
  • User.java
  • 四、其他
  • 获取源码



一、系统介绍

本系统实现了销售考评系统源码,管理端实现了管理员登录、评分结果、评分管理、添加评分、用户管理、添加用户、角色管理、添加角色、销售管理、添加销售

1.环境配置

JDK版本:1.8
Mysql:5.7

二、系统展示

1. 管理员登录

IDEA+springboot+jpa+Layui+Mysql销售考评系统源码_intellij-idea

账号:admin 密码:123

2.评分结果

IDEA+springboot+jpa+Layui+Mysql销售考评系统源码_layui_02

3.评分管理

IDEA+springboot+jpa+Layui+Mysql销售考评系统源码_User_03

4.添加评分

IDEA+springboot+jpa+Layui+Mysql销售考评系统源码_User_04

5.用户管理

IDEA+springboot+jpa+Layui+Mysql销售考评系统源码_spring boot_05

6.添加用户

IDEA+springboot+jpa+Layui+Mysql销售考评系统源码_spring_06

7.角色管理

IDEA+springboot+jpa+Layui+Mysql销售考评系统源码_intellij-idea_07

8.添加角色

IDEA+springboot+jpa+Layui+Mysql销售考评系统源码_spring_08

8.销售管理

IDEA+springboot+jpa+Layui+Mysql销售考评系统源码_spring_09

9.添加销售

IDEA+springboot+jpa+Layui+Mysql销售考评系统源码_spring boot_10

三、部分代码

UserDao.java

import cn.temptation.domain.Score;
import cn.temptation.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

public interface UserDao extends JpaRepository<User, Integer>, JpaSpecificationExecutor<User> {
    @Query(value = "SELECT * FROM t_user WHERE username = ?1", nativeQuery = true)
    User findByUserName(String username);
}

UserController.java

import cn.temptation.dao.RoleDao;
import cn.temptation.dao.UserDao;
import cn.temptation.domain.Role;
import cn.temptation.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.persistence.criteria.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class UserController {
    @Autowired
    private UserDao userDao;
    @Autowired
    private RoleDao roleDao;

    @RequestMapping("/user")
    public String index() {
        return "user";
    }

    @RequestMapping("/user_list")
    @ResponseBody
    public Map<String, Object> userList(@RequestParam Map<String, Object> queryParams) {
        Map<String, Object> result = new HashMap<>();

        try {
            Integer page = Integer.parseInt(queryParams.get("page").toString());
            Integer limit = Integer.parseInt(queryParams.get("limit").toString());
            String condition = (String) queryParams.get("condition");
            String keyword = (String) queryParams.get("keyword");

            // 创建查询规格对象
            Specification<User> specification = (Root<User> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> {
                Predicate predicate = null;
                Path path = null;

                if (condition != null && !"".equals(condition) && keyword != null && !"".equals(keyword)) {
                    switch (condition) {
                        case "username":    // 用户名称
                            path = root.get("username");
                            predicate = cb.like(path, "%" + keyword + "%");
                            break;
                        case "rolename":    // 角色名称
                            path = root.join("role", JoinType.INNER);
                            predicate = cb.like(path.get("rolename"), "%" + keyword + "%");
                            break;
                    }
                }

                return predicate;
            };

            Pageable pageable = PageRequest.of(page - 1, limit, Sort.Direction.ASC, "userid");

            Page<User> users = userDao.findAll(specification, pageable);

            result.put("code", 0);
            result.put("msg", "查询OK");
            result.put("count", users.getTotalElements());
            result.put("data", users.getContent());
        } catch (Exception e) {
            e.printStackTrace();
            result.put("code", 500);
            result.put("msg", "服务器内部错误");
            result.put("count", 0);
            result.put("data", new ArrayList());
        }

        return result;
    }

    @RequestMapping("/user_delete")
    @ResponseBody
    public Integer userDelete(@RequestParam String userid) {
        try {
            userDao.deleteById(Integer.parseInt(userid));
            return 0;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return -1;
    }

    @RequestMapping("/user_view")
    public String view(Integer userid, Model model) {
        User user = new User();
        if (userid != null) {
            user = userDao.getOne(userid);
        }
        model.addAttribute("user", user);
        return "user_view";
    }

    @RequestMapping("/role_load")
    @ResponseBody
    public List<Role> roleList() {
        return roleDao.findAll();
    }

    @RequestMapping("/user_update")
    @ResponseBody
    public Integer userUpdate(User user) {
        try {
            userDao.save(user);
            return 0;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return -1;
    }
}

User.java

import lombok.Data;

import javax.persistence.*;
import java.util.List;

@Data
@Entity
@Table(name = "t_user")
public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "userid")
    private Integer userid;
    @Column(name = "username")
    private String username;
    @Column(name = "password")
    private String password;
    @ManyToOne(cascade = {CascadeType.MERGE, CascadeType.REFRESH}, optional = false)
    @JoinColumn(name = "roleid", foreignKey = @ForeignKey(name = "none"))
    private Role role;
    @Transient // 忽略不生成该注解的字段
    private List<MenuOne> menuOnes;
}