传统工程和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搭建项目思路

SpringBoot工程中Web mvc 请求参数的处理(servlet)

SpringBoot入门

SpringBoot整合Jsp和Thymeleaf (附工程)

云计算对于传统软件工程的影响

SpringBoot整合Jsp和Thymeleaf (附工程)