博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
springboot+mybatis项目搭建
阅读量:5287 次
发布时间:2019-06-14

本文共 4156 字,大约阅读时间需要 13 分钟。

 

一.idea创建一个springBoot项目

 

二.创建的目录结构

 

三.Pom.xml文件

<?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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
   
</parent>
    <groupId>com.example</groupId>
    <artifactId>springbootdemo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>springbootdemo</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jersey</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-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!--添加mybatis依赖-->
       
<dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.4</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.4.6</version>
        </dependency>
        <!--添加mysql依赖-->
       
<dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.15</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>5.1.3.RELEASE</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

四.application.properties文件#修改tomcat端口号

server.port=8088 #配制mysql数据库映射 spring.datasource.url=jdbc:mysql://127.0.0.1:3306/yz?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone = GMT spring.datasource.username=root spring.datasource.password=yzltz_0324 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver #配制mapper映射文件 mybatis.mapper-locations=classpath:/mappers/*.xml

 

五.SpringbootdemoApplication.java启动文件package com.example.springbootdemo;import org.mybatis.spring.annotation.MapperScan;

import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; @SpringBootApplication @MapperScan(basePackages = "com.example.springbootdemo.mapper.SpringBootTestMapper") public class SpringbootdemoApplication extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(SpringbootdemoApplication.class, args); } }

六.Controllerimport java.util.List;

@RestController public class SpringBootTest {
    @RequestMapping("/home") public String home() { return "Hello Spring Boot!"; } @Autowired private SpringBootTestService springBootTestService; @RequestMapping("/testList") public List
getTestList(){ List
list=springBootTestService.getTestList(); return list; }; }

七.Service

接口

public interface SpringBootTestService {
    public List
getTestList(); }

 

实现类

import java.util.List;

@Service

public class SpringBootTestServiceImpl implements SpringBootTestService {
    @Autowired     private SpringBootTestMapper springBootTestMapper;     @Override     public List
getTestList() {
        List
list=springBootTestMapper.getTestList();         return list;     } }

八.Mapper

import java.util.List; @Mapper public interface SpringBootTestMapper {
    public List
getTestList(); }

九.Mapper.xml

   
 
 
 
 

 

转载于:https://www.cnblogs.com/txf0324/p/11127238.html

你可能感兴趣的文章
C# JSON字符串序列化与反序列化
查看>>
推荐:全新Java开发思维导图
查看>>
[Selenium+Java] Find Element and Find Elements in Selenium
查看>>
JVM 知识点总览 - 高级 Java 工程师面试必备
查看>>
测试1
查看>>
CF 671D Roads in Yusland
查看>>
vue 新版本 webpack 代理 跨域设置
查看>>
最长回文( 模板 )
查看>>
UITableView
查看>>
sql语句学习
查看>>
给大家推荐常用的正则表达式
查看>>
【SAS ADVANCE】Performing Advanced Queries Using PROC SQL
查看>>
20165337第四周课上补做
查看>>
hexo基本操作
查看>>
mvc BundleConfig实现对Css、Js压缩打包加载
查看>>
day11
查看>>
8位、24位、32位图像数据转换
查看>>
XSBASE 270-S_裸机程序_流水灯
查看>>
手机扫描文字如何用软件识别
查看>>
收藏一些常用的methods
查看>>