【发布时间】:2017-11-02 10:07:41
【问题描述】:
我有一个 MainController,它是一个 RestController,它使用单独的类 (CommandInterpreter.java) 中的 java 代码按价格顺序获取车辆列表。运行时,'/vehicles-by-price' 已经显示了我要格式化的列表。我想获取返回的列表并将其格式化为表格,但我不确定如何执行此操作。
我目前在主页上显示的“资源/静态”中有一个 index.html。有没有办法为“/vehicles-by-price”页面制作一个 html 文件以显示传递给它的列表(或我可以在 html 中使用的 js 文件)以显示在表格中?
我是 Spring 新手,因此文件的任何代码/必要结构都会有所帮助!
主控制器:
@RestController
public class MainController {
//Get CommandInterpreter object
private CommandInterpreter ci = new CommandInterpreter();
private List<Vehicle> vehicles;
MainController () throws Exception {
//Set up list of vehicles from JSON
vehicles = ci.parseJsonVehicles();
}
@RequestMapping("/vehicles-by-price")
public List<Vehicle> getVehiclesByPrice() {
vehicles = ci.getVehiclesByPrice(vehicles);
return vehicles;
}
}
【问题讨论】:
标签: java html spring spring-boot spring-restcontroller