【发布时间】:2016-01-25 18:16:33
【问题描述】:
我正在尝试使用 Thymeleaf 模板和 springboot api 提供动态 html 页面。这是我想要实现的场景。
当有人提出以下请求时:hostname/client,另一方面,如果有人提出以下请求,应用程序将返回一个 Json 对象:hostname/client.html ,这个请求在不同的控制器中被捕获,以便我可以操作将返回的视图。
客户端控制器 这个类按预期工作,它返回一个 Json 对象
@RestController
public class ClientController {
@Autowired
public ClientService clientServiceImp;
@RequestMapping("/client")
public Client get(@RequestParam(value="name", defaultValue="World") String name){
return clientServiceImp.getClient(name);
}
}
家庭控制器 此类的方法不会将调用映射到 *.html
@Controller
public class HomeController {
@RequestMapping(value={"/*.html"}, produces="text/html")
public String getIndex(Model model, HttpServletRequest request){
// I will set here the thymeleaf fragment location based on the resource requested.
return "index";
}
*这是我在调用 hostname/client.html 后收到的错误 白标错误页面 *此应用程序没有显式映射 /error,因此您将其视为后备。 2016 年 1 月 25 日星期一 16:04:56 出现意外错误(类型=不可接受,状态=406)。 找不到可接受的代表**
Springboot基本配置
@SpringBootApplication(scanBasePackages = {"com.serviceira"})
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
重要的是要指出我没有为应用程序设置任何其他配置。提前感谢您的帮助。
【问题讨论】:
-
你需要为
.html设置servlet映射。你是用xml还是java配置
标签: java json spring-mvc thymeleaf