【发布时间】:2018-07-03 06:51:02
【问题描述】:
我正在尝试使用 REST 和休眠以 XML 格式获取国家/地区的详细信息。但是当点击下面的 URL 是我得到的错误。我已将请求中的标头接受正确设置为 xml。
The resource identified by this request is only capable of generating
responses with characteristics not acceptable according to the request
"accept" headers.
控制器
@RequestMapping(value = "/getAllCountries", method =
RequestMethod.GET,produces="application/xml",
headers = "Accept=application/xml")
public List<Country> getCountries() throws CustomerNotFoundException{
List<Country> listOfCountries = countryService.getAllCountries();
return listOfCountries;
}
型号
@XmlRootElement (name = "COUNTRY")
@XmlAccessorType(XmlAccessType.FIELD)
@Entity
@Table(name="COUNTRY")
public class Country{
@XmlAttribute
@Id
@Column(name="id")
@GeneratedValue(strategy=GenerationType.IDENTITY)
int id;
@XmlElement
@Column(name="countryName")
String countryName;
@XmlElement
@Column(name="population")
long population;
public Country() {
super();
}
服务
@Transactional
public List<Country> getAllCountries() {
return countryDao.getAllCountries();
}
道
public List<Country> getAllCountries() {
Session session = this.sessionFactory.getCurrentSession();
List<Country> countryList = session.createQuery("from Country").list();
return countryList;
}
有人可以帮忙吗..
【问题讨论】:
-
您的依赖项中有
Jackson吗? -
@Thomas 是的,我在依赖项中有杰克逊
标签: java xml spring hibernate rest