美文网首页
《十次方》05、父工程及公共模块搭建

《十次方》05、父工程及公共模块搭建

作者: db41bbeed50c | 来源:发表于2018-12-29 09:36 被阅读43次

    创建新工程

    图片.png

    创建maven项目(这里在创建过程中我并没有使用webapp这个骨架进行创建,因为他会通过网络下载很多其实我并不需要的jar包,需要使用的我直接在项目中配置即可。)

    图片.png

    公共工程(使用“-”下划线符合IDEA的开发规范,下一步的时候不要改名称)

    图片.png

    调整工作空间(大家根据自己的情况来即可)

    图片.png 图片.png

    pom文件

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.tensquare</groupId>
        <artifactId>tensquare_parent</artifactId>
        <version>1.0-SNAPSHOT</version>
        <modules>
            <module>tensquare_common</module>
            <module>tensquare_base</module>
        </modules>
        <!--两种情况打pom:-->
        <!--1.聚合工程的父工程-->
        <!--2.统一管理依赖的parent-->
        <!--需要进行部署到Tomcat打war包-->
        <!--其他的情况打jar包-->
        <packaging>pom</packaging>
    
        <name>tensquare_parent</name>
        <!--这个名字要不要都可以 -->
        <description>十次方项目</description>
    
        <!--我们的项目是基于springboot的所以需要继承‘spring-boot-starter-parent’-->
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.0.1.RELEASE</version>
            <relativePath/>
        </parent>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <java.version>1.8</java.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
    
        <!--spring官网所提供的仓库 -->
        <repositories>
            <repository>
                <id>spring-snapshots</id>
                <name>SpringSnapshots</name>
                <url>https://repo.spring.io/snapshot</url>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
            <repository>
                <id>spring-milestones</id>
                <name>SpringMilestones</name>
                <url>https://repo.spring.io/milestone</url>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
            </repository>
        </repositories>
    
        <!--下载插件 -->
        <pluginRepositories>
            <pluginRepository>
                <id>spring-snapshots</id>
                <name>SpringSnapshots</name>
                <url>https://repo.spring.io/snapshot</url>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </pluginRepository>
            <pluginRepository>
                <id>spring-milestones</id>
                <name>SpringMilestones</name>
                <url>https://repo.spring.io/milestone</url>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
            </pluginRepository>
        </pluginRepositories>
    
    </project>
    

    搭建公共工程

    图片.png

    定义返回结果实体类

    //返回结果实体类
    public class Result{
    
        private Boolean flag;//是否成功
        private Integer code;//返回码
        private String message;//返回信息
        private Object data;//返回数据
    
        public Result() {
        }
    
        public Result(Boolean flag, Integer code, String message) {
            this.flag = flag;
            this.code = code;
            this.message = message;
        }
    
        public Result(Boolean flag, Integer code, String message, Object data) {
    
            this.flag = flag;
            this.code = code;
            this.message = message;
            this.data = data;
        }
    
        public Boolean getFlag() {
            return flag;
        }
    
        public void setFlag(Boolean flag) {
            this.flag = flag;
        }
    
        public Integer getCode() {
            return code;
        }
    
        public void setCode(Integer code) {
            this.code = code;
        }
    
        public String getMessage() {
            return message;
        }
    
        public void setMessage(String message) {
            this.message = message;
        }
    
        public Object getData() {
            return data;
        }
    
        public void setData(Object data) {
            this.data = data;
        }
    

    定义返回分页结果实体类

    //返回分页结果
    public class PageResult<T> {
    
        private Long total;
        private List<T> rows;
    
        public PageResult() {
        }
    
        public PageResult(Long total, List<T> rows) {
            this.total = total;
            this.rows = rows;
        }
    
        public Long getTotal() {
    
            return total;
        }
    
        public void setTotal(Long total) {
            this.total = total;
        }
    
        public List<T> getRows() {
            return rows;
        }
    
        public void setRows(List<T> rows) {
            this.rows = rows;
        }
    

    定义状态码实体类

    //定义状态码实体类(Ctrl+R进行替换)
    public class StatusCode {
    
        public static final int OK = 20000;//成功
        public static final int ERROR = 20001;//失败
        public static final int LOGINERROR = 20002;//用户名或密码错误
        public static final int ACCESSERROR = 20003;//权限不足
        public static final int REMOTEERROR = 20004;//远程调用失败
        public static final int REPERROR = 20005;//重复操作
    
    }
    

    十次方文集:https://www.jianshu.com/nb/32298744

    相关文章

      网友评论

          本文标题:《十次方》05、父工程及公共模块搭建

          本文链接:https://www.haomeiwen.com/subject/qlbelqtx.html