关于写SpringBoot+Mybatisplus+Shiro项目的经验分享一:简单介绍

这次我尝试写一个原创的项目 the_game

  框架选择: SpringBoot+Mybatisplus+Shiro

首先是简单的介绍(素材灵感来自英雄联盟)

5个关键的表:

  admin(管理员):

  

  lol(英雄):

   lol_forces(势力):

   lol_occupation(职业):

   lol_routes(分路):

其中英雄表中的 force_id 为int类型,必须通过查找 lol_forces 才能得到具体势力名

occupation_one、occupation_two 为int类型,必须通过查找 lol_occupation 才能得到具体职业名

route_one、route_two 为int类型,必须通过查找 lol_routes 才能得到具体分路名

Gender(性别):使用枚举的方式

因为使用了MybatisPlus,所以减轻了很多写Sql的负担,并且增加了 逻辑删除, 主键策略, 枚举等工具

实体类(都使用了Lombok):

LoL 

package com.zy.entity.lol;

import com.baomidou.mybatisplus.annotation.*;
import com.zy.enums.GenderEnum;
import lombok.Data;

import java.util.Date;

@Data
@TableName(value = "lol")
/**
 * 英雄联盟实体类
 */
public class Lol {

    //英雄编号,主键
    //采用手动赋值方式
    @TableId(type = IdType.INPUT)
    private Integer hId;

    //英雄称号
    @TableField(value = "designation")
    private String designation;

    //英雄名
    @TableField(value = "hero_name")
    private String heroName;

    //性别,采用枚举的方式
    @TableField(value = "gender")
    //private Integer gender;
    private GenderEnum gender;

    //势力编号,可以查询forces表得到
    @TableField(value = "force_id")
    private Integer forceId;

    //主要职业编号,可以查询forces表得到
    @TableField(value = "occupation_one")
    private Integer occupationOne;

    //次要职业编号,可以查询forces表得到
    @TableField(value = "occupation_two")
    private Integer occupationTwo;

    //推荐分路一,可以查询routes表得到
    @TableField(value = "route_one")
    private Integer routeOne;

    //推荐分路二,可以查询routes表得到
    @TableField(value = "route_two")
    private Integer routeTwo;

    //逻辑删除
    @TableLogic
    private Integer deleted;

    //创建时间
    @TableField(value = "create_time",fill = FieldFill.INSERT)
    private Date createTime;

    //更新时间
    @TableField(value = "update_time",fill = FieldFill.INSERT_UPDATE)
    private Date updateTime;

}
lolForces:
@Data
@TableName(value = "lol_forces")
/**
 * lol的势力实体类
 */
public class LolForces {

    //势力编号,主键
    //采用手动赋值方式
    @TableId(type = IdType.INPUT)
    private Integer fId;

    //势力名
    @TableField(value = "f_name")
    private String fName;

}

LolOccupation:
@Data
@TableName(value = "lol_occupation")
/**
 * lol的职业实体类
 */
public class LolOccupation {

    //职业编号,主键
    //采用默认方式
    @TableId
    private Integer hcId;

    //职业名(英文)
    @TableField(value = "name_us")
    private String nameUs;

    //职业名(中文)
    @TableField(value = "name_cn")
    private String nameCn;

}

LolRoutes:
@Data
@TableName(value = "lol_routes")
/**
 * lol的分路实体类
 */
public class LolRoutes {

    //分路编号,主键
    //采用手动赋值方式
    @TableId(type = IdType.INPUT)
    private Integer rId;

    //分路名
    @TableField(value = "route")
    private String route;
}

GenderEnum枚举
package com.zy.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;

public enum GenderEnum {
    男(0,"男"),
    女(1,"女");

    GenderEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    @EnumValue
    private Integer code;
    private String msg;

}

还需要注意的是,因为前端显示数据时,像是势力、职业这种属性,不能用数字,而需要名字

因此我的增加了VO(value object)用于传输,其封装的属性都是前端页面需要的

LolVo

@Data
/**
 * 传输的实体类
 */
public class LolVo {

    //英雄编号
    private Integer hId;
    //英雄称号
    private String designation;
    //英雄名
    private String heroName;
    //性别
    private GenderEnum gender;
    //势力名
    private String force;
    //职业名(主)
    private String occupationOne;
    //职业名(次)
    private String occupationTwo;
    //推荐分路名一
    private String routeOne;
    //推荐分路名二
    private String routeTwo;

}

管理lol表 是此项目的核心,其中admin(管理员)拥有CRUD的权限,而未登录的游客只可以进行查找

 在呈现数据时,采用分页的方式,并且页面通过session判断是否登录,从而呈现不同的按钮, 比如增删改的按钮游客不可见

 

效果初览(游客视角):

  

原文地址:https://www.cnblogs.com/kzyuan/p/13083795.html