zoukankan      html  css  js  c++  java
  • SpringBoot中的RequesMapping两层路径时html中会无法加载样式

    在list.html页面中使用/templates/emp 请求跳转到add.html页面中如果在Controller中写的是两层路径则无法加载样式。

    list.html

    <div class="container-fluid">
    			<div class="row">
    				<!--引入侧边栏-->
    				<div th:replace="commons/bar::#sidebar(activeUri='emps')"></div>
    
    				<main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
    					<h2><a class="btn btn-sm btn-success" href="" th:href="@{/templates/emp}">员工添加</a></h2>
    					<div class="table-responsive">
    						<table class="table table-striped table-sm">
    							<thead>
    								<tr>
    									<th>#</th>
    									<th>lastName</th>
    									<th>email</th>
    									<th>gender</th>
    									<th>department</th>
    									<th>birth</th>
    									<th>操作</th>
    								</tr>
    							</thead>
    

    add.html

    <!DOCTYPE html>
    <!-- saved from url=(0052)http://getbootstrap.com/docs/4.0/examples/dashboard/ -->
    <html lang="en" xmlns:th="http://www.thymeleaf.org">
    
    	<head>
    		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    		<meta name="description" content="">
    		<meta name="author" content="">
    
    		<title>Dashboard Template for Bootstrap</title>
    		<!-- Bootstrap core CSS -->
    		<link href="asserts/css/bootstrap.min.css"  rel="stylesheet">
    
    		<!-- Custom styles for this template -->
    		<link href="asserts/css/dashboard.css"  rel="stylesheet">
    
    
    <!--		<style type="text/css">-->
    <!--			/* Chart.js */-->
    <!--			-->
    <!--			@-webkit-keyframes chartjs-render-animation {-->
    <!--				from {-->
    <!--					opacity: 0.99-->
    

    EmployeeController.java

    
    @Controller
    public class EmployeeController {
    
        @Autowired
        private EmployeeDao employeeDao;
    
        // 查询所有的用户信息
        @GetMapping(value = "/emps")
        public String employees(Model model){
            Collection<Employee> employees = employeeDao.getAll();
            model.addAttribute("emps",employees);
            return "emp/list";
        }
    
        //
        @GetMapping(value = "/templates/emp")
        public String toAddPage(){
            return "emp/add";
        }
    
    }
    

    解决方法:

    1.将list.html和Controller中的路径改为一层/emp

    2.将add.html中的加载css路径改为

    		<link href="/asserts/css/bootstrap.min.css"  rel="stylesheet">
    或者
    		<link href="../asserts/css/bootstrap.min.css"  rel="stylesheet">
    		<!-- Custom styles for this template -->
    		<link href="/asserts/css/dashboard.css"  rel="stylesheet">
    或者
    		<link href="../asserts/css/dashboard.css"  rel="stylesheet">
    
    知之为知之,不知为不知
  • 相关阅读:
    MySQL数据库的主从同步
    学习Java必看的Java书籍(高清中文最新版附下载链接)
    servlet重点知识总结
    JUnit & JMockit单元测试
    mongodb重点知识总结
    Quartz学习总结
    IDEA使用总结
    bat脚本知识总结
    linux shell脚本相关知识
    SpringMVC重点知识总结
  • 原文地址:https://www.cnblogs.com/bevishe/p/14243765.html
Copyright © 2011-2022 走看看