您的位置:首页 > 编程语言 > Java开发

《spring-boot学习》-02-hello world

2017-02-24 15:47 274 查看
1.新建一个maven项目

pox.xml文件内容如下

<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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion>
<groupId>springBootTest2</groupId>
<artifactId>springBootTest2</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>springBootTest2 Maven Webapp</name>
<url>http://maven.apache.org</url>

<!-- spring boot基本环境 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.1.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>

<!--web应用基本环境配置 -->
<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> -->
<finalName>ceshi</finalName>
</build>
</project>


这个地方写错可能在运行的时候报错



2.编写controller文件

package com.sishuok.controller;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
* Created by 三劫散仙 on 2015/4/24.
*/
@Controller
@EnableAutoConfiguration
public class HellowController {

@RequestMapping("/hellow")
@ResponseBody
public String hellow(){

return "哈喽,Spring Boot !";
}

public static void main(String[] args) {
//第一个简单的应用,
SpringApplication.run(HellowController.class,args);

}

}


3.直接运行main方法。可以看到控制台打印出



4.在页面输入http://localhost:8080/hellow 注意这里没有项目名称

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: