SpringBoot:HelloWorld:修订间差异
imported>Soleverlee |
imported>Soleverlee |
||
第69行: | 第69行: | ||
... | ... | ||
</pre> | </pre> | ||
另外可以试用RestController: | |||
<source lang="java"> | |||
@RestController | |||
@EnableAutoConfiguration | |||
public class RestfulController { | |||
@RequestMapping("/info") | |||
String version(){ | |||
return "micrork 0.1"; | |||
} | |||
} | |||
</source> | |||
=打包部署= | =打包部署= | ||
[[Category:Programe]] | [[Category:Programe]] |
2016年8月31日 (三) 15:27的版本
创建maven工程
修改pom.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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.riguz</groupId>
<artifactId>micrork</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>micrork</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
创建Rest服务
@Controller
@EnableAutoConfiguration
public class SimpleController {
@RequestMapping("/")
@ResponseBody
String home() {
return "Hello World!";
}
}
再创建一个主函数:
public static void main(String[] args) {
SpringApplication.run(SimpleController.class, args);
}
运行即可(访问localhost:8080):
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v1.4.0.RELEASE) ...
另外可以试用RestController:
@RestController
@EnableAutoConfiguration
public class RestfulController {
@RequestMapping("/info")
String version(){
return "micrork 0.1";
}
}