SpringBoot集成thymaleaf+layui+swagger2中遇到的问题

首先,我们要知道Springboot默认是不支持JSP的,默认使用thymeleaf模板引擎。以下是我在使用的过程中遇到的一些问题:

1、Field empMapper in com.test.service.EmployeeService required a bean of type 'com.test.mapper.EmployeeMapper' that could not be found.

解决方法:需要在SpringBoot的启动类上添加@MapperScan注解

扩展:SpringBoot编写 启动类、Controller、Service、Mapper需要的注解:

2、关于swagger2如何使用,请参考:Spring Boot中使用Swagger2构建RESTful API文档

但是在SpringBoot中进行编写controller、service、mapper时,使用swagger2遇到了以下问题:

据目前来看,是因为在SpringBoot的启动类上添加了扫描包的注解引起的:

解决方法:在SpringBoot的启动类上添加@EnableSwagger2注解即可。

3、SpringBoot中文件结构及如何访问html文件

文件结构:

通过Controller访问html文件:

  • 在application.properties中进行如下配置:
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.servlet.content-type=text/html
spring.thymeleaf.cache=false
  • 编写controller中的映射:跳转到templates下的index_page.html页面
    @RequestMapping("/index")
    public ModelAndView getIndex(){
        ModelAndView modelAndView=new ModelAndView();

        modelAndView.setViewName("index_page");
        return modelAndView;
    }

 4、引用静态文件Failed to load resource: the server responded with a status of 404 ()

解决办法:在启动类中配置静态访问资源

5、在启动类上配置了静态访问资源之后,Swagger2又被拦截,出现如下问题:

解决办法:在启动类上添加如下来解决跨域问题:

我自己联系的代码在:https://github.com/hedanning/learn_layUI,可进行下载看简单的操作

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值