Spring Boot(二)-整合mybatis,mvc,freemarker
在创建好的springboot项目中进行配置:
一:添加maven依赖
<!-- mybatis --> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.1.1</version> </dependency> <!-- mysql --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.21</version> </dependency> <!-- tomcat的支持.--> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <!-- freemarker的支持--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency>
二:配置application.yml
springboot项目创建好是:application.properties空文件。
我们需要将application.properties改为application.yml
创建好之后添加配置:
spring: # spring mvc mvc: view: prefix: /templates/ suffix: .html # freemarker freemarker: cache: false request-context-attribute: request template-loader-path: classpath:/templates prefix: suffix: .html # 数据源 datasource: url: jdbc:mysql://localhost:3306/luck username: root password: 123456 driver-class-name: com.mysql.jdbc.Driver jpa: hibernate: ddl-auto: update # mybatis配置 mybatis: mapper-locations: classpath*:sqlmap/*Mapper.xml type-aliases-package: com.luck.pojo
注意:上面的配置根据我自己项目配置,比如路径:classpath:/templates
三:添加mybatis相关文件:
若不会mybatis逆向生成文件请参考这篇文章:https://blog.csdn.net/qq_37751454/article/details/80647674
-----------------------
下图是我的项目结构:
四:执行
执行springhwbapplication里的main方法即可运行!
*****************
项目已放到github上欢迎下载:https://github.com/luckhwb/spring-boot
有什么问题可以交流下,谢谢!!
https://github.com/luckhwb/spring-boot.git