创建一个简单的 Springboot web项目

1、点击Project

2、点击 Next

3、项目名

4、web 项目

4、确认

5、pom.xml

扫描二维码关注公众号,回复: 6342334 查看本文章
<?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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>moneyer</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>moneyer</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <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>

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

</project>

6、启动类

package com.example.moneyer;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MoneyerApplication {

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

}

7、Controller类

package com.example.moneyer;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    @RequestMapping("/hello")
    public  String  login(){
        return "hello world!!";
    }
    @RequestMapping("closed")
    public String  close(){
        return "This door is closed!";
    }
}

8、启动项目

"C:\Program Files\Java\jdk1.8.0_181\bin\java.exe"...

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.5.RELEASE)

2019-06-03 20:04:01.853  INFO 3320 --- [           main] com.example.moneyer.MoneyerApplication   : Starting MoneyerApplication on DESKTOP-LLVMBMQ with PID 3320 (C:\Users\dell\IdeaProjects\moneyer\target\classes started by dell in C:\Users\dell\IdeaProjects\moneyer)
2019-06-03 20:04:01.857  INFO 3320 --- [           main] com.example.moneyer.MoneyerApplication   : No active profile set, falling back to default profiles: default
2019-06-03 20:04:03.241  INFO 3320 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2019-06-03 20:04:03.266  INFO 3320 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-06-03 20:04:03.266  INFO 3320 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.19]
2019-06-03 20:04:03.363  INFO 3320 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-06-03 20:04:03.363  INFO 3320 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1448 ms
2019-06-03 20:04:03.537  INFO 3320 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-06-03 20:04:03.693  INFO 3320 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2019-06-03 20:04:03.695  INFO 3320 --- [           main] com.example.moneyer.MoneyerApplication   : Started MoneyerApplication in 2.619 seconds (JVM running for 3.568)

9、效果

  1)http://localhost:8080/hello

   

  2)http://localhost:8080/closed

   

猜你喜欢

转载自www.cnblogs.com/Small-sunshine/p/10969768.html
今日推荐