关于Springboot-Mybatis无配置文件注解版的思考

本文探讨了Springboot集成Mybatis时如何避免使用配置文件,详细解析了无配置文件的Springboot-Mybatis项目的结构。内容包括:项目架构、配置文件仅保留application.properties,以及在UserMapper.java中使用注解实现DAO层操作。此外,还介绍了Springboot对Controller和TestController注解的理解,以及页面定位和静态资源目录。总结了Springboot+Mybatis的简化配置要点,并提到了使用Thymeleaf替代jsp的建议。
摘要由CSDN通过智能技术生成

        上一篇是搭建了一个springboot+mybatis的项目demo,我们发现,整个项目除了application.properties文件,其他配置文件,如mybatis-config.xml、mapper.xml都不需要,甚至数据库java配置类也不需要。非常的方便,但是这方便却来得稀里糊涂,另外搭建一个springboot+mybatis的方式非常多,但是这对于一个初学者而言,并不是一个好事,因为很容易弄混,所以本片旨在于弄清楚springboot集成mybatis时,该框架默认做了那些东西。本文还是拿上一篇文件的demo进行演示,具体搭建过程不在演示。

 1、springboot项目架构

2、整个项目除了pom.xml文件和application.properties文件外,没有其他配置文件。

      pom.xml文件内容(部分jar包没有用到,也还是加上去了):

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.xz</groupId>
    <artifactId>blog</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>blog</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <!-- spring版本号 -->
        <spring.version>5.0.8.RELEASE</spring.version>
    </properties>

    <dependencies>
        <!-- 单元测试 -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.2</version>
        </dependency>

        <!-- JSTL (JSP standard Tag Library) JSP 标准标签库 -->
        <dependency>
            <groupId>javax.servlet</groupId>
        
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值