idea 创建简单的webdemo

£可爱£侵袭症+ 提交于 2020-02-28 22:29:29

1.start.spring.io

简单的web例子

打开IDE中的项目,并在src/main/java/com/example/demo文件夹中找到DemoApplication.java文件。现在通过添加额外的方法和注释来更改文件的内容

2.例子的Demo1Application.java

package com.example.demo1;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class Demo1Application {

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

    @GetMapping("/hello")
    public String hello(@RequestParam(value = "name", defaultValue = "keny88888") String name) {
        return String.format("Hello %s!", name);
    }
}

 

3.运行mvnw spring-root:run

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

2020-02-28 20:00:18.506  INFO 9964 --- [           main] com.example.demo1.Demo1Application       : Starting Demo1Application on kenychen-PC with PID 9964 (D:\IdeaProjects\demo1\target\classes started by kenychen in D:\IdeaProjects\demo1)
2020-02-28 20:00:18.513  INFO 9964 --- [           main] com.example.demo1.Demo1Application       : No active profile set, falling back to default profiles: default
2020-02-28 20:00:21.453  INFO 9964 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2020-02-28 20:00:21.482  INFO 9964 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-02-28 20:00:21.483  INFO 9964 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.31]
2020-02-28 20:00:21.730  INFO 9964 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-02-28 20:00:21.731  INFO 9964 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3037 ms
2020-02-28 20:00:22.122  INFO 9964 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-02-28 20:00:22.390  WARN 9964 --- [           main] ion$DefaultTemplateResolverConfiguration : Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)
2020-02-28 20:00:22.863  INFO 9964 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2020-02-28 20:00:22.906  INFO 9964 --- [           main] com.example.demo1.Demo1Application       : Started Demo1Application in 6.473 seconds (JVM running for 9.176)
2020-02-28 20:00:57.201  INFO 9964 --- [nio-8080-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-02-28 20:00:57.201  INFO 9964 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2020-02-28 20:00:57.214  INFO 9964 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : Completed initialization in 13 ms

4.运行结果

http://localhost:8080/hello?name=xiaoxiao

Hello xiaoxiao!

 

 

 

 

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!