Spring boot 学习笔记 ---分分钟构建一个web程序(一)

来源:互联网 发布:视频画中画制作软件 编辑:程序博客网 时间:2024/06/04 19:06


Springboot学习笔记


1.分分钟创建一个简单springmvc项目

基本环境

jdk1.7+

maven 3.3+

eclipse

  1. 使用创建一个maven项目
















2.添加pom依赖


<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><groupId>com.zghw</groupId><artifactId>spring-boot-demo</artifactId><version>0.0.1-SNAPSHOT</version><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.2.5.RELEASE</version></parent><properties><java.version>1.7</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>



  1. 开发一个restController

package com.zghw.controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestControllerpublic class HelloWorldController {@RequestMapping("/")public String hello() {return "hello";}}
  1. 创建运行程序Application

package com.zghw;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class Application {public static void main(String args[]){SpringApplication.run(Application.class, args);}}

  1. 启动main()方法访问项目








  1. 打包运行

    进入目录/home/zghw/gitspace/spring-boot-demo

    mvnclean install

    java-jar target/spring-boot-demo-0.0.1-SNAPSHOT.jar

1 0