java程序员怎么创建自己的网站:第四章:做个网站引入广告赚点小钱

为了节约开发时间先整一个小架构,网站初期访问不会太大,这套架构可以使用一段时间,废话不多说,开搞。
在idea中创建一个maven工程作为父工程,给它的pom.xml配置一下

  

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5. <modelVersion>4.0.0</modelVersion>
  6. <groupId>com.java.lzw</groupId>
  7. <artifactId>lzwmall</artifactId>
  8. <version>1.0-SNAPSHOT</version>
  9. <packaging>pom</packaging>
  10. <modules>
  11. <module>generator</module>
  12. <module>poral</module>
  13. <module>common</module>
  14. </modules>
  15. <parent>
  16. <groupId>org.springframework.boot</groupId>
  17. <artifactId>spring-boot-starter-parent</artifactId>
  18. <version>2.1.3.RELEASE</version>
  19. <relativePath/>
  20. </parent>
  21. <dependencies>
  22. <dependency>
  23. <groupId>org.springframework.boot</groupId>
  24. <artifactId>spring-boot-starter</artifactId>
  25. </dependency>
  26. <dependency>
  27. <groupId>org.springframework.boot</groupId>
  28. <artifactId>spring-boot-starter-web</artifactId>
  29. </dependency>
  30. <dependency>
  31. <groupId>org.springframework.boot</groupId>
  32. <artifactId>spring-boot-starter-actuator</artifactId>
  33. </dependency>
  34. <dependency>
  35. <groupId>org.springframework.boot</groupId>
  36. <artifactId>spring-boot-starter-aop</artifactId>
  37. </dependency>
  38. <dependency>
  39. <groupId>org.springframework.boot</groupId>
  40. <artifactId>spring-boot-starter-test</artifactId>
  41. <scope>test</scope>
  42. </dependency>
  43. <!--MyBatis分页插件-->
  44. <dependency>
  45. <groupId>com.github.pagehelper</groupId>
  46. <artifactId>pagehelper-spring-boot-starter</artifactId>
  47. <version>1.2.10</version>
  48. </dependency>
  49. <!--集成druid连接池-->
  50. <dependency>
  51. <groupId>com.alibaba</groupId>
  52. <artifactId>druid-spring-boot-starter</artifactId>
  53. <version>1.1.10</version>
  54. </dependency>
  55. </dependencies>
  56. </project>

创建一个子common工程,还是maven工程,修改pom.xml

   

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5. <modelVersion>4.0.0</modelVersion>
  6. <groupId>com.java.lzw</groupId>
  7. <artifactId>common</artifactId>
  8. <version>1.0-SNAPSHOT</version>
  9. <packaging>jar</packaging>
  10. <name>common</name>
  11. <description>common project for lzwmall</description>
  12. <dependencies>
  13. <!--Swagger-UI API文档生产工具-->
  14. <dependency>
  15. <groupId>io.springfox</groupId>
  16. <artifactId>springfox-swagger2</artifactId>
  17. <version>2.7.0</version>
  18. </dependency>
  19. <dependency>
  20. <groupId>io.springfox</groupId>
  21. <artifactId>springfox-swagger-ui</artifactId>
  22. <version>2.7.0</version>
  23. </dependency>
  24. <!--分页插件-->
  25. <dependency>
  26. <groupId>com.github.pagehelper</groupId>
  27. <artifactId>pagehelper</artifactId>
  28. <version>5.1.8</version>
  29. </dependency>
  30. <!--Spring Data家族有多个模块,所有的模块都基于Spring Data Commoms模块进行扩展,
  31. 例如Spring Data JPA是针对JPA做扩展的一个子模块;Spring Data Mongo是针对MongoDB的子模块,但是共同的接口都是Spring Data。
  32. 可以说Spring Data Commons是其所有子模块的抽象,定义了一系列的操作标准及接口。-->
  33. <dependency>
  34. <groupId>org.springframework.data</groupId>
  35. <artifactId>spring-data-commons</artifactId>
  36. <version>2.1.5.RELEASE</version>
  37. </dependency>
  38. <!--Hutool Java工具包-->
  39. <dependency>
  40. <groupId>cn.hutool</groupId>
  41. <artifactId>hutool-all</artifactId>
  42. <version>4.5.7</version>
  43. </dependency>
  44. </dependencies>
  45. </project>

common的项目结构

 

CommonPage

    package com.common.api;
     
    import com.github.pagehelper.PageInfo;
    import org.springframework.data.domain.Page;
     
    import java.util.List;
     
    /**
     * 分页数据封装类
     * Created by macro on 2019/4/19.
     */
    public class CommonPage<T> {
        private Integer pageNum;
        private Integer pageSize;
        private Integer totalPage;
        private Long total;
        private List<T> list;
     
        /**
         * 将PageHelper分页后的list转为分页信息
         */
        public static <T> CommonPage<T> restPage(List<T> list) {
            CommonPage<T> result = new CommonPage<T>();
            PageInfo<T> pageInfo = new PageInfo<T>(list);
            result.setTotalPage(pageInfo.getPages());
            result.setPageNum(pageInfo.getPageNum());
            result.setPageSize(pageInfo.getPageSize());
            result.setTotal(pageInfo.getTotal());
            result.setList(pageInfo.getList());
            return result;
        }
     
        /**
         * 将SpringData分页后的list转为分页信息
         */
        public static <T> CommonPage<T> restPage(Page<T> pageInfo) {
            CommonPage<T> result = new CommonPage<T>();
            result.setTotalPage(pageInfo.getTotalPages());
            result.setPageNum(pageInfo.getNumber());
            result.setPageSize(pageInfo.getSize());
            result.setTotal(pageInfo.getTotalElements());
            result.setList(pageInfo.getContent());
            return result;
        }
     
        public Integer getPageNum() {
            return pageNum;
        }
     
        public void setPageNum(Integer pageNum) {
            this.pageNum = pageNum;
        }
     
        public Integer getPageSize() {
            return pageSize;
        }
     
        public void setPageSize(Integer pageSize) {
            this.pageSize = pageSize;
        }
     
        public Integer getTotalPage() {
            return totalPage;
        }
     
        public void setTotalPage(Integer totalPage) {
            this.totalPage = totalPage;
        }
     
        public List<T> getList() {
            return list;
        }
     
        public void setList(List<T> list) {
            this.list = list;
        }
     
        public Long getTotal() {
            return total;
        }
     
        public void setTotal(Long total) {
            this.total = total;
        }
    }

CommonResult

    package com.common.api;
     
    /**
     * 通用返回对象
     * Created by macro on 2019/4/19.
     */
    public class CommonResult<T> {
        private long code;
        private String message;
        private T data;
     
        protected CommonResult() {
        }
     
        protected CommonResult(long code, String message, T data) {
            this.code = code;
            this.message = message;
            this.data = data;
        }
     
        /**
         * 成功返回结果
         *
         * @param data 获取的数据
         */
        public static <T> CommonResult<T> success(T data) {
            return new CommonResult<T>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data);
        }
     
        /**
         * 成功返回结果
         *
         * @param data 获取的数据
         * @param  message 提示信息
         */
        public static <T> CommonResult<T> success(T data, String message) {
            return new CommonResult<T>(ResultCode.SUCCESS.getCode(), message, data);
        }
     
        /**
         * 失败返回结果
         * @param errorCode 错误码
         */
        public static <T> CommonResult<T> failed(IErrorCode errorCode) {
            return new CommonResult<T>(errorCode.getCode(), errorCode.getMessage(), null);
        }
     
        /**
         * 失败返回结果
         * @param message 提示信息
         */
        public static <T> CommonResult<T> failed(String message) {
            return new CommonResult<T>(ResultCode.FAILED.getCode(), message, null);
        }
     
        /**
         * 失败返回结果
         */
        public static <T> CommonResult<T> failed() {
            return failed(ResultCode.FAILED);
        }
     
        /**
         * 参数验证失败返回结果
         */
        public static <T> CommonResult<T> validateFailed() {
            return failed(ResultCode.VALIDATE_FAILED);
        }
     
        /**
         * 参数验证失败返回结果
         * @param message 提示信息
         */
        public static <T> CommonResult<T> validateFailed(String message) {
            return new CommonResult<T>(ResultCode.VALIDATE_FAILED.getCode(), message, null);
        }
     
        /**
         * 未登录返回结果
         */
        public static <T> CommonResult<T> unauthorized(T data) {
            return new CommonResult<T>(ResultCode.UNAUTHORIZED.getCode(), ResultCode.UNAUTHORIZED.getMessage(), data);
        }
     
        /**
         * 未授权返回结果
         */
        public static <T> CommonResult<T> forbidden(T data) {
            return new CommonResult<T>(ResultCode.FORBIDDEN.getCode(), ResultCode.FORBIDDEN.getMessage(), data);
        }
     
        public long getCode() {
            return code;
        }
     
        public void setCode(long code) {
            this.code = code;
        }
     
        public String getMessage() {
            return message;
        }
     
        public void setMessage(String message) {
            this.message = message;
        }
     
        public T getData() {
            return data;
        }
     
        public void setData(T data) {
            this.data = data;
        }
    }

IErrorCode

    package com.common.api;
     
    /**
     * 封装API的错误码
     * Created by macro on 2019/4/19.
     */
    public interface IErrorCode {
        long getCode();
     
        String getMessage();
    }

ResultCode

    package com.common.api;
     
    /**
     * 枚举了一些常用API操作码
     * Created by macro on 2019/4/19.
     */
    public enum ResultCode implements IErrorCode {
        SUCCESS(200, "操作成功"),
        FAILED(500, "操作失败"),
        VALIDATE_FAILED(404, "参数检验失败"),
        UNAUTHORIZED(401, "暂未登录或token已经过期"),
        FORBIDDEN(403, "没有相关权限");
        private long code;
        private String message;
     
        private ResultCode(long code, String message) {
            this.code = code;
            this.message = message;
        }
     
        public long getCode() {
            return code;
        }
     
        public String getMessage() {
            return message;
        }
    }

创建子工程,maven工程,作为数据层项目

  

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <groupId>com.java.lzw</groupId>
  6. <artifactId>generator</artifactId>
  7. <version>1.0-SNAPSHOT</version>
  8. <packaging>jar</packaging>
  9. <name>generator</name>
  10. <description>generator project for lzwmall</description>
  11. <dependencies>
  12. <dependency>
  13. <groupId>com.java.lzw</groupId>
  14. <artifactId>common</artifactId>
  15. <version>1.0-SNAPSHOT</version>
  16. </dependency>
  17. <!-- MyBatis 生成器 -->
  18. <dependency>
  19. <groupId>org.mybatis.generator</groupId>
  20. <artifactId>mybatis-generator-core</artifactId>
  21. <version>1.3.3</version>
  22. </dependency>
  23. <!-- MyBatis-->
  24. <dependency>
  25. <groupId>org.mybatis</groupId>
  26. <artifactId>mybatis</artifactId>
  27. <version>3.4.6</version>
  28. </dependency>
  29. <!--Mysql数据库驱动-->
  30. <dependency>
  31. <groupId>mysql</groupId>
  32. <artifactId>mysql-connector-java</artifactId>
  33. <version>8.0.15</version>
  34. </dependency>
  35. </dependencies>
  36. </project>

generator的项目架构

 

CommentGenerator

    package com.generator;
     
    import org.mybatis.generator.api.IntrospectedColumn;
    import org.mybatis.generator.api.IntrospectedTable;
    import org.mybatis.generator.api.dom.java.CompilationUnit;
    import org.mybatis.generator.api.dom.java.Field;
    import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
    import org.mybatis.generator.internal.DefaultCommentGenerator;
    import org.mybatis.generator.internal.util.StringUtility;
     
    import java.util.Properties;
     
    /**
     * 自定义注释生成器
     * Created by macro on 2018/4/26.
     */
    public class CommentGenerator extends DefaultCommentGenerator {
        private boolean addRemarkComments = false;
        private static final String EXAMPLE_SUFFIX="Example";
        private static final String API_MODEL_PROPERTY_FULL_CLASS_NAME="io.swagger.annotations.ApiModelProperty";
     
        /**
         * 设置用户配置的参数
         */
        @Override
        public void addConfigurationProperties(Properties properties) {
            super.addConfigurationProperties(properties);
            this.addRemarkComments = StringUtility.isTrue(properties.getProperty("addRemarkComments"));
        }
     
        /**
         * 给字段添加注释
         */
        @Override
        public void addFieldComment(Field field, IntrospectedTable introspectedTable,
                                    IntrospectedColumn introspectedColumn) {
            String remarks = introspectedColumn.getRemarks();
            //根据参数和备注信息判断是否添加备注信息
            if(addRemarkComments&&StringUtility.stringHasValue(remarks)){
    //            addFieldJavaDoc(field, remarks);
                //数据库中特殊字符需要转义
                if(remarks.contains("\"")){
                    remarks = remarks.replace("\"","'");
                }
                //给model的字段添加swagger注解
                field.addJavaDocLine("@ApiModelProperty(value = \""+remarks+"\")");
            }
        }
     
        /**
         * 给model的字段添加注释
         */
        private void addFieldJavaDoc(Field field, String remarks) {
            //文档注释开始
            field.addJavaDocLine("/**");
            //获取数据库字段的备注信息
            String[] remarkLines = remarks.split(System.getProperty("line.separator"));
            for(String remarkLine:remarkLines){
                field.addJavaDocLine(" * "+remarkLine);
            }
            addJavadocTag(field, false);
            field.addJavaDocLine(" */");
        }
     
        @Override
        public void addJavaFileComment(CompilationUnit compilationUnit) {
            super.addJavaFileComment(compilationUnit);
            //只在model中添加swagger注解类的导入
            if(!compilationUnit.isJavaInterface()&&!compilationUnit.getType().getFullyQualifiedName().contains(EXAMPLE_SUFFIX)){
                compilationUnit.addImportedType(new FullyQualifiedJavaType(API_MODEL_PROPERTY_FULL_CLASS_NAME));
            }
        }
    }

Generator

    package com.generator;
     
    import org.mybatis.generator.api.MyBatisGenerator;
    import org.mybatis.generator.config.Configuration;
    import org.mybatis.generator.config.xml.ConfigurationParser;
    import org.mybatis.generator.internal.DefaultShellCallback;
     
    import java.io.InputStream;
    import java.util.ArrayList;
    import java.util.List;
     
    /**
     * 用于生产MBG的代码
     * Created by macro on 2018/4/26.
     */
    public class Generator {
        public static void main(String[] args) throws Exception {
            //MBG 执行过程中的警告信息
            List<String> warnings = new ArrayList<String>();
            //当生成的代码重复时,覆盖原代码
            boolean overwrite = true;
            //读取我们的 MBG 配置文件
            InputStream is = Generator.class.getResourceAsStream("/generatorConfig.xml");
            ConfigurationParser cp = new ConfigurationParser(warnings);
            Configuration config = cp.parseConfiguration(is);
            is.close();
     
            DefaultShellCallback callback = new DefaultShellCallback(overwrite);
            //创建 MBG
            MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
            //执行生成代码
            myBatisGenerator.generate(null);
            //输出警告信息
            for (String warning : warnings) {
                System.out.println(warning);
            }
        }
    }

generator.properties

    jdbc.driverClass=com.mysql.jdbc.Driver
    jdbc.connectionURL=jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
    jdbc.userId=root
    jdbc.password=123456

generatorConfig.xml

   

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE generatorConfiguration
  3. PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
  4. "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
  5. <generatorConfiguration>
  6. <properties resource="generator.properties"/>
  7. <context id="MySqlContext" targetRuntime="MyBatis3" defaultModelType="flat">
  8. <property name="beginningDelimiter" value="`"/>
  9. <property name="endingDelimiter" value="`"/>
  10. <property name="javaFileEncoding" value="UTF-8"/>
  11. <!-- 为模型生成序列化方法-->
  12. <plugin type="org.mybatis.generator.plugins.SerializablePlugin"/>
  13. <!-- 为生成的Java模型创建一个toString方法 -->
  14. <plugin type="org.mybatis.generator.plugins.ToStringPlugin"/>
  15. <commentGenerator type="com.generator.CommentGenerator">
  16. <!-- 是否去除自动生成的注释 true:是 : false:否 -->
  17. <property name="suppressAllComments" value="true"/>
  18. <property name="suppressDate" value="true"/>
  19. <property name="addRemarkComments" value="true"/>
  20. </commentGenerator>
  21. <jdbcConnection driverClass="${jdbc.driverClass}"
  22. connectionURL="${jdbc.connectionURL}"
  23. userId="${jdbc.userId}"
  24. password="${jdbc.password}">
  25. <!--解决mysql驱动升级到8.0后不生成指定数据库代码的问题-->
  26. <property name="nullCatalogMeansCurrent" value="true" />
  27. </jdbcConnection>
  28. <javaModelGenerator targetPackage="com.generator.model" targetProject="generator\src\main\java"/>
  29. <sqlMapGenerator targetPackage="mapper" targetProject="generator\src\main\resources"/>
  30. <javaClientGenerator type="XMLMAPPER" targetPackage="com.generator.mapper"
  31. targetProject="generator\src\main\java"/>
  32. <!--生成全部表tableName设为%-->
  33. <table tableName="%">
  34. <generatedKey column="id" sqlStatement="MySql" identity="true"/>
  35. </table>
  36. </context>
  37. </generatorConfiguration>

如果你不想连接我的数据库,可以将generator.properties中的数据连接改为你自己的,到时运行Generator中的main方法,生成你自己的数据文件
创建一个Springboot子工程,作为门户,网站前台给用户看的,修改pom.xml

   

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <groupId>com.java.lzw</groupId>
  6. <artifactId>poral</artifactId>
  7. <version>1.0-SNAPSHOT</version>
  8. <packaging>jar</packaging>
  9. <name>poral</name>
  10. <description>poral project for lzwmall</description>
  11. <properties>
  12. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  13. <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  14. <java.version>1.8</java.version>
  15. <skipTests>true</skipTests>
  16. </properties>
  17. <parent>
  18. <groupId>com.java.lzw</groupId>
  19. <artifactId>lzwmall</artifactId>
  20. <version>1.0-SNAPSHOT</version>
  21. <relativePath>../</relativePath>
  22. </parent>
  23. <dependencies>
  24. <!--依赖数据层-->
  25. <dependency>
  26. <groupId>com.java.lzw</groupId>
  27. <artifactId>generator</artifactId>
  28. <version>1.0-SNAPSHOT</version>
  29. </dependency>
  30. <!--集成logstash,logstash就是一根具备实时数据传输能力的管道,负责将数据信息从管道的输入端传输到管道的输出端;
  31. 与此同时这根管道还可以让你根据自己的需求在中间加上滤网,Logstash提供里很多功能强大的滤网以满足你的各种应用场景。
  32. Logstash常用于日志关系系统中做日志采集设备-->
  33. <dependency>
  34. <groupId>net.logstash.logback</groupId>
  35. <artifactId>logstash-logback-encoder</artifactId>
  36. <version>4.8</version>
  37. </dependency>
  38. </dependencies>
  39. <build>
  40. <plugins>
  41. <plugin>
  42. <groupId>org.springframework.boot</groupId>
  43. <artifactId>spring-boot-maven-plugin</artifactId>
  44. </plugin>
  45. </plugins>
  46. </build>
  47. </project>

poral的项目架构

 

config中的MyBatisConfig

    package com.java.lzw.poral.config;
     
    import org.mybatis.spring.annotation.MapperScan;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.transaction.annotation.EnableTransactionManagement;
     
    /**
     * MyBatis配置类
     * Created by macro on 2019/4/8.
     */
    @Configuration
    @EnableTransactionManagement
    @MapperScan({"com.generator.mapper","com.java.lzw.poral.dao"})//第一个参数对应generator项目的mapper接口,第二个参数对应本项目自定义的dao(mapper)层接口
    public class MyBatisConfig {
     
    }

config中的SwaggerConfig

    package com.java.lzw.poral.config;
     
    import io.swagger.annotations.ApiOperation;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import springfox.documentation.builders.ApiInfoBuilder;
    import springfox.documentation.builders.PathSelectors;
    import springfox.documentation.builders.RequestHandlerSelectors;
    import springfox.documentation.service.ApiInfo;
    import springfox.documentation.spi.DocumentationType;
    import springfox.documentation.spring.web.plugins.Docket;
    import springfox.documentation.swagger2.annotations.EnableSwagger2;
     
    @Configuration
    @EnableSwagger2
    public class SwaggerConfig {
     
        @Bean
        public Docket createRestApi(){
            return new Docket(DocumentationType.SWAGGER_2)
                    .apiInfo(apiInfo())
                    .select()
                    .apis(RequestHandlerSelectors.basePackage("com.java.lzw.poral.controller"))
                    .paths(PathSelectors.any())
                    .build();
        }
     
        private ApiInfo apiInfo() {
            return new ApiInfoBuilder()
                    .title("商城前台系统")
                    .description("商城前台系统")
                    .contact("lzw")
                    .version("1.0")
                    .build();
        }
     
    }

controller中的DemoController

    package com.java.lzw.poral.controller;
     
    import com.generator.model.OmsOrder;
    import com.java.lzw.poral.service.OmsOrderService;
    import io.swagger.annotations.Api;
    import io.swagger.annotations.ApiOperation;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.ResponseBody;
     
    import java.util.List;
     
    @Api(description = "测试接口")
    @Controller
    @RequestMapping("/demoController")
    public class DemoController {
     
     
        @Autowired
        private OmsOrderService omsOrderService;
     
        @ApiOperation("测试")
        @RequestMapping(value = "/mail", method = RequestMethod.GET)
        @ResponseBody
        public List<OmsOrder> sendMail() {
            List<OmsOrder> orderList = omsOrderService.getOrderInfo();
            return orderList;
        }
     
     
    }

dao层是你自定义的mapper接口,我这边只是做一个测试先没有写

service层的OmsOrderService

    package com.java.lzw.poral.service;
     
    import com.generator.model.OmsOrder;
     
    import java.util.List;
     
    public interface OmsOrderService {
     
        List<OmsOrder> getOrderInfo();
     
    }

service.impl层的

    package com.java.lzw.poral.service.impl;
     
    import com.generator.mapper.OmsOrderMapper;
    import com.generator.model.OmsOrder;
    import com.generator.model.OmsOrderExample;
    import com.java.lzw.poral.service.OmsOrderService;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import java.util.List;
     
    @Service
    public class OmsOrderServiceImpl implements OmsOrderService {
     
        @Autowired
        private OmsOrderMapper orderMapper;
     
        @Override
        public List<OmsOrder> getOrderInfo() {
            OmsOrderExample omsOrderExample = new OmsOrderExample();
            OmsOrderExample.Criteria criteria = omsOrderExample.createCriteria();
            return orderMapper.selectByExample(omsOrderExample);
        }
    }

启动类PoralApplication

  1. package com.java.lzw.poral;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. @SpringBootApplication
  5. public class PoralApplication {
  6. public static void main(String[] args) {
  7. SpringApplication.run(PoralApplication.class, args);
  8. }
  9. }

resoures下的application.properties没有写

resoures下的application.yml

 

  1. spring:
  2. profiles:
  3. active: dev #默认为开发环境
  4. mybatis:
  5. mapper-locations:
  6. - classpath*:mapper/*.xml
  7. logging:
  8. level:
  9. root: info #日志配置DEBUG,INFO,WARN,ERROR
  10. com.macro.mall: debug
  11. # file: demo_log.log #配置日志生成路径
  12. # path: /var/logs #配置日志文件名称

resoures下的application-dev.yml

  

  1. spring:
  2. datasource:
  3. url: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
  4. username: root
  5. password: 123456
  6. druid:
  7. initial-size: 5 #连接池初始化大小
  8. min-idle: 10 #最小空闲连接数
  9. max-active: 20 #最大连接数
  10. web-stat-filter:
  11. exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" #不统计这些请求数据
  12. stat-view-servlet: #访问监控网页的登录用户名和密码
  13. login-username: druid
  14. login-password: druid

新加resoures下的logback-spring.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE configuration>
  3. <configuration>
  4. <include resource="org/springframework/boot/logging/logback/defaults.xml"/>
  5. <include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
  6. <!--应用名称-->
  7. <property name="APP_NAME" value="mall-admin"/>
  8. <!--日志文件保存路径-->
  9. <property name="LOG_FILE_PATH" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}}/logs}"/>
  10. <contextName>${APP_NAME}</contextName>
  11. <!--每天记录日志到文件appender-->
  12. <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
  13. <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
  14. <fileNamePattern>${LOG_FILE_PATH}/${APP_NAME}-%d{yyyy-MM-dd}.log</fileNamePattern>
  15. <maxHistory>30</maxHistory>
  16. </rollingPolicy>
  17. <encoder>
  18. <pattern>${FILE_LOG_PATTERN}</pattern>
  19. </encoder>
  20. </appender>
  21. <!--输出到logstash的appender-->
  22. <appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
  23. <destination>localhost:4560</destination>
  24. <encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder"/>
  25. </appender>
  26. <root level="INFO">
  27. <appender-ref ref="CONSOLE"/>
  28. <appender-ref ref="FILE"/>
  29. <appender-ref ref="LOGSTASH"/>
  30. </root>
  31. </configuration>

这个时候后端架构基本搭好了,小架构:springboot+mybatis+MyBatisGenerator+Swagger-UI+PageHelper

现在有二种方式,一个是在poral项目中写页面,一种是新建一个项目前后端分离

我现在一个开发就不分离了,直接写到poral项目中

poral的架构

 

把你的静态资源搞进 static包里

把你的页面搞到templates里面去

修改一下application.properties文件

   

  1. server.port=8084
  2. #这里使用thymeleaf模板引擎代替jsp页面
  3. spring.thymeleaf.mode=LEGACYHTML5
  4. spring.thymeleaf.cache=false

使用thymeleaf需要导入依赖到poral项目中

   

  1. <dependency>
  2. <groupId>org.thymeleaf</groupId>
  3. <artifactId>thymeleaf</artifactId>
  4. <version>2.1.4</version>
  5. </dependency>

页面也要加头文件

   

  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml"
  3. xmlns:th="http://www.thymeleaf.org">

如果不会使用thymeleaf我之前的博客中给上链接https://blog.csdn.net/java_wxid/article/details/86498332

当然如果你是新手用jsp写也没有事。

如果是前后端分离:启动后端项目在浏览器中输入:http://localhost:8084/swagger-ui.html#/

可以查看你的接口文档

 

不过你需要部署你的接口到服务器,前端人员才可进行开发。

剩下的就属于你的开发时间了,网站做成什么样就看你的开发水平了,这里我就不写了。

当然我还知道有很多东西没有配置,像什么alipay,短信验证码,权限,缓存,信息队列之类的,但初期第一版也就先这样吧。

这里给上简单的项目链接可以下载:

链接:https://pan.baidu.com/s/1coEfS73tsP9wmSJ-ewb45g
提取码:fy5n
 

如果写好你的项目运行不报错之后就该部署项目到网上去,让用户可以通过域名访问你的网站了,部署也有二种情况,一种用自己的机器部署,一种用云服务器,而这二种可以分为普通部署和使用docker部署,这里我给上之前有部署过的项目部署流程的博客地址https://blog.csdn.net/java_wxid/article/details/89785556。

这种情况是用我的笔记本部署,用云数据库连接。当然如果你习惯了linux系统部署,而且像快速部署到云服务器上建议你购买所需的环境镜像并重装该镜像即可,这样可以少了很多配置。

重装系统操作文档链接:https://cloud.tencent.com/document/product/213/4933

需要有搭建tomcat的集成环境即可,这边为您推荐与之相关的环境供您参考。

Java运行环境(nginx+mysql+tomcat) :https://market.cloud.tencent.com/products/6483

 

现在是激动人心的时刻了,引入广告联盟,赚钱的时候了。

麒麟广告联盟(www.70e.com),支持点击和弹窗。一千点击100元。一千弹窗50元。周付,50元起付,支持网银,最好的是支持支付宝。比较好的公司运营联盟除开百度跟谷歌外,再就是酷奇广告联盟,他们那边不扣量,不扣税,不扣手续费。

这里就介绍二家,具体流程我也不好写,毕竟每家的不同,要求也不同,弄好这些杂七杂八的东西,把你的广告引入的项目中就ok了。到时直接根据访问量拿钱,所以你需要对你的网站弄一个吸引人的点,这里方式多种,我就不介绍了。