基於SpringCloud+vue(ElementUI)+mySQL前後端分離設計之–搭建後臺管理系統

程式碼牛發表於2019-01-19

開發一個部落格系統

文章數:選單文章都沒更新完
搭建eureka註冊中心 (請先閱讀此文章) https://segmentfault.com/a/11…
搭建Beans編寫Token解析註解 https://segmentfault.com/a/11…
搭建許可權管理系統 https://segmentfault.com/a/11…
搭建後臺管理系統 https://segmentfault.com/a/11…
前端Fetch請求封裝 https://segmentfault.com/a/11…

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

    <name>customer</name>
    <description>customer project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.6.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>
        <spring-cloud.version>Camden.SR6</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.server</groupId>
            <artifactId>beans</artifactId>
            <version>1.0-SNAPSHOT</version><!--這是我的beans專案-->
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-websocket</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-feign</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.11</version>
        </dependency>

        <!-- SpringData-Jpa依賴-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

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


</project>

啟動類

@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient
@EnableFeignClients
public class CustomerApplication {

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

使用許可權管理系統服務類

@FeignClient(value = "AUS")
public interface AuthorityServer {
    @RequestMapping(value = "/auth/login",method = RequestMethod.POST)
    String loginAuthentication(@RequestBody UserEntity user);

    @RequestMapping(value = "/auth/token",method = RequestMethod.GET)
    String getResourceAuthentication(@RequestParam(value = ParameterNames.ACCESS_TOKEN) String token);

    @RequestMapping(value = "/auth/sign",method = RequestMethod.POST)
    String userSignIn(@RequestBody UserEntity user);

    @RequestMapping(value = "/auth/update",method = RequestMethod.POST)
    String userUpdate(@RequestBody UserEntity user);

    @RequestMapping(value = "/api/verify",method = RequestMethod.GET)
    String getResourcePermissions(@RequestParam(value = ParameterNames.ACCESS_TOKEN)String token,@RequestParam(ParameterNames.CODE) String app,@RequestParam(ParameterNames.PATH) String path);
}

》》例子:
"使用該類直接調方法傳參就可以了"
    @Autowired
    private AuthorityServer authorityServer;
    
    authorityServer.loginAuthentication(bean);

相關文章