使用idea创建springboot项目并搭建MVC框架的配置

新建Spring Initializr项目,项目名称为:Test,勾选引入Web、Mysql、Mybatis包,使用maven进行依赖管理,然后进行如下配置:

1、在java目录下新建controller(使用@Controller注解)、service接口和service实现类(使用@Service注解)、dao接口(使用@Mapper注解)、model,在resources目录下新建mapper.xml文件;

2、在TestApplication配置mapper扫描器:@MapperScan("com.xx.xx.dao");

3、在application.properties配置文件中配置数据库连接信息和mybatis相关配置

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver  //注意:com.mysql.jdbc.Driver已不建议使用

spring.datasource.url=jdbc:mysql://localhost:3306/mysql?characterEncoding=utf-8&serverTimezone=UTC

spring.datasource.username=root

spring.datasource.password=


mybatis.mapper-locations=classpath:mapper/*.xml   //配置mapper文件的位置

mybatis.configuration.map-underscore-to-camel-case=true  //开启驼峰命名

mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl  //输出日志到控制台

你可能感兴趣的:(使用idea创建springboot项目并搭建MVC框架的配置)