栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

IDEA配置database插件及Mybatisx插件的使用

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

IDEA配置database插件及Mybatisx插件的使用

一、配置

进入IDEA后选择 File-->Setting-->Plugins

选择Marketplace,输入Database,点击Insall进行下载

如果一直转圈,请借鉴IDEA 离线安装插件_程序员柒七的博客-CSDN博客_idea离线安装插件

下载后配置Database

1.先配置对应数据库的包 

2.配置时区:在"Advanced"标签页"VM options"增加:-Duser.timezone=PRC

 3.添加数据库

其中Url:

Mysql 8  url为:其中test为数据库名

jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC

Mysql 5 url为:其中test为数据库名

jdbc:mysql://localhost:3306/test

4.配置成功效果

 二、使用

1.安装Mybaisx插件

选择Marketplace,输入Mybatisx,点击Insall进行下载

2.选择要生成的数据库表 

 3.填写下面信息

4.自动生成结果

5.UserService集成IService报错因为缺少依赖 通过AIt+Enter 进行添加依赖 (一般很少出现)

6.测试

(1)配置pom和yml文件

        pom:


        
        
            com.baomidou
            mybatis-plus-boot-starter
            3.4.2
        
        
        
            org.springframework.boot
            spring-boot-starter-jdbc
        

        
        
            org.springframework.boot
            spring-boot-starter-thymeleaf
        
        
        
            org.springframework.boot
            spring-boot-starter-web
        
        
        
            mysql
            mysql-connector-java
            runtime
        
        
        
            org.projectlombok
            lombok
            true
        
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
            
                
                    org.junit.vintage
                    junit-vintage-engine
                
            
        
        
            junit
            junit
            test
        
    

 

        
            
                src/main/java
                
                    ***.properties
                    ***.yml
                    ***.xml
                
                false
            
        
    

        yml:

spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/hms?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8
    username: root
    password: root
  thymeleaf:
    cache: false  #设置为false,否则会有缓存,导致页面没法及时看到更新后的效果。
#修改端口号默认是8080
server:
  port: 8888
#mybatis-plus相关配置
mybatis-plus:
  mapper-locations: classpath:mapper/*.xml #扫描mapper下的所有xml文件
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  type-aliases-package: com.zwl.entity   #扫描实体类包、配置别名

        controller:

import com.zwl.entity.User;
import com.zwl.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/user")
    public List users(){
        List userList=userService.selectList();
        return userList;
    }
}

UserService和UserServiceImpl:

import com.zwl.entity.User;
import com.baomidou.mybatisplus.extension.service.IService;

import java.util.List;

public interface UserService extends IService {

    List selectList();
}
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zwl.entity.User;
import com.zwl.service.UserService;
import com.zwl.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl
    implements UserService{
    @Autowired
    private UserMapper userMapper;
    @Override
    public List selectList() {
        return userMapper.selectList();
    }
}

        UserMapper:

import com.zwl.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import java.util.List;

public interface UserMapper extends BaseMapper {

    List selectList();

}

        UserMapper.xml





    
            
            
            
            
            
    

    
        id,name,password,
        phone,state
    
    

运行结果出现所有信息证明配置成功!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/933139.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号