• springboot


    SpringBoot是由Privota团队提供的全新框架,其设计目的是用来简化Spring应用的初始搭建及开发过程
    sping程序缺点

    • 配置繁琐
    • 依赖设置繁琐

    Springboot程序优点

    • 自动配置
    • 起步依赖(简化依赖配置)
    • 辅助功能(内置服务器)

    starter

    • springboot中常见项目名称,定义了当前项目使用的所有项目坐标,以达到减少依赖配置的目的

    parent

    • 所有SpringBoot项目要继承的项目,定义了若干个坐标版本号(依赖管理,而非依赖),以达到减少依赖冲突的目的

    实际开发

    • 使用任意坐标时,仅书写GAV中的G和A,v由SpringBoot提供
    • 如果发送坐标错误,在指定version(要小心版本冲突)
    yaml

    YAML(YAML Ain’t Markup Language) 一种数据序列化格式

    • 优点:
      容易阅读
      容易与脚本语言交互
      以数据为核心,重数据轻格式
    • YAML文件扩展名
      主流 .yml
      .yaml
      语法规则
      大小写铭感
      属性层级关系使用多行描述,每行结尾使用冒号结束
      使用缩进表示层级关系,同层级左侧对齐,只允许使用空格
      属性值前面添加空格(属性名与属性之间使用冒号+空格作为分隔)

    yaml读取数据

    lesson: SpringBoot
    
    server:
      port: 80
    
    enterprise:
      name: itcast
      age: 16
      tel: 187909090
      subject:
        - java
        - spring
        - mvc
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    package com.shanks.controller;
    
    import com.shanks.domain.Enterprise;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.core.env.Environment;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    import java.sql.SQLOutput;
    
    @RestController
    @RequestMapping("/books")
    public class BookController {
        @Value("${lesson}")
        private String lesson;
    
        @Value("${server.port}")
        private Integer port;
    
        @Value("${enterprise.subject[0]}")
        private String subject_00;
    
        @Autowired
        private Environment environment;
    
        @Autowired
        private Enterprise enterprise;
    
    
    
    
        @GetMapping("/{id}")
        public String getById(@PathVariable Integer id){
    
            System.out.println(lesson);
            System.out.println(port);
            System.out.println(subject_00);
            System.out.println("--=-=-=-===============-=-=-=-");
            System.out.println(environment.getProperty("lesson"));
            System.out.println(environment.getProperty("server.port"));
            System.out.println(environment.getProperty("enterprise.age"));
            System.out.println(environment.getProperty("enterprise.subject[1]"));
            System.out.println("----------------");
            System.out.println(enterprise);
            return "hello springboot! ";
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    package com.shanks.domain;
    
    import org.springframework.boot.context.properties.ConfigurationProperties;
    import org.springframework.stereotype.Component;
    
    import java.util.Arrays;
    @Component
    @ConfigurationProperties(prefix = "enterprise")
    public class Enterprise {
        private String name;
        private Integer age;
        private String tel;
        private String[] subject;
    
        @Override
        public String toString() {
            return "Enterprise{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    ", tel='" + tel + '\'' +
                    ", subject=" + Arrays.toString(subject) +
                    '}';
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public Integer getAge() {
            return age;
        }
    
        public void setAge(Integer age) {
            this.age = age;
        }
    
        public String getTel() {
            return tel;
        }
    
        public void setTel(String tel) {
            this.tel = tel;
        }
    
        public String[] getSubject() {
            return subject;
        }
    
        public void setSubject(String[] subject) {
            this.subject = subject;
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57

    解决

    自定义对象封装数据警告
    加上依赖

    <dependency>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-configuration-processorartifactId>
                <optional>trueoptional>
            dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5

    mybatisplus

    • 无侵入:只做增强不做改变,不会对现有工程产生影响
    • 强大的CURD操作:内置通用Mapper,少配置即可实现单表的CURD
    • 支持lambda: 编写查询条件无需担心字段写错
    • 支持主键自动生成
    • 内置分页插件
      在这里插入图片描述
      在这里插入图片描述
      在这里插入图片描述
      在这里插入图片描述
      在这里插入图片描述
      在这里插入图片描述
      在这里插入图片描述
      在这里插入图片描述

    代码生成器

    package com.shanks;
    
    import com.baomidou.mybatisplus.annotation.IdType;
    import com.baomidou.mybatisplus.generator.AutoGenerator;
    import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
    import com.baomidou.mybatisplus.generator.config.GlobalConfig;
    import com.baomidou.mybatisplus.generator.config.PackageConfig;
    import com.baomidou.mybatisplus.generator.config.StrategyConfig;
    
    public class CodeGenerator {
        public static void main(String[] args) {
            //获取代码生成器对象
            AutoGenerator autoGenerator = new AutoGenerator();
            //设置数据库相关配置
            DataSourceConfig dataSource = new DataSourceConfig();
            dataSource.setDriverName("com.mysql.cj.jdbc.Driver");
            dataSource.setUrl("jdbc:mysql://localhost:3306/mybatispuls?serverTimezone=UTC");
            dataSource.setUsername("root");
            dataSource.setPassword("123456");
            autoGenerator.setDataSource(dataSource);
            //设置全局配置
            GlobalConfig globalConfig = new GlobalConfig();
            //设置代码生成位置
            globalConfig.setOutputDir(System.getProperty("user.dir")+"/mybatisplus_generate/src/main/java");
            //设置生成完毕
            globalConfig.setOpen(false);
            globalConfig.setAuthor("shanks");
            //设置生成是否覆盖原始文件
            globalConfig.setFileOverride(true);
            //设置数据层接口名,%s为占位符,指代模块名称
            globalConfig.setMapperName("%sDao");
            //设置id生成策略
            globalConfig.setIdType(IdType.ASSIGN_ID);
            autoGenerator.setGlobalConfig(globalConfig);
            /**
             * 设置包名相关配置
             */
            PackageConfig packageInfo = new PackageConfig();
            //设置生成的包名
            packageInfo.setParent("com.shanks");
            //设置实体类包名
            packageInfo.setEntity("domain");
            //设置数据层包名
            packageInfo.setMapper("dao");
            autoGenerator.setPackageInfo(packageInfo);
            /**
             * 策略设置
             */
            StrategyConfig strategyConfig = new StrategyConfig();
            //设置当前参与生的表名,参数为可变参数
            strategyConfig.setInclude("tb_user");
            //设置数据库名称前缀, 模块名 = 数据表名 - 前缀名
            strategyConfig.setTablePrefix("tb");
            //设置是否启用Rest风格
            strategyConfig.setRestControllerStyle(true);
            //设置乐观锁字段名
            strategyConfig.setVersionFieldName("version");
            //设置逻辑删除字段名
            strategyConfig.setLogicDeleteFieldName("deleted");
            //设置是否启用lombok
            strategyConfig.setEntityLombokModel(true);
            autoGenerator.setStrategy(strategyConfig);
    
            autoGenerator.execute();
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
  • 相关阅读:
    CICD—Jenkins Gitlab自动化打包.net到K8S
    11-定位
    git本地分支代码合并到主分支,主分支合并到我的分支
    Python 办公自动化之 PDF 操作详解
    CSP-J 2023 入门级 第一轮 阅读程序(3)
    2247: 【区赛】[宁波32届小学生]买玩具
    MySql 数据库【子查询】
    【无标题】
    55_Pandas.DataFrame 转换为 JSON 字符串/文件并保存 (to_json)
    03-条件分支及循环
  • 原文地址:https://blog.csdn.net/pilipala_biu/article/details/126733269