spring-boot配置
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.17.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
- @RequestMapping注解返回的是一个跳转路径,需再加一个@ResponseBody转成json对象
- @RestController注解,可以换成@Controller注解 1.2配合使用
- 注意@SpringBootApplication注解只会扫描相同包或者子包的类下的注解
@RestController
@SpringBootApplication
public class Example {
@RequestMapping("/")
String home() {
return "Hello World!";
}
@RequestMapping("/mp")
HashMap home1() {
HashMap hm = new HashMap();
hm.put("id", 99);
return hm;
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Example.class, args);
}
}