springboot+mybatis-plus+mysql搭建开发环境

 

工具:idea

环境:java8

 

完整项目下载地址:点我下载

 

第一步:创建springboot项目

 

因时间为题,直接上图,不再一一描述,不懂的在下面留言

 

springboot+mybatis-plus+mysql搭建开发环境_第1张图片

 

springboot+mybatis-plus+mysql搭建开发环境_第2张图片

springboot+mybatis-plus+mysql搭建开发环境_第3张图片

springboot+mybatis-plus+mysql搭建开发环境_第4张图片

springboot+mybatis-plus+mysql搭建开发环境_第5张图片

springboot+mybatis-plus+mysql搭建开发环境_第6张图片

 

至此,创建完成一个springboot项目,并且导入了所需的 引用

 

UserController.java 文件内容:

package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.service.UserService;
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;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping
    public List find(){

        List list = userService.list();
        return list;
    }
}

User.java 文件内容:

package com.example.demo.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.io.Serializable;

@Data
@TableName("sys_user")
public class User implements Serializable {

    @TableId("id")
    private String id;

    @TableField("name")
    private String name;

    @TableField("age")
    private String age;

}

UserMapper 

package com.example.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.entity.User;

public interface UserMapper extends BaseMapper {
}

 UserServiceImp 

package com.example.demo.service.imp;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.User;
import com.example.demo.mapper.UserMapper;
import com.example.demo.service.UserService;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImp extends ServiceImpl implements UserService {


}

UserService 

package com.example.demo.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.example.demo.entity.User;

public interface UserService extends IService {
}

 DemoApplication 

package com.example.demo;

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

@SpringBootApplication
@MapperScan("com.example.demo.mapper")
public class DemoApplication {

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

}

 mapper







    
    
        
        
        
    

    

配置文件

server:
  port: 8082


mybatis-plus:
  type-aliases-package: com.example.demo.entity
  mapper-locations: classpath:/mapper/*Mapper.xml

spring:
  datasource:
    url: jdbc:mysql://192.168.0.198:3306/irule
    username: root
    password: iceter
    driver-class-name: com.mysql.jdbc.Driver



 

至此项目搭建完毕。

未测试,有问题请在下面留言

访问地址:http://192.168.0.49:8082/user 已测试,可用

 

springboot+mybatis-plus+mysql搭建开发环境_第7张图片

你可能感兴趣的:(spring,boot)