IDEA创建SpringBoot项目并集成Mybatis

系列文章目录

提示:这里可以添加系列文章的所有文章的目录,目录需要自己手动添加
例如:


文章目录

  • 系列文章目录
  • 前言
  • 一、通过IDEA创建一个完整的springboot项目
    • 1.File-->New-->Project;
    • 2.选择Spring Initializr并配置项目信息,最后添加依赖并finish;
    • 2.添加application.properties配置中mybatis的相关配置(否则会报错);
    • 3.添加webapp目录(File->Project Structrue),添加路径\src\main\webapp;
    • 4.添加相应的controller代码和jsp页面代码,目录结构如下;
    • 5.pom.xml里添加相关依赖;
  • 总结


前言

提示:这里可以添加本文要记录的大概内容:

例如:。


提示:以下是本篇文章正文内容,下面案例可供参考

一、通过IDEA创建一个完整的springboot项目

1.File–>New–>Project;

2.选择Spring Initializr并配置项目信息,最后添加依赖并finish;

IDEA创建SpringBoot项目并集成Mybatis_第1张图片
IDEA创建SpringBoot项目并集成Mybatis_第2张图片

2.添加application.properties配置中mybatis的相关配置(否则会报错);

#1.端口
server.port=8088
#2.mysql配置信息
spring.datasource.url=jdbc:mysql://localhost:3306/testkey?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=123456
#3.jsp调用相关
spring.mvc.view.prefix=/
spring.mvc.view.suffix=.jsp

3.添加webapp目录(File->Project Structrue),添加路径\src\main\webapp;

IDEA创建SpringBoot项目并集成Mybatis_第3张图片

4.添加相应的controller代码和jsp页面代码,目录结构如下;

IDEA创建SpringBoot项目并集成Mybatis_第4张图片

5.pom.xml里添加相关依赖;


<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0modelVersion>
    <parent>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-parentartifactId>
        <version>2.7.3version>
        <relativePath/> 
    parent>
    <groupId>host.wangkaigroupId>
    <artifactId>springbootDemoartifactId>
    <version>0.0.1-SNAPSHOTversion>
    <name>springbootDemoname>
    <description>springbootDemodescription>
    <properties>
        <java.version>1.8java.version>
    properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-webartifactId>
        dependency>
        <dependency>
            <groupId>org.mybatis.spring.bootgroupId>
            <artifactId>mybatis-spring-boot-starterartifactId>
            <version>2.2.2version>
        dependency>

        <dependency>
            <groupId>mysqlgroupId>
            <artifactId>mysql-connector-javaartifactId>
            <scope>runtimescope>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-testartifactId>
            <scope>testscope>
        dependency>



        
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-tomcatartifactId>
            <scope>providedscope>
        dependency>
        <dependency>
            <groupId>org.apache.tomcat.embedgroupId>
            <artifactId>tomcat-embed-jasperartifactId>
        dependency>
        <dependency>
            <groupId>javax.servletgroupId>
            <artifactId>jstlartifactId>
            <scope>providedscope>
        dependency>
        <dependency>
            <groupId>javax.servletgroupId>
            <artifactId>javax.servlet-apiartifactId>
            <scope>providedscope>
        dependency>
        <dependency>
            <groupId>org.apache.tomcat.embedgroupId>
            <artifactId>tomcat-embed-jasperartifactId>
            <scope>providedscope>
        dependency>
        
        <dependency>
            <groupId>taglibsgroupId>
            <artifactId>standardartifactId>
            <version>1.1.2version>
        dependency>
    dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-maven-pluginartifactId>
                <version>1.4.2.RELEASEversion>
                <configuration>
                    <mainClass>host.wangkai.springbootdemo.SpringbootDemoApplicationmainClass>
                configuration>
            plugin>
        plugins>

        <resources>
            
            <resource>
                
                <directory>src/main/webappdirectory>
                
                <targetPath>META-INF/resourcestargetPath>
                <includes>
                    <include>**/**include>
                includes>
                <filtering>falsefiltering>
            resource>
            <resource>
                
                <directory>src/main/resourcesdirectory>
                <includes>
                    <include>**/**include>
                includes>
                <filtering>falsefiltering>
            resource>
        resources>
    build>

project>

至此暂时可以调起页面;
IDEA创建SpringBoot项目并集成Mybatis_第5张图片


总结

提示:这里对文章进行总结:

例如:以上就是今天要讲的内容。

你可能感兴趣的:(JavaWeb,mybatis,spring,boot,java)