进入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-starter3.4.2 org.springframework.boot spring-boot-starter-jdbcorg.springframework.boot spring-boot-starter-thymeleaforg.springframework.boot spring-boot-starter-webmysql mysql-connector-javaruntime org.projectlombok lomboktrue org.springframework.boot spring-boot-starter-testtest org.junit.vintage junit-vintage-enginejunit junittest 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 ServiceImplimplements 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
运行结果出现所有信息证明配置成功!



