MybatisPlus-快速集成并使用

STS快速创建SpringBoot项目
这里补充一下:
我这里STS创建的SB项目,配置的阿里的maven仓库,一直没法创建BootVerison大于1.5的后来换成了默认的仓库才可以创建大于1.5版本的SB项目,
改成默认镜像以后Pom文件可能会报错,
以下为解决办法:

1.help ->Install New Software -> add ->https://otto.takari.io/content/sites/m2e.extras/m2eclipse-mavenarchiver/0.17.2/N/LATEST
PS:点击 next 前,将 eclipse Install 窗口右下角的 Contact all update sites during install to find required software 选项取消掉。
2.一直next confirm 安装更新 提示重启eclipse 然后再右键项目maven update project

创建成功以后简单测试:
application.yml

server:
  address: 
  port: 80
spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/demo?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
    username: root
    password: root

启动类


@SpringBootApplication
@MapperScan("com.config.code.dao")
public class DemoApplication {

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

}

User对象 (小辣椒插件)

package com.config.code.pojo;

import lombok.Data;

@Data
public class User {
    private Long id;
    private String name;
    private Integer age;
    private String email;
	@Override
	public String toString() {
		return "User [id=" + id + ", name=" + name + ", age=" + age + ", email=" + email + "]";
	}
    
}

usermapper

package com.config.code.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.config.code.pojo.User;

public interface UserMapper extends BaseMapper {

}

Controller

package com.config.code;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.config.code.dao.UserMapper;
import com.config.code.pojo.User;

@Controller
public class Index {
@Autowired
UserMapper userMapper;
	@RequestMapping("/index")
	public String name() {
		List selectList = userMapper.selectList(null);
		for (User user : selectList) {
			System.err.println(user);
		}
		return "";
	}
}

pom



	4.0.0
	
		org.springframework.boot
		spring-boot-starter-parent
		2.2.0.M2
		 
	
	com.example
	demo
	0.0.1-SNAPSHOT
	war
	demo
	Demo project for Spring Boot

	
		1.8
	

	
		
			org.springframework.boot
			spring-boot-starter-web
		

		
			org.springframework.boot
			spring-boot-starter-tomcat
			provided
		
		
			org.springframework.boot
			spring-boot-starter-test
			test
		
		
		
		   
        		org.springframework.boot
       		 	spring-boot-starter
   		 	
		
		 
        org.projectlombok
        lombok
        true
    
    
        
        com.baomidou
        mybatis-plus-boot-starter
        3.1.1
    
    
    
			mysql
			mysql-connector-java
			runtime
		
	

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

	
		
			spring-snapshots
			Spring Snapshots
			https://repo.spring.io/snapshot
			
				true
			
		
		
			spring-milestones
			Spring Milestones
			https://repo.spring.io/milestone
		
	
	
		
			spring-snapshots
			Spring Snapshots
			https://repo.spring.io/snapshot
			
				true
			
		
		
			spring-milestones
			Spring Milestones
			https://repo.spring.io/milestone
		
	



你可能感兴趣的:(MybatisPlus)