第一步:创建一个简单的java项目,强烈建议使用maven来管理和构建项目

新手六步上手Springboot+SpringMVC+Mybatis项目

新手六步上手Springboot+SpringMVC+Mybatis项目

新手六步上手Springboot+SpringMVC+Mybatis项目

第二步:引入springboot相关的依赖包

引入springboot的WEB启动器组件
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

 

关于视图引模板引擎

  如果视图层选择用thymeleaf,则需要引入thymeleaf的依赖包:

  <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

如果选择jsp,需要加入jsp相关的包

    <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>jstl</artifactId>
          </dependency>
    
         <dependency>
             <groupId>org.apache.tomcat.embed</groupId>
             <artifactId>tomcat-embed-jasper</artifactId>
             <scope>provided</scope>
         </dependency>

引入数据库驱动包:

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>

 

数据库连接池可以选择用阿里的druid:

    <!-- druid 数据库连接池 -->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid</artifactId>
        <version>1.0.9</version>
    </dependency>

持久层框架引入:

    <!-- Mybatis 启动器-->
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.1.1</version>
    </dependency>

第三步:

 

 

 

第三步:配置启动类注解

在控制层所在包的上一级包下或者就在controller所在包下新建启动类,增加注解@Application

新手六步上手Springboot+SpringMVC+Mybatis项目

 

 

第四步:整合持久层框架mybatis

               在全局配置文件application.properties文件中加入Mybatis配置

新手六步上手Springboot+SpringMVC+Mybatis项目

              设计Mapper接口、创建实现mapper接口的xml文件

新手六步上手Springboot+SpringMVC+Mybatis项目

新手六步上手Springboot+SpringMVC+Mybatis项目

 

第五步:实现第一个Controller

               写一个controller,设置url映射方法及入口注解

新手六步上手Springboot+SpringMVC+Mybatis项目

新手六步上手Springboot+SpringMVC+Mybatis项目

第六步:

启动类中运行main方法运行项目。

新手六步上手Springboot+SpringMVC+Mybatis项目

 

好了,第一个springboot+springMVC+mybatis的项目框架就完成了,是不是很简单,当然对于有springMVC基础,熟悉mybatis的同学来说,该篇文章可以忽略;对于想开发java web项目的新手来说建议一步一步按照步骤动手实践会比较有意义。

 

相关文章:

  • 2021-11-17
  • 2022-12-23
  • 2021-07-06
  • 2022-12-23
  • 2021-10-28
  • 2022-01-20
  • 2021-11-05
猜你喜欢
  • 2021-06-01
  • 2022-12-23
  • 2022-02-10
  • 2021-08-07
  • 2021-10-01
  • 2021-04-16
  • 2021-11-05
相关资源
相似解决方案