我正在跟踪有关REST服务的小练习。
我使用的是Spring 2.0.3.RELEASE和tomcat 7。
问题:应用程序的提示不返回任何内容
控制器
@RestController
@RequestMapping("/persons")
public class PersonController {
@Autowired
PersonService ps;
@RequestMapping("/all")
public List<Person> getAll() {
return ps.getAll();
}
@RequestMapping("{id}")
public Person getPerson(@PathVariable("id") Long id) {
return ps.getPerson(id);
}
}
这是PersonService类
@Service
public class PersonService {
@Autowired
DataSource dataSource;
@Autowired
PersonRepositoryInterface personRepository;
public PersonService()
{
}
public Person getPerson(Long id)
{
return personRepository.findOne(id);
}
public List<Person>getAll()
{
return (ArrayList<Person>) personRepository.findAll();
}
}
这是PersonRepositoryInterface接口
public interface PersonRepositoryInterface extends CrudRepository<Person,Long> {
List<Person>findByAge(int Age);
List<Person>findByFirstName(String firstname);
@Query(" from Person p where p.id=:x")
public Person findOne(@Param("x") Long id);
}
该班级人员具有字段id,firstName,lastName作为属性。
当然,数据库中有一些记录,运行代码时没有错误
生成的日志结尾。数据库连接没有问题
Tomcat started on port(s): 8080 (http) with context path ''
Started WebservicesApplication in 8.93 seconds (JVM running for 9.89)
Application shutdown requested.
Closing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@1afa13b: startup date [Thu Aug 02 22:22:40 CEST 2018]; root of context hierarchy
Unregistering JMX-exposed beans on shutdown
Unregistering JMX-exposed beans
Closing JPA EntityManagerFactory for persistence unit 'default'
HHH000031: Closing
External cascade style registration [persist : STYLE_PERSIST] overrode base registration [STYLE_PERSIST_SKIPLAZY]
Implicitly destroying ServiceRegistry on de-registration of all child ServiceRegistries
Implicitly destroying Boot-strap registry on de-registration of all child ServiceRegistries
HikariPool-1 - Shutdown initiated...
HikariPool-1 - Shutdown completed.