私は作成している基本的な春の起動アプリケーションを持っていますが、/ admin/のURLを与える管理コントローラがあります。私の問題は、このURLが/の代わりに/ adminをURLの先頭に付けて静的リソースにアクセスする方法を変更することです。コントローラでベースURLを使用している場合、静的リソースはもう利用できません
/** URLから/ admin/** URLから静的リソースにアクセスできるようにするにはどうすればよいですか?
エラーを返す例要求: リクエストの上http://localhost:8080/admin/css/bootstrap.min.css
をGETは、この要求に動作します: http://localhost:8080/css/bootstrap.min.css
をGETしかし、私はThymeleafにプレフィックスを削除するには良い、ダイナミックな解決策を知りませんまたは春。本当にすべてのHTMLページに異なるものを追加する必要はありません。私が私のWebMvcConfigurerAdapterにこれを追加
@Controller
@RequestMapping("/admin")
public class AdminController {
@Autowired
ModelAndViewService modelAndViewService;
@RequestMapping(value = "/developer", method = RequestMethod.GET)
public String developer(Model model, Authentication authentication) {
modelAndViewService.developerList(model,authentication);
return "admin/developerList";
}
}
:
<link href="../../static/css/bootstrap.min.css"
th:href="@{css/bootstrap.min.css}" rel="stylesheet"/>
私は私のコントローラにURLを前置しています方法:どのように私はHTMLページに私のリソースにアクセスしていますが
問題を解決しようとします。
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**","/admin/**")
.addResourceLocations("/resources/");
}
ご協力いただければ幸いです!簡単な修正だと思っています。