SpringBoot+mybatisPlus+Vue to build the front desk system of student record

SpringBoot+mybatisPlus+Vue to build the front desk system of student record

Front and rear end separation interaction:

Back end development:

Use IDEA+SQLyog+Maven

Version introduction:

IDEA:2020.0

sqlyog:V12.14

Maven:3.8.2

MySql:8.0.2

springBoot:2.5.7

mabatisPlus:3.0.5

Content introduction:

Inspired by my classmates, I found that this is a good hand training project. By compiling a web page similar to the community to visualize some classmate record information (using a private warehouse), record some events in the past years, record some things that were interesting and worth sharing through public discussion, and state the things that were regrettable in the past. After a series of research and analysis, this project is indeed feasible. Don't talk much, open the whole!

(the demand analysis here is not clear and cannot be developed through waterfall model)

Development process:

1. Establish a general springBoot project (NewsSchool)
2. Establish a sub module (services) in it

Add dependencies and directly use parent project management

<java.version>1.8</java.version>
<mybatis-plus.version>3.0.5</mybatis-plus.version>
<velocity.version>2.0</velocity.version>
<swagger.version>2.7.0</swagger.version>
<httpclient.version>4.5.1</httpclient.version>
<json.version>20170516</json.version>
<dependencyManagement>
    <!--mybatis-plus Persistent layer-->
    <dependency>
    	<groupId>com.baomidou</groupId>
        <artifactId>mybatis-plus-boot-starter</artifactId>
        <version>${mybatis-plus.version}</version>
    </dependency>

    <!-- velocity template engine, Mybatis Plus Code generator needs -->
    <dependency>
		<groupId>org.apache.velocity</groupId>
        <artifactId>velocity-engine-core</artifactId>
        <version>${velocity.version}</version>
    </dependency>

    <!--swagger-->
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>${swagger.version}</version>
    </dependency>
    <!--swagger ui-->
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>${swagger.version}</version>
    </dependency>
    <!--httpclient-->
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>${httpclient.version}</version>
    </dependency>
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>${json.version}</version>
    </dependency>      
</dependencyManagement>

Note: if microservice development is used, the traffic may not be so large, so the centralized advantage is even greater at this time. If you want to add it later, you need to shut down and update it once. Please refer to Phoenix architecture for specific architecture ideas

Configuration import of services

	<dependencies>
		<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!--mybatis-plus-->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
        </dependency>

        <!--mysql-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>

        <!-- velocity template engine, Mybatis Plus Code generator needs -->
        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity-engine-core</artifactId>
        </dependency>

        <!--swagger-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
        </dependency>

        <!--lombok Used to simplify entity classes: need to install lombok plug-in unit-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
		<!--httpclient-->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
        </dependency>
		<dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
    </dependencies>
3. Establish a local database (there is no system design, but now it's just practice)
DROP TABLE `rem_student`; 
CREATE TABLE `rem_student` ( 
     `id` CHAR(19) NOT NULL COMMENT 'student ID', `name` VARCHAR(20) NOT NULL COMMENT 'Student name',
     `sex` VARCHAR(10) NOT NULL COMMENT 'Student gender', `telephone` VARCHAR(11) NOT NULL COMMENT 'Student telephone', 
     `q_email` VARCHAR(10) NOT NULL COMMENT 'qq', `intro` VARCHAR(500) NOT NULL DEFAULT '' COMMENT 'Student personality signature', 
     `gmt_brithday` DATETIME COMMENT 'Student birthday', 
     `level` INT(10) UNSIGNED NOT NULL COMMENT 'Account grade', `avatar` VARCHAR(255) DEFAULT NULL COMMENT 'Student Avatar', 
     `is_deleted` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Logical deletion 1( true)Deleted, 0( false)Not deleted', 
     `gmt_create` DATETIME NOT NULL COMMENT 'Creation time', `
     gmt_modified` DATETIME NOT NULL COMMENT 'Update time', 
     PRIMARY KEY (`id`),
     UNIQUE KEY `uk_name` (`name`) ) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COMMENT='Use students';
DROP TABLE `rem_user`; 
CREATE TABLE `rem_user` ( 
    `token` CHAR(19) NOT NULL COMMENT 'User ID', 
    `username` CHAR(19) NOT NULL COMMENT 'account number', 
    `password` CHAR(19) NOT NULL COMMENT 'password',
    PRIMARY KEY (`token`), 
    UNIQUE KEY `uk_name` (`username`) ) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COMMENT='User'; 
4. Configure application yml
server:
  port: 8101
spring:
  # service name
  application:
    name: student_rem

  # Environment settings: dev, test, prod
  profiles:
    active: dev
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url:  jdbc:mysql://localhost:3306/memoirs?characterEncoding=utf8&useSSL=true&serverTimezone=UTC&allowPublicKeyRetrieval=true
    username: root
    password: "030428"
  #Returns the global time format of json
  jackson:
    date-format: yyyy-MM-dd HH:mm:ss
    time-zone: UTC

  #mybatis log
mybatis-plus:
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
5. Use automatic code generator to quickly generate structure
public class CodeGenerator {
    @Test
    public void run() {

        // 1. Create code generator
        AutoGenerator mpg = new AutoGenerator();

        // 2. Global configuration
        GlobalConfig gc = new GlobalConfig();
        String projectPath = System.getProperty("user.dir");
        gc.setOutputDir("E:\\CSDN\\XinJianYiZhon\\NewsSchool\\services" + "/src/main/java");

        gc.setAuthor("testjava");
        gc.setOpen(false); //Open Explorer after build
        gc.setFileOverride(false); //Whether the file is overwritten during regeneration

        //UserServie
        gc.setServiceName("%sService");    //Remove the initial I of the Service interface

        gc.setIdType(IdType.ID_WORKER_STR); //Primary key policy
        gc.setDateType(DateType.ONLY_DATE);//Defines the date type in the generated entity class
        gc.setSwagger2(true);//Turn on Swagger2 mode

        mpg.setGlobalConfig(gc);

        // 3. Data source configuration
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setUrl("jdbc:mysql://localhost:3306/memoirs?characterEncoding=utf8&useSSL=true&serverTimezone=UTC&allowPublicKeyRetrieval=true");
        dsc.setDriverName("com.mysql.cj.jdbc.Driver");
        dsc.setUsername("root");
        dsc.setPassword("030428");
        dsc.setDbType(DbType.MYSQL);
        mpg.setDataSource(dsc);

        // 4. Package configuration
        PackageConfig pc = new PackageConfig();
        pc.setModuleName("zushiye"); //Module name
        //Package com atguigu. eduservice
        pc.setParent("com");
        //Package com atguigu. eduservice. controller
        pc.setController("controller");
        pc.setEntity("pojo");
        pc.setService("service");
        pc.setMapper("mapper");
        mpg.setPackageInfo(pc);

        // 5. Policy configuration
        StrategyConfig strategy = new StrategyConfig();

        strategy.setInclude("rem_user");

        strategy.setNaming(NamingStrategy.underline_to_camel);//Naming strategy for mapping database tables to entities
        strategy.setTablePrefix(pc.getModuleName() + "_"); //Remove the table prefix when generating entities

        strategy.setColumnNaming(NamingStrategy.underline_to_camel);//Naming policy for mapping database table fields to entities
        strategy.setEntityLombokModel(true); // lombok model @ accessories (chain = true) setter chain operation

        strategy.setRestControllerStyle(true); //restful api style controller
        strategy.setControllerMappingHyphenStyle(true); //Hump to hyphen in url

        mpg.setStrategy(strategy);


        // 6. Execute
        mpg.execute();
    }
}
6. Configure config
@Configuration
@MapperScan("com.zushiye.mapper")
@ComponentScan(basePackages = {"com.zushiye"})
public class StudentConfig {
    /**
     * Logical deletion plug-in
     */
    @Bean
    public ISqlInjector sqlInjector() {
        return new LogicSqlInjector();
    }

    /**
     * Paging plug-in
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }


}
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("gmtCreate",new Date(),metaObject);
        this.setFieldValByName("gmtModified",new Date(),metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("gmtModified",new Date(),metaObject);
    }
}
7. Configure swagger tool
@Configuration
@EnableSwagger2
public class SwapperConfig {

    @Bean
    public Docket webApiConfig(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("webApi")
                .apiInfo(webApiInfo())
                .select()
                .paths(Predicates.not(PathSelectors.regex("/admin/.*")))
                .paths(Predicates.not(PathSelectors.regex("/error.*")))
                .build();

    }

    private ApiInfo webApiInfo(){

        return new ApiInfoBuilder()
                .title("memoir")
                .description("This document describes the definition of memoir interface")
                .version("1.0")
                .build();
    }
}

Configure the return data of response and use chain development

@Data
public class R {
    @ApiModelProperty(value = "Is it successful")
    private Boolean success;

    @ApiModelProperty(value = "Return code")
    private Integer code;

    @ApiModelProperty(value = "Return message")
    private String message;

    @ApiModelProperty(value = "Return data")
    private Map<String, Object> data = new HashMap<String, Object>();

    private R (){
    }

    //Successful static method
    public static R ok() {
        R r = new R();
        r.setSuccess(true);
        r.setCode(ResultCode.SUCCESS);
        r.setMessage("success");
        return r;
    }

    //Static method failed
    public static R error() {
        R r = new R();
        r.setSuccess(false);
        r.setCode(ResultCode.ERROR);
        r.setMessage("fail");
        return r;
    }

    public R success(Boolean success){
        this.setSuccess(success);
        return this;
    }

    public R message(String message){
        this.setMessage(message);
        return this;
    }

    public R code(Integer code){
        this.setCode(code);
        return this;
    }

    public R data(String key, Object value){
        this.data.put(key, value);
        return this;
    }

    public R data(Map<String, Object> map){
        this.setData(map);
        return this;
    }
}

public class ResultCode {
    public static Integer SUCCESS = 20000; //success

    public static Integer ERROR = 20001; //fail
}

Note: please refer to the configuration file of Silicon Valley for details here

Show development structure:

At this point, the backend configuration ends

Look forward to the next front-end construction and subsequent development!

Simply show the front page!

My beauty is not much, please give me more advice!

I hope you will give me a series of development suggestions

Keywords: Java Spring Boot Vue.js

Added by dbdbdb on Fri, 25 Feb 2022 13:08:23 +0200