關於寫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判斷是否登錄,從而呈現不同的按鈕, 比如增刪改的按鈕游客不可見

 

效果初覽(游客視角):

 

 

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM