springboot整合

前提配置,一切前提

一般都是自动导入

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.2.2</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

boot多了一个application.properties。很重要

二.application.properties

server.port:更改端口号

server.port= 8081
#?????
spring.datasource.username=root
spring.datasource.password=
spring.datasource.url=jdbc:mysql://localhost:3306/spring?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

sql mapper

<?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.jia.spring06.dao.UserDao">
    <insert id="updateInsert" parameterType="com.jia.spring06.pojo.User">
        insert into users (id,name,age) values(#{id},#{name},#{age});
    </insert>
    <select id="queryById" resultType="com.jia.spring06.pojo.User" parameterType="int">
        select *from users where id=#{id};
    </select>
    <delete id="updateDel" parameterType="int">
        delete from users where id=#{id};
    </delete>
    <select id="findNumbers" resultType="int">
        insert count(*) from users;
    </select>
    <select id="queryAll" resultType="com.jia.spring06.pojo.User">
        select *from users
    </select>
</mapper

三.启动类

@SpringBootApplication:核心注解,作用是开启自动配置,千万别改

 

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Spring06Application {

    public static void main(String[] args) {
        SpringApplication.run(Spring06Application.class, args);
    }

}

四.了解各层

  • domain:相当于实体类(entity),
  • service:业务代码
  • controller:控制层

其他的都和spring差不多,springboot完全就是玩注解

底层就是spring

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值