首先,我们要知道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,可进行下载看简单的操作