栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

springboot 应用注意事项

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

springboot 应用注意事项

1 准备内容

mysql安装 docker-compose.yml内容

version: '3'
 
services:
    mysql-db:
        container_name: mysql5.7
        image: mysql:5.7
 
        ports:
          - "13306:3306"
        environment:
            MYSQL_ROOT_PASSWORD: "root"
			- TZ=Asia/Shanghai
        command:
          --wait_timeout=31536000
          --interactive_timeout=31536000
          --max_connections=1000
        volumes:
          - "./mysql/data: /var/lib/mysql"
          - "./mysql/config: /etc/mysql/conf.d"

maven 换源 setting.xml



      
          
            alimaven  
            aliyun maven  
            http://maven.aliyun.com/nexus/content/groups/public/  
            central          
          
      

排除自动配置bean @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})

pom.xml 配置druid和Hibernate验证

    
        com.github.drtrang
        druid-spring-boot2-starter
        1.1.10
    
    
    
        org.springframework.boot
        spring-boot-starter-validation
        2.5.5
    
      
        com.baomidou
        mybatis-plus-boot-starter
        3.4.3.4
    

BaseDO

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;


@TableName(value ="tag")
@Data
public class Tag implements Serializable {
    
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    
    @TableField(value = "name")
    private String name;

    
    @TableField(value = "createTime")
    private Date createTime;

    
    @TableField(value = "isDelete")
    private Byte isDelete;

    
    @TableField(value = "updateTime")
    private Date updateTime;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        Tag other = (Tag) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
            && (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
            && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
            && (this.getIsDelete() == null ? other.getIsDelete() == null : this.getIsDelete().equals(other.getIsDelete()))
            && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
        result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
        result = prime * result + ((getIsDelete() == null) ? 0 : getIsDelete().hashCode());
        result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", id=").append(id);
        sb.append(", name=").append(name);
        sb.append(", createTime=").append(createTime);
        sb.append(", isDelete=").append(isDelete);
        sb.append(", updateTime=").append(updateTime);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }
}

自动生成实体类


响应基类

import lombok.Data;


@Data
public class BaseResponse {

    private int code;

    private T data;

    private String message;

    public BaseResponse(int code, T data, String message) {
        this.code = code;
        this.data = data;
        this.message = message;
    }
}

响应工具类


public class ResultUtils {

    
    public static  BaseResponse success(T data) {
        return new BaseResponse<>(0, data, "ok");
    }

    
    public static  BaseResponse error(int code, String errorMessage) {
        return new BaseResponse<>(code, null, errorMessage);
    }
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/887803.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号