博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Intellij创建简单Springboot项目
阅读量:6580 次
发布时间:2019-06-24

本文共 4202 字,大约阅读时间需要 14 分钟。

Intellij创建简单Springboot项目

 

第一步:选择创建新项目——file-new-project

 

第二步:选择项目类型——Spring Initializr-next

 第三步:输入项目信息——Spring Initializr-next

 第四步:选择Spring组建——web-web(勾选)

第五步:修改项目名称和项目路径(默认即可)——Finish

第六步:写一个Demo Controller层(controller的代码必须和SpringbootDemoApplication.java位于同级目录或之下)

 

//Main方法,项目从这里iahsi启动,是项目创建时自动生成的;package com.example.springboot_demo;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class SpringbootDemoApplication {    public static void main(String[] args) {        SpringApplication.run(SpringbootDemoApplication.class, args);    }}

 

 

//自定义Controller方法(注意@RestController的使用)package com.example.springboot_demo.controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestControllerpublic class DemoController {    @RequestMapping("/login")    public String login(){        return "login success!";    }}

 

第七步:启动项目,并用浏览器访问项目

//启动日志输出  .   ____          _            __ _ _ /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/  ___)| |_)| | | | | || (_| |  ) ) ) )  '  |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot ::        (v2.1.0.RELEASE)2018-11-29 09:47:16.011  INFO 14668 --- [           main] c.e.s.SpringbootDemoApplication          : No active profile set, falling back to default profiles: default2018-11-29 09:47:17.710  INFO 14668 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)2018-11-29 09:47:17.734  INFO 14668 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]2018-11-29 09:47:17.735  INFO 14668 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/9.0.122018-11-29 09:47:17.899  INFO 14668 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext2018-11-29 09:47:17.899  INFO 14668 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1802 ms2018-11-29 09:47:17.933  INFO 14668 --- [           main] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]2018-11-29 09:47:17.939  INFO 14668 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]2018-11-29 09:47:17.940  INFO 14668 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]2018-11-29 09:47:17.940  INFO 14668 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'formContentFilter' to: [/*]2018-11-29 09:47:17.940  INFO 14668 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]2018-11-29 09:47:18.203  INFO 14668 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'2018-11-29 09:47:18.482  INFO 14668 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''2018-11-29 09:47:18.487  INFO 14668 --- [           main] c.e.s.SpringbootDemoApplication          : Started SpringbootDemoApplication in 3.183 seconds (JVM running for 4.749)

 

 

 备注:一开始在DemoController上用@Controller注解,发现不起效果;原来@RestController和@Controller是有区别的。

通过查看@RestController的源码发现:@RestController注解 = @ResponseBody + @Controller

package org.springframework.web.bind.annotation;import java.lang.annotation.Documented;import java.lang.annotation.ElementType;import java.lang.annotation.Retention;import java.lang.annotation.RetentionPolicy;import java.lang.annotation.Target;import org.springframework.core.annotation.AliasFor;import org.springframework.stereotype.Controller;@Target({ElementType.TYPE})@Retention(RetentionPolicy.RUNTIME)@Documented@Controller@ResponseBodypublic @interface RestController {    @AliasFor(        annotation = Controller.class    )    String value() default "";}

 

 参考资料:

1-

2-

 

转载于:https://www.cnblogs.com/wobuchifanqie/p/10036458.html

你可能感兴趣的文章
MongoDB的副本集Replica Set
查看>>
Maven项目中的配置文件找不到以及打包问题
查看>>
面向对象
查看>>
HDU 1058 Humble Numbers
查看>>
NYOJ The Triangle
查看>>
wps10.1中将txt转为excel
查看>>
并发同步知多少
查看>>
解决执行脚本报syntax error: unexpected end of file或syntax error near unexpected token `fi'错误的问题...
查看>>
[BZOJ3312][USACO]不找零(状压DP)
查看>>
页面之间的传值和大量参数的传递
查看>>
python学习之路-5 基础进阶篇
查看>>
gtp转换mbr
查看>>
django rest framework
查看>>
登录注册界面
查看>>
poj1985 求树的直径
查看>>
Python PyPI中国镜像
查看>>
centos 设置静态IP
查看>>
[Angularjs]系列——学习与实践
查看>>
js -- canvas img 封装
查看>>
转 我们工作的动力是什么 工作最终是为了什么?
查看>>