requirejs&&springboot

1.Spring Boot

Spring boot 基础结构主要有三个文件夹:

(1)src/main/java  程序开发以及主程序入口

(2)src/main/resources 配置文件

(3)src/test/java  测试程序

一般根目录下面有一个Application.java,主要用于做一些框架配置,以及项目启动;

其他的domain目录主要用于实体(Entity)与数据访问层(Repository),service 层主要是业务类代码,controller 负责页面访问控制。

注解的使用是spring boot学习的重要模块,例如:@SpringBootApplication声明让Spring Boot自动给程序进行配置,这个配置等同于:@Configuration ,@EnableAutoConfiguration 、@ComponentScan 三个配置。

新建一个mavenproject,在pom.xml里写最初的设置:

<?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.example</groupId>
    <artifactId>springDemo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>springDemo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </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>
        <prerequisites>
        <maven>3.0.0</maven>
    </prerequisites>
    <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>
         <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
       </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

在项目根目录里建一个项目启动的application

package com.example.springDemo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; 

@SpringBootApplication
public class SpringDemoApplication {

    public static void main(String[] args) {
       SpringApplication.run(SpringDemoApplication.class, args);
    }
    
}

在根目录下建一个controller文件夹,里面放页面访问控制

   @RequestMapping("/hello")
    public String index() {
   
        return "Hello World yo";
    }

然后运行启动的java文件,就可以在浏览器里看到执行的结果。默认端口是8080

2.requirjs+vue+element+nginx

主要是在requirejs中使用vue、elementui,使用nginx进行了反向代理。

(1).在项目中若要使用vue和elementui需要在入口文件中配置,paths:{'ELEMENT':'plugs/element-ui/lib/index', 'vue':'plugs/vue/dist/vue’}这里的ELEMENT一定要大写,因为elementui向外暴露的就是全局ELEMENT,vue要小写,因为elementui依赖于vue,大写的话项目找不着vue.js文件

(2).页面跳转使用hashChange事件,当发生hashChange事件时的逻辑写在plugs.js文件里,这个是写全局事件的,在标签里写属性data-open=”url”,在listen.js里写这个属性所对应的on事件或其他事件。

(3) .Nginx配置只需要两个地方:一是nginx.conf里的include xxx.conf,xxx.conf配置文件里配置相关的端口号,项目地址,以及服务器相关接口。

原文地址:https://www.cnblogs.com/LULULI/p/9792157.html