springboot整合springmvc时Controller层无法跳转到html页面,顺带解决页面不能调用resource下静态资源问题

先贴我的项目路径

springboot整合springmvc时Controller层无法跳转到html页面,顺带解决页面不能调用resource下静态资源问题_第1张图片

1、查找问题

 

前几天写了一个controller,一直没法通过地址跳转到course.html页面,报错,我查百度都说可能application启动类位置的问题,但我看了下我的项目结构,application启动类的确和我的controller包在同一级目录

springboot整合springmvc时Controller层无法跳转到html页面,顺带解决页面不能调用resource下静态资源问题_第2张图片

 

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;


@Controller
public class PageController {
    @RequestMapping("/courseadd")
    public String addCourse(){
        return "admin/course.html";
    }
    @GetMapping("/index")
    public String addIndex(){
        return "admin/index.html";
    }
}

 然后又看到可能没扫描到controller包的答案,于是我又顺带看了下我的启动类,嗯,也没问题

 

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan(basePackages = {"com.laoxu.spbone.entity","com.laoxu.spbone.dao","com.laoxu.spbone.bll","com.laoxu.spbone.controller"})
public class SpboneApplication {


    public static void main(String[] args) {

        SpringApplication.run(SpboneApplication.class, args);

    }

}

于是我把目光放在 application.properties文件,woc,我自己配置了上下文路径我自己给忘了,真是降智

springboot整合springmvc时Controller层无法跳转到html页面,顺带解决页面不能调用resource下静态资源问题_第3张图片

2、解决问题

ok,有了,但是现在resource下的js,css等文件不能加载,并没有被成功访问

springboot整合springmvc时Controller层无法跳转到html页面,顺带解决页面不能调用resource下静态资源问题_第4张图片

 

问了某位老哥,才知道改资源引用地址就OK,因为通过springmvc调用的页面都是从static包下开始引用的,所以不用返回admin上一级目录再调用其他资源


    
    Title
    
    
    
    
    

    
    
    
    

    
    
    
    

3、完美解决!!!

警告!!!

警告自己不能再犯这么蠢的错误了!!!!!

 

4.26更新补充

如果还是扫不到resource下的静态文件,就在pom下面加这些代码


      src/main/resources
      
      **/*.properties
      **/*.xml
      
      **/*.html
     **/*.js
     **/*.css
     **/*.png
     **/*.gif
     
     /static/
     
     false

 

你可能感兴趣的:(springboot,java,spring,boot,html,spring,springmvc)