springboot项目创建:

1,创建一个maven项目:

在这里插入图片描述

2,在pom.xml引入相关依赖:

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

    <!--mybatis依赖-->
    <dependency>
      <groupId>org.mybatis.spring.boot</groupId>
      <artifactId>mybatis-spring-boot-starter</artifactId>
      <version>2.1.0</version>
    </dependency>

    <!--mysql驱动-->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.39</version>
    </dependency>


 <!--引入parent-->
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.2.RELEASE</version>
  </parent>

3,相关架构:

在这里插入图片描述

4,启动类SpringBootApp:

package com.xwb;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * 启动类
 *
 */
@SpringBootApplication
@MapperScan("com.xwb.Mapper")//批量扫描
public class SpringBootApp
{
    public static void main( String[] args )
    {
        SpringApplication.run(SpringBootApp.class,args);
    }
}

5,配置数据源(application.yml)

spring:
  # 配置数据源
  datasource:
#  数据库驱动的全限定名
    driver-class-name:  com.mysql.jdbc.Driver
#    数据库JDBC连接
    url:  jdbc:mysql://localhost:3305/javatest?useSSL=false
#    用户名
    username: root
    password: 123456

mybatis:
# XML配置文件的位置
  mapper-locations: classpath:Mapper/*.xml

6,创建于数据库相应的pojo类(student):

package com.xwb.pojo;

public class Student {
    private Integer SID;
    private String Sname;
    private Integer Sage;
    private String Ssex;

    public Integer getSID() {
        return SID;
    }

    public void setSID(Integer SID) {
        this.SID = SID;
    }

    public String getSname() {
        return Sname;
    }

    public void setSname(String sname) {
        Sname = sname;
    }

    public Integer getSage() {
        return Sage;
    }

    public void setSage(Integer sage) {
        Sage = sage;
    }

    public String getSsex() {
        return Ssex;
    }

    public void setSsex(String ssex) {
        Ssex = ssex;
    }

    @Override
    public String toString() {
        return "Student{" +
                "SID=" + SID +
                ", Sname='" + Sname + '\'' +
                ", Sage=" + Sage +
                ", Ssex='" + Ssex + '\'' +
                '}';
    }
}

7,实现相应的Mapper层接口(studentMapper):

package com.xwb.Mapper;

import com.xwb.pojo.Student;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Component;

import java.util.List;


@Mapper
@Component
public interface StudentMapper {
    public List<Student> selectAllStudents();
}

8,配置相应的XML文件:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.xwb.Mapper.StudentMapper">
    <select id="selectAllStudents" resultType="com.xwb.pojo.Student">
    select * from student
 </select>

</mapper>

9,实现service层(studentService):

package com.xwb.Service;

import com.xwb.Mapper.StudentMapper;
import com.xwb.pojo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentService {
    @Autowired
    private StudentMapper studentMapper;

    public List<Student> findAll(){
        return studentMapper.selectAllStudents();
    }
}

10,实现Controller层(StudentService):

package com.xwb.Controller;

import com.xwb.Service.StudentService;
import com.xwb.pojo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class StudentController {
    @Autowired
    private StudentService studentService;
    @RequestMapping("/list")
    @ResponseBody
    public List<Student> list(){
        return studentService.findAll();
    }


}

11,运行查看:

在这里插入图片描述
输入端口号和相应的URL在浏览器中查看:
在这里插入图片描述
数据库表:
在这里插入图片描述