【发布时间】:2016-01-17 20:14:48
【问题描述】:
我正在做这个简单的工作我的任务是添加一个新的 REST api 我继续创建了一个新控制器,我可以在其中从 sql 文件中检索所有数据。但是,我一直在获取酒店列表。谢谢。
这是我的代码:
控制器:
package sample.data.jpa.web;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import sample.data.jpa.domain.City;
import sample.data.jpa.domain.Hotel;
import sample.data.jpa.domain.HotelSummary;
import sample.data.jpa.domain.Review;
import sample.data.jpa.service.CityService;
import sample.data.jpa.service.CityRepository;
import sample.data.jpa.service.HotelService;
@Controller
class HotelController {
@Autowired(required = true)
private CityRepository cityRepository;
@Autowired(required = true)
private CityService cityService;
private HotelService hotelService;
private City cityObject;
private Hotel hotelObject;
@RequestMapping(value = "/getAllData")
@ResponseBody
@Transactional(readOnly = true)
Iterable<City> getAllData() {
return this.cityRepository.findAll();
}
@RequestMapping(value = "/new")
@ResponseBody
@Transactional(readOnly = true)
Iterable<Hotel> getBestHotelsWithBestRatings() {
return this.hotelService.getHotel(cityObject, name);
}
}
【问题讨论】:
标签: java spring spring-mvc jpa spring-boot