• SpringMVC+Spring+mybatis 项目实践


    创建Maven项目

     项目创建完成后导入相关文件

     配置相关依赖

    <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.3.1.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
        <groupId>com.example</groupId>
        <artifactId>Demo</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>Demo</name>
        <description>Demo project for Spring Boot</description>
    
        <properties>
            <java.version>1.8</java.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.mybatis.spring.boot</groupId>
                <artifactId>mybatis-spring-boot-starter</artifactId>
                <version>2.1.3</version>
            </dependency>
    
            <dependency>
                <groupId>tk.mybatis</groupId>
                <artifactId>mapper-spring-boot-starter</artifactId>
                <version>2.1.4</version>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-devtools</artifactId>
                <scope>runtime</scope>
                <optional>true</optional>
            </dependency>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <optional>true</optional>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
                <exclusions>
                    <exclusion>
                        <groupId>org.junit.vintage</groupId>
                        <artifactId>junit-vintage-engine</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
    
            <dependency>
                <groupId>com.microsoft.sqlserver</groupId>
                <artifactId>mssql-jdbc</artifactId>
                <scope>runtime</scope>
            </dependency>
    
            <!-- 使用 jsp 必要依赖 -->
            <dependency>
                <groupId>org.apache.tomcat.embed</groupId>
                <artifactId>tomcat-embed-jasper</artifactId>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>jstl</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-thymeleaf</artifactId>
                <version>2.3.1.RELEASE</version>
            </dependency>
    
        </dependencies>
        <pluginRepositories>
            <pluginRepository>
                <id>alimaven spring plugin</id>
                <name>alimaven spring plugin</name>
                <url>https://maven.aliyun.com/repository/spring-plugin</url>
            </pluginRepository>
        </pluginRepositories>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <version>2.3.1.RELEASE</version>
                </plugin>
            </plugins>
        </build>

    配置数据库

    配置显示页面

     

     添加一个mybatis的mapper库

     修改servlet代码

     运行:

     

    效果和MVC2项目相同

     

     

     

     码云地址:https://gitee.com/xmr123/JAVAEE/tree/feature-SSM

  • 相关阅读:
    修改CentOS 6.4 root用户的系统默认语言设置
    Xpages学习
    Mysql 执行sql脚本文件
    Errors occurred during the build. Errors running builder 'JavaScript Validator' on project 'XXX'.
    【鸟哥学习笔记】之一:目录的权限问题
    学习C++的一些问题总结
    C# 一些知识点总结(一)_继承,多态,集合,关键字...
    .NET Framework 框架的一些简单介绍
    Winform窗体关闭时判断是否关闭
    SQL Server 数据库的安全管理(登录、角色、权限)
  • 原文地址:https://www.cnblogs.com/543123abcxmr/p/13196623.html
Copyright © 2020-2023  润新知