springboot+mybatis plus基础+IService

创建springboot项目:

1.pom文件:



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.2.6.RELEASE
         
    
    com.example
    demo111
    0.0.1-SNAPSHOT
    demo111
    Demo project for Spring Boot

    
        1.8
    

    
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            com.baomidou
            mybatis-plus-boot-starter
            3.0.1
        
        
            mysql
            mysql-connector-java
            5.1.34
        
        
        
        
            org.springframework.boot
            spring-boot-starter-jdbc
        
        
            org.springframework.boot
            spring-boot-starter
        

        
            org.projectlombok
            lombok
            true
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
            
                
                    org.junit.vintage
                    junit-vintage-engine
                
            
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    


2.controller:

package com.example.demo111.controller;


import com.example.demo111.Bean.Own;
import com.example.demo111.service.OwnSercvice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/Own")
public class OwnController {

    @Autowired
    private OwnSercvice ownSercvice;

    @GetMapping("sing")
    public void sing(){
        System.out.println("111111111");
        Own byId = ownSercvice.getById(1);
        System.out.println(byId);
    }

}

3.service:

package com.example.demo111.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.example.demo111.Bean.Own;

public interface OwnSercvice extends IService {
}

4.serviceImpl:

package com.example.demo111.service.impl;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo111.Bean.Own;
import com.example.demo111.mapper.OwnMapper;
import com.example.demo111.service.OwnSercvice;
import org.springframework.stereotype.Service;

@Service
public class OwnServiceImpl extends ServiceImpl implements OwnSercvice {

}

5.mapper:

package com.example.demo111.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo111.Bean.Own;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface OwnMapper extends BaseMapper {
}

6.

Demo111Application:
package com.example.demo111;

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

@SpringBootApplication
@MapperScan("com.example.demo111.mapper")
public class Demo111Application {

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

}

7.application.properties:

spring:
server.port=8091
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/shopping_house?characterEncoding=utf-8&autoReconnect=true&failOverReadOnly=false&useSSL=true
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

# ====================MybatisPlus====================

8.bean:
package com.example.demo111.Bean;

import lombok.Data;

@Data
public class Own {

    private Integer id;
    private String name;
    private char sex;
    private Integer year;
    private String address;
}

9表格数据库自建own

 

 

 

你可能感兴趣的:(Mybatis,Plus,mybatis,spring,boot,mybatisplus)