传统工程和springboot工程
Posted zhy819
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了传统工程和springboot工程相关的知识,希望对你有一定的参考价值。
传统创建工程的方法:
1.创建web工程
2.配置springmvc以及web.xml
3.编写Controller
4.部署tomcat
springboot工程的创建方法:
在没有联网的情况下,依旧可以创建工程,创建一个空工程,自己导入依赖,创建启动类
1.创建一个空工程,导入依赖,依赖必须继承spring-boot-stater-parent
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.2.RELEASE</version> <relativePath/> </parent>
<dependencies> <!--因为没有tomcat,所以要添加spring mvc的依赖--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
2. 编写Controller类
@RestController public class PojoController { @RequestMapping("/hello") public Map sayHello(){ Map map = new HashMap(); map.put("hi","sayhello"); return map; } }
3.创建并编写主启动类(主启动类必须是Controller等其他类的父级)
@SpringBootApplication //主启动类 public class HelloApplication { public static void main(String[] args) { //run()方法的参数是本身的字节码和一个参数 SpringApplication.run(HelloApplication.class,args); } }
4.启动带有main方法的主启动类
并访问Controller中的url:http://localhost:8080/hello
以上是关于传统工程和springboot工程的主要内容,如果未能解决你的问题,请参考以下文章
SpringBoot工程中Web mvc 请求参数的处理(servlet)