SpringBoot学习helloworld

  这几天开始学习springBoot记录一下(Hello World)

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>org.bianqi.spring.first</groupId>
<artifactId>SpringBootFirst</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>${start-class}</mainClass>
<layout>ZIP</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

2.编写controller

 package org.bianqi.first.demo;

 import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; @RestController
@EnableAutoConfiguration
@ComponentScan
public class FirstDemo { @Autowired
private FirstService fs; @RequestMapping("/")
String home(){
fs.demo();
return "hello world!";
}
public static void main(String[] args) {
SpringApplication.run(FirstDemo.class, args);
} }

3.编写service的接口

 package org.bianqi.first.demo;

 public interface FirstService {
public String demo();
}

4.编写service层实现类

 package org.bianqi.first.demo;

 import org.springframework.stereotype.Service;

 @Service
public class FirstServiceImpl implements FirstService{ public String demo(){
System.out.println("hhhhh");
return "helloworld我爱你";
}
}

在Controller中通过main方法启动~浏览器访问http://localhost:8080/ 显示helloworld 并且控制台打印hhhhh

上一篇:SharePoint2013的头像显示和读取


下一篇:unity iOS本地代码总结(一)