pom.xml文件,配置了需要导入的jar文件
org.springframework.boot spring-boot-starter-parent 1.3.3.RELEASE org.springframework.boot spring-boot-starter-web
Controller
package com.solr.boot.user.controller;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;import com.solr.boot.user.domain.User;@RestController@EnableAutoConfigurationpublic class UserController { @RequestMapping("/user/{id}") public User unique(@PathVariable Long id){ if(id==1){ User user = new User(); user.setId(id); user.setName("Heinrich"); return user; } return null; } public static void main(String[] args) { SpringApplication.run(UserController.class, args); }}
为什么用@RestController,因为他是包含了 和 @RespenseBody,现在运行就可以了