前言

本篇文章主要介绍的关于本人在使用IDEA的一些使用方法,一些常用设置,一些插件推荐和使用。请注意,本文特长,2w多字加上几十张图片,建议收藏观看~

前提准备

idea官网: https://www.jetbrains.com/idea/

如果是学生的话,可以在idea直接申请使用;

如果在GitHub上面有持续维护的开源项目话,也可以进行申请使用;

如果有条件的话,可以支持一下正版。

破解版以及说明

链接:https://pan.baidu.com/s/1v0N0pd20LNbMgsK6ItJnLA
提取码:qvam

IDEA基本设置

编码设置

FILE ->Settings->Editor->File Encodings设置以下:
IDE Encondings:IDE编码 ,设为UTF8
Project Encoding:项目编码,设为UTF8
Default encoding for properties files:默认文件编码,设为UTF8

IDEA设置JDK

1.导入JDK

打开IDEA之后,点击File →Project Struture ,然后点击SDK,选择JDK路径,导入就行

2.默认JDK

File-Other Settings-> Default Project Structure-> project

选择JDK版本

3.项目设置JDK

File-Settings-> Build,Execution, Deployment -> Compiler -> Java Compiler

选择JDK的版本就行

Maven 设置

1.打开-File-Settings 搜索Maven,然后选择Maven 安装目录和配置路径。

  1. 创建Maven项目

    打开-File-New-Project 点击NEXT

git设置

file->setting->git 输入git安装的地址。例如: D:\Program Files\Git\bin\git.exe

注释模板设置

1.类注释模板

创建类的时候会自动创建该注释!

File-Settings-Editor->File and Code TemPlates

选择 Includes->File Heather

添加如下:

/**
* @Title: ${PROJECT_NAME}
* @Description:
* @Version:1.0.0
* @Since:jdk1.8
* @author pancm
* @date ${DATE}
*/

使用方法,在IDEA创建一个类,就会自动带出该注释,示例如下:

自定义类注释模板,输入一个关键字(自定义)就可以快速创建!

File-->Settings-->Editor-->Live Templates

新建一个组(Templates Group),名称随意(userTemplates)不冲突就行,然后在新建一个模板(Live Templates),Abbreviation 名称为 m1 。

添加如下:

/** 

* @Title: $PROJECT_NAME$ 

* @Description:  

* @Version:1.0.0   

* @Since:jdk1.8  

* @author pancm

* @Date  $date$ 

**/

然后点击edit variables进行编辑。

方法注释

File-->Settings-->Editor-->Live Templates

和上面一样,名称为m2。

添加如下:

/**

* @Author xxx

* @Description  

* @Date  $date$

* @Param $param$

* @return $return$

**/



修改 Expand with 为 Enter,然后点击 Edit variables 进行对照,下拉选择即可。

使用示例,在类上面输入m1,按回车就出现注释,在方法上面输出m2就出现方法的注释。

快捷键使用

注: 由于我是从eclipse转过来的,因此开始会找一些快捷对比而使用。

IDEA和Eclipse快捷键对比

idea 与 Eclipse 快捷键的区别,上为Eclipse的快捷键,下为Idea的快捷键
查找类名
CTRL + SHIFT + R
CTRL + N
查找JAR包中的类
CTRL + SHIFT + T
两次 CTRL + N
查找文件
CTRL + SHEFT + R
CTRL + SHEFT + N
查找JAR包中的文件
CTRL + SHIFT + T
两次 CTRL + SHEFT + N
查找类中的方法以及字段

CTRL + SHEFT + ALT + N
查找那些类调用该资源(资源可能是字段、方法、类)
CTRL + SHIFT + G
ALT + F7 ,快速显示查找内容 CTRL + ALT + F7
查找文件中的变量
点击变量 CTRL + K :移动
点击变量 CTRL + SHEFT + F7 高亮显示 F3 : 移动; SHEFT + F3 : 反向移动
定位行数
CTRL + L
CTRL + G
快速生成get set、构造函数等
ALT + SHIFT + S
ALT + INSERT
快速生成try cache
SHIFT + ALT + Z
CTRL + ALT + T 同时还能生成if else 等等其他的东西
快速优化引用包
CTRL + SHIFT + O
CTRL + ALT + O
快速格式化代码
CTRL + SHIFT + F
CTRL + ALT + L
重构代码
CTRL + F2
SHIFT + F6
显示类中的变量、方法
CTRL + O
CTRL + F12
快速生产类、方法、字段注释
CTRL + SHEFT + J
/** + ENTER
代码行 上下移动
ALT + 上下键
CTRL + SHIFT + 上下键
打开光标处的类或方法
F3
CTRL + B, CTRL + ALT + B 进入接口或者抽象类的实现类
其他的快捷键:
F4 查找变量来源
CTRL + 空格 代码提示 (和系统输入法冲突,请在Settings->Keymap->mainmenu -> code ->Completion->basic,右键添加自己的快捷键)
ALT + 回车 导入包,自动修正
CTRL + H 查看类的继承关系。
CTRL + Q 显示注释文档(跟eclipse鼠标放到类、方法、字段显示的内容一样)
CTRL + W 选中代码,连续按会有其他效果
CTRL + U 查看当前类的父类以及接口,
CTRL + ALT + U 查看类UML图
CTRL + SHIFT + U 切换大小写
CTRL + P 方法参数提示,可以看到这个方法有哪些多态方法
SHIFT + ALT + INSERT 竖编辑模式

一些使用经验

显示行号

File -> Settings ->Editor ->General -> Appearance =>Show line numbers选中

查找快捷键冲突问题处理

File -> Settings -> Keymap -> Main menu -> Edit ->Find =>修改Find…和Replace…分别改为Ctrl+F 和Ctrl+R

代码智能提示大小写

File -> Settings ->Eidtor->General->Code Completion => Case sensitive completion 改为none

代码提示

在Main menu->code->completion-> basic修改为Alt+/

设置用*标识编辑过的文件

Editor –> Editor Tabs选中Mark modifyied tabs with asterisk

方法悬浮提示(类似eclipse)

Editor > General 下 Other 区域中的 show quick documentation on mouse move

shell 、ftp的使用

tools -> ssh start session

填写地址、账号密码登录即可

ftp 使用

setting -> deployment 增加ftp/sftp 然后填写地址、账号密码登录即可

导入导出配置

导出:

File- -->Export Settings ->选择导出目录,会出现一个settings.jar的文件

导入方法:

File->Import Settings ->选择需要导入的settings.jar即可

自动导入和优化包

右键setting -General -Auto Import

IDEA启动设置

后缀补全

main方法运行忽略其他错误

idea有个麻烦的点是运行一个项目,必须全部都不能报错,因此在调试阶段,可以这样修改运行。

第一步



第二步

idea忽略一些错误

忽略注释错误:

忽略spring mapping 无法注入问题

IDEA引入jar包

java工程引入jar包跟eclipse有点不同,选中工具栏上"文件"--->"Project Structure"--->选择“Libraries”--->点击“+”--->"Java"--->选择自己需要的jar包即可。

IDEA 引入tomcat

点击Run-Edit Configurations...

点击左侧“+”,选择Tomcat Server--Local,

在Tomcat Server -> Unnamed -> Server -> Application server项目下,点击 Configuration ,找到本地 Tomcat 服务器,再点击 OK按钮。

IDEA Maven 自动导包

Settings > Maven > Importing > Import maven project automatically

自动清除多余的import

tkmybatis代码生成

pom文件配置:

需要添加:

<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>${tk.mybatis.boot.version}</version>
</dependency>
<!-- mybatis-generator-core 反向生成java代码,解决dtd 标红的问题-->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.5</version>
</dependency>

Source配置

  <plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<verbose>true</verbose>
<overwrite>true</overwrite>
<configurationFile>src/main/resources/generator/generatorConfig.xml</configurationFile>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.connector.version}</version>
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
<version>3.4.3</version>
</dependency>
</dependencies>
</plugin>
</plugins>

Idea配置:

命令: mybatis-generator:generate -e

关于插件的推荐和使用

插件安装

在线安装

File-Settings-Pluigin

输入要搜索的插件

离线安装

File-Settings-Pluigin -Install plugin from disk

选择离线下载的插件

插件推荐

Lombok Plugin 简化代码

Statistic 代码统计

CheckStyle 代码格式检查(可以自己/公司脚本)

FindBugs bugs插件

SonarLint bugs插件

grep Console 控制台插件

.ignore git 文件提交过滤

CodeGlance 右侧文档结构图

Background Image Plus 设置背景图片: view -> Set Backgroup Image

Key promoter 快捷键提示,将鼠标放上去的时候会有提示

Markdown support 编辑Markdown文件 .md 文件

Maven Helper maven插件,打开该pom文件的Dependency Analyzer视图

GsonFormat 将json转换为object

JRebel for IntelliJ 是一款热部署插件

AceJump 代替鼠标的软件,按快捷键进入 AceJump 模式后(默认是 Ctrl+J)

javaDoc 注释插件

Free MyBatis plugin Mybatis插件,可以自由跳转到对应的mapping.xml中

MyBatisX //mybatis 的增强插件, 在接口中写一个方法, 可以根据这个方法在mapper.xml中自动生成DML语句, 前提是这个mapper.xml 得先建好且指定了接口的名称空间

idea-mybatis-generator //mybatis的代码生成器,可以将数据库表生成实体类和对应mapper

Translation 翻译软件

SonarLint 代码质量管理工具

SequenceDiagram 可以根据代码调用链路自动生成时序图,右键 --> Sequence Diagaram 即可调出。

Maven Helper 查看maven直接引用的关系进行排除, 安装后 IDEA 中打开 pom.xml 文件时,就会多出一个 "Dependency Analyzer" 选项卡。

Maven search 快速查找maven依赖,支持模糊查找,需要连接网络

GenerateAllSetter 一键通过new对象生成

EasyCode 快速生成代码

EasyCode代码生成模板

注:这是我在开发某个项目使用的模板,并非通用所有项目,仅做参考。EasyCode官方自带有一套模板,初学者可以使用这套,熟悉之后可以在进行自定义。

Easy Code介绍:

•基于IntelliJ IDEA开发的代码生成插件,支持自定义任意模板(Java,html,js,xml)。

•只要是与数据库相关的代码都可以通过自定义模板来生成。支持数据库类型与java类型映射关系配置。

•支持同时生成生成多张表的代码。每张表有独立的配置信息。完全的个性化定义,规则由你设置

路径: File -> Settings->Plugins

输入: /vendor:"Easy Code Office Website" 进行搜索然后进安装。

安装完成之后需要重启IEDA。

插件安装之后建议先设置作者

路径:File -> Settings->Other Setting

示例图:

自定义模板设置

设置完作者之后,点击Template Setting,然后点击右边的+,创建一个分组名称,这个名称随意,不重复就行,这里就设置MyGroup,然后点击左边的+号进行添加模板:

1.dao模板

PowerShell
##定义初始变量 #set($tableName = $tool.append($tableInfo.name, "Dao")) ##设置回调 $!callback.setFileName($tool.append($tableName, ".java")) $!callback.setSavePath($tool.append($tableInfo.savePath, "/dao")) ##拿到主键 #if(!$tableInfo.pkColumn.isEmpty()) #set($pk = $tableInfo.pkColumn.get(0)) #end #if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}dao; import $!{tableInfo.savePackageName}.model.$!{tableInfo.name}; import $!{tableInfo.savePackageName}.vo.$!{tableInfo.name}VO; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Mapper; import java.util.List; /** * @Title: $!{tableInfo.comment}($!{tableInfo.name})表数据库访问层 * @Description: * @Version:1.0.0 * @Since:jdk1.8 * @author $author * @date $!time.currTime() */ @Mapper public interface $!{tableName} { /** * 通过ID查询单条数据 * * @param $!pk.name 主键 * @return 实例对象 */ $!{tableInfo.name}VO queryById($!pk.shortType $!pk.name); /** * 通过实体查询一条数据 * * @param $!tool.firstLowerCase($!{tableInfo.name})VO 实例对象 * @return 对象列表 */ $!{tableInfo.name}VO findOne($!{tableInfo.name}VO $!tool.firstLowerCase($!{tableInfo.name})VO); /** * 通过实体作为筛选条件查询 * * @param $!tool.firstLowerCase($!{tableInfo.name})VO 实例对象 * @return 对象列表 */ List<$!{tableInfo.name}VO> queryAll($!{tableInfo.name}VO $!tool.firstLowerCase($!{tableInfo.name})VO); /** * 新增数据 * * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象 * @return 影响行数 */ int insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})); /** * 批量新增数据(MyBatis原生foreach方法) * * @param entities List<$!{tableInfo.name}> 实例对象列表 * @return 影响行数 */ int insertBatch(@Param("entities") List<$!{tableInfo.name}> entities); /** * 批量新增或按主键更新数据(MyBatis原生foreach方法) * * @param entities List<$!{tableInfo.name}> 实例对象列表 * @return 影响行数 */ int insertOrUpdateBatch(@Param("entities") List<$!{tableInfo.name}> entities); /** * 修改数据 * * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象 * @return 影响行数 */ int update($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})); /** * 通过主键删除数据 * * @param $!pk.name 主键 * @return 影响行数 */ int deleteById($!pk.shortType $!pk.name); }

2.entity模板

Kotlin
##引入宏定义 $!define #set($tableName = $tool.append($tableInfo.name, "VO")) ##设置回调 $!callback.setFileName($tool.append($tableName, ".java")) $!callback.setSavePath($tool.append($tableInfo.savePath, "/vo")) #if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}vo; ##使用全局变量实现默认包导入 $!autoImport import java.io.Serializable; import com.alibaba.fastjson.JSONObject; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; /** * @Title: $!{tableInfo.comment}($!{tableInfo.name})请求响应对象 * @Description: * @Version:1.0.0 * @Since:jdk1.8 * @author $author * @date $!time.currTime() */ @ApiModel(value = "$!{tableInfo.name}", description = "$!{tableInfo.comment}") @Data public class $!{tableInfo.name}VO extends BasePage implements Serializable { private static final long serialVersionUID = $!tool.serial(); #foreach($column in $tableInfo.fullColumn) #if(${column.comment})/** * ${column.comment} */#end @ApiModelProperty(value = "${column.comment}") private $!{tool.getClsNameByFullName($column.type)} $!{column.name}; #end @Override public String toString(){ return JSONObject.toJSONString(this); } }

3.service模板

PowerShell
##定义初始变量 #set($tableName = $tool.append("I",$tableInfo.name, "Service")) ##设置回调 $!callback.setFileName($tool.append($tableName, ".java")) $!callback.setSavePath($tool.append($tableInfo.savePath, "/service")) ##拿到主键 #if(!$tableInfo.pkColumn.isEmpty()) #set($pk = $tableInfo.pkColumn.get(0)) #end #if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service; $!autoImport import $!{tableInfo.savePackageName}.vo.$!{tableInfo.name}VO; import java.util.List; /** * @Title: $!{tableInfo.comment}($!{tableInfo.name})表服务接口 * @Description: * @Version:1.0.0 * @Since:jdk1.8 * @author $author * @date $!time.currTime() */ public interface $!{tableName} { /** * 通过ID查询单条数据 * * @param $!pk.name 主键 * @return 实例对象 */ $!{tableInfo.name}VO queryById($!pk.shortType $!pk.name); /** * 通过实体作为筛选条件查询 * * @param $!tool.firstLowerCase($!{tableInfo.name})VO 实例对象 * @return 对象列表 */ ApiResult list($!{tableInfo.name}VO $!tool.firstLowerCase($!{tableInfo.name})VO); /** * 新增数据 * * @param $!tool.firstLowerCase($!{tableInfo.name})VO 实例对象 * @return 实例对象 */ int insert($!{tableInfo.name}VO $!tool.firstLowerCase($!{tableInfo.name})VO); /** * 修改数据 * * @param $!tool.firstLowerCase($!{tableInfo.name})VO 实例对象 * @return 实例对象 */ int update($!{tableInfo.name}VO $!tool.firstLowerCase($!{tableInfo.name})VO); /** * 通过主键删除数据 * * @param $!pk.name 主键 * @return 是否成功 */ boolean deleteById($!pk.shortType $!pk.name); }

4.serviceImpl 模板

PowerShell
##定义初始变量 #set($tableName = $tool.append($tableInfo.name, "ServiceImpl")) ##设置回调 $!callback.setFileName($tool.append($tableName, ".java")) $!callback.setSavePath($tool.append($tableInfo.savePath, "/service/impl")) ##拿到主键 #if(!$tableInfo.pkColumn.isEmpty()) #set($pk = $tableInfo.pkColumn.get(0)) #end #if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service.impl; $!autoImport import $!{tableInfo.savePackageName}.vo.$!{tableInfo.name}VO; import $!{tableInfo.savePackageName}.model.$!{tableInfo.name}; import $!{tableInfo.savePackageName}.dao.$!{tableInfo.name}Dao; import $!{tableInfo.savePackageName}.service.I$!{tableInfo.name}Service; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import org.springframework.stereotype.Service; import org.springframework.beans.BeanUtils; import javax.annotation.Resource; import java.util.List; /** * @Title: $!{tableInfo.comment}($!{tableInfo.name})表服务实现类 * @Description: * @Version:1.0.0 * @Since:jdk1.8 * @author $author * @date $!time.currTime() */ @Service("$!tool.firstLowerCase($!{tableInfo.name})Service") public class $!{tableName} implements I$!{tableInfo.name}Service { @Resource private $!{tableInfo.name}Dao $!tool.firstLowerCase($!{tableInfo.name})Dao; /** * 通过ID查询单条数据 * * @param $!pk.name 主键 * @return 实例对象 */ @Override public $!{tableInfo.name}VO queryById($!pk.shortType $!pk.name) { return this.$!{tool.firstLowerCase($!{tableInfo.name})}Dao.queryById($!pk.name); } /** * 根据条件查询 * * @return 实例对象的集合 */ @Override public ApiResult list($!{tableInfo.name}VO $!{tool.firstLowerCase($!{tableInfo.name})}) { int pageNum = $!{tool.firstLowerCase($!{tableInfo.name})}.getPageNum(); int pageSize = $!{tool.firstLowerCase($!{tableInfo.name})}.getPageSize(); Page page = PageHelper.startPage(pageNum, pageSize); List<$!{tableInfo.name}VO> result = $!{tool.firstLowerCase($!{tableInfo.name})}Dao.queryAll($!{tool.firstLowerCase($!{tableInfo.name})}); return ApiResult.success(new PageResult<>(page.getTotal(), result, pageSize, pageNum)); } /** * 新增数据 * * @param $!tool.firstLowerCase($!{tableInfo.name})VO 实例对象 * @return 实例对象 */ @Override public int insert($!{tableInfo.name}VO $!tool.firstLowerCase($!{tableInfo.name})VO) { $!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}) = new $!{tableInfo.name}(); BeanUtils.copyProperties($!tool.firstLowerCase($!{tableInfo.name})VO,$!tool.firstLowerCase($!{tableInfo.name})); return $!{tool.firstLowerCase($!{tableInfo.name})}Dao.insert($!tool.firstLowerCase($!{tableInfo.name})); } /** * 修改数据 * * @param $!tool.firstLowerCase($!{tableInfo.name})VO 实例对象 * @return 实例对象 */ @Override public int update($!{tableInfo.name}VO $!tool.firstLowerCase($!{tableInfo.name})VO) { $!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}) = new $!{tableInfo.name}(); BeanUtils.copyProperties($!tool.firstLowerCase($!{tableInfo.name})VO,$!tool.firstLowerCase($!{tableInfo.name})); return $!{tool.firstLowerCase($!{tableInfo.name})}Dao.update($!tool.firstLowerCase($!{tableInfo.name})); } /** * 通过主键删除数据 * * @param $!pk.name 主键 * @return 是否成功 */ @Override public boolean deleteById($!pk.shortType $!pk.name) { return this.$!{tool.firstLowerCase($!{tableInfo.name})}Dao.deleteById($!pk.name) > 0; }
}

5.controller模板

Kotlin
##定义初始变量 #set($tableName = $tool.append($tableInfo.name, "Controller")) ##设置回调 $!callback.setFileName($tool.append($tableName, ".java")) $!callback.setSavePath($tool.append($tableInfo.savePath, "/controller")) ##拿到主键 #if(!$tableInfo.pkColumn.isEmpty()) #set($pk = $tableInfo.pkColumn.get(0)) #end #if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}controller; import $!{tableInfo.savePackageName}.vo.$!{tableInfo.name}VO; import $!{tableInfo.savePackageName}.service.I$!{tableInfo.name}Service; import org.springframework.web.bind.annotation.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; /** * @Title: $!{tableInfo.comment}($!{tableInfo.name})表控制层 * @Description: * @Version:1.0.0 * @Since:jdk1.8 * @author $author * @date $!time.currTime() */ @Api(tags = "$!{tableInfo.comment}($!{tableInfo.name})") @RestController @RequestMapping("$!tool.firstLowerCase($tableInfo.name)") public class $!{tableName} { /** * 服务对象 */ @Autowired private I$!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)Service; /** * 新增一条数据 * * @param $!tool.firstLowerCase($tableInfo.name)VO 实体类 * @return Response对象 */ @ApiOperation(value = "$!{tableInfo.comment}新增",notes = "$!{tableInfo.comment}新增") @RequestMapping(value = "save", method = RequestMethod.POST) public ApiResult insert(@RequestBody $!{tableInfo.name}VO $!tool.firstLowerCase($tableInfo.name)VO, HttpServletRequest httpRequest) { int result = $!{tool.firstLowerCase($tableInfo.name)}Service.insert($!tool.firstLowerCase($tableInfo.name)VO); if (result > 0) { return ApiResult.success(); } return ApiResult.error("新增失败"); } /** * 修改一条数据 * * @param $!tool.firstLowerCase($tableInfo.name)VO 实体类 * @return Response对象 */ @ApiOperation(value = "$!{tableInfo.comment}修改",notes = "$!{tableInfo.comment}修改") @RequestMapping(value = "edit", method = RequestMethod.POST) public ApiResult update(@RequestBody $!{tableInfo.name}VO $!tool.firstLowerCase($tableInfo.name)VO, HttpServletRequest httpRequest) { $!{tool.firstLowerCase($tableInfo.name)}Service.update($!tool.firstLowerCase($tableInfo.name)VO); return ApiResult.success(); } /** * 删除一条数据 * * @param $!tool.firstLowerCase($tableInfo.name)VO 参数对象 * @return Response对象 */ @ApiOperation(value = "$!{tableInfo.comment}删除",notes = "$!{tableInfo.comment}删除") @RequestMapping(value = "del", method = RequestMethod.POST) public ApiResult delete(@RequestBody $!{tableInfo.name}VO $!tool.firstLowerCase($tableInfo.name)VO, HttpServletRequest httpRequest) { $!{tool.firstLowerCase($tableInfo.name)}Service.deleteById($!{tool.firstLowerCase($tableInfo.name)}VO.getId()); return ApiResult.success(); } /** * 分页查询 * */ @ApiOperation(value = "$!{tableInfo.comment}查询",notes = "$!{tableInfo.comment}查询") @RequestMapping(value = "list", method = RequestMethod.POST) public ApiResult list(@RequestBody $!{tableInfo.name}VO $!tool.firstLowerCase($tableInfo.name)VO) { return $!{tool.firstLowerCase($tableInfo.name)}Service.list($!tool.firstLowerCase($tableInfo.name)VO); } /** * 详情查询 * */ @ApiOperation(value = "$!{tableInfo.comment}详情",notes = "$!{tableInfo.comment}详情") @RequestMapping(value = "view", method = RequestMethod.GET) public ApiResult view( @RequestParam("id") Long id) { return ApiResult.success($!{tool.firstLowerCase($tableInfo.name)}Service.queryById(id)); } }

6.mapper模板

HTML
##引入mybatis支持 $!mybatisSupport ##设置保存名称与保存位置 $!callback.setFileName($tool.append($!{tableInfo.name}, "Mapper.xml")) $!callback.setSavePath($tool.append($modulePath, "/src/main/resources/guard/mapper")) ##拿到主键 #if(!$tableInfo.pkColumn.isEmpty()) #set($pk = $tableInfo.pkColumn.get(0)) #end <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="$!{tableInfo.savePackageName}.dao.$!{tableInfo.name}Dao"> <resultMap type="$!{tableInfo.savePackageName}.vo.$!{tableInfo.name}VO" id="$!{tableInfo.name}Map"> #foreach($column in $tableInfo.fullColumn) <result property="$!column.name" column="$!column.obj.name" jdbcType="$!column.ext.jdbcType"/> #end </resultMap> <!--查询单个--> <select id="queryById" resultMap="$!{tableInfo.name}Map"> select #allSqlColumn() from $!tableInfo.obj.name where $!pk.obj.name = #{$!pk.name} </select> <!--通过实体查询一条数据--> <select id="findOne" resultMap="$!{tableInfo.name}Map"> select #allSqlColumn() from $!tableInfo.obj.name <where> #foreach($column in $tableInfo.fullColumn) <if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end"> and $!column.obj.name = #{$!column.name} </if> #end </where> limit 1 </select> <!--通过实体作为筛选条件查询--> <select id="queryAll" resultMap="$!{tableInfo.name}Map"> select #allSqlColumn() from $!tableInfo.obj.name <where> #foreach($column in $tableInfo.fullColumn) <if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end"> and $!column.obj.name = #{$!column.name} </if> #end </where> </select> <!--新增所有列--> <insert id="insert" keyProperty="$!pk.name" useGeneratedKeys="true"> insert into $!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($velocityHasNext), #end#end) values (#foreach($column in $tableInfo.otherColumn)#{$!{column.name}}#if($velocityHasNext), #end#end) </insert> <insert id="insertBatch" keyProperty="$!pk.name" useGeneratedKeys="true"> insert into $!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($velocityHasNext), #end#end) values <foreach collection="entities" item="entity" separator=","> (#foreach($column in $tableInfo.otherColumn)#{entity.$!{column.name}}#if($velocityHasNext), #end#end) </foreach> </insert> <insert id="insertOrUpdateBatch" keyProperty="$!pk.name" useGeneratedKeys="true"> insert into $!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($velocityHasNext), #end#end) values <foreach collection="entities" item="entity" separator=","> (#foreach($column in $tableInfo.otherColumn)#{entity.$!{column.name}}#if($velocityHasNext), #end#end) </foreach> on duplicate key update #foreach($column in $tableInfo.otherColumn)$!column.obj.name = values($!column.obj.name) #if($velocityHasNext), #end#end </insert> <!--通过主键修改数据--> <update id="update"> update $!{tableInfo.obj.name} <set> #foreach($column in $tableInfo.otherColumn) <if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end"> $!column.obj.name = #{$!column.name}, </if> #end </set> where $!pk.obj.name = #{$!pk.name} </update> <!--通过主键删除--> <delete id="deleteById"> delete from $!{tableInfo.obj.name} where $!pk.obj.name = #{$!pk.name} </delete> </mapper>

7.model模板

Kotlin
##引入宏定义 $!define ##使用宏定义设置回调(保存位置与文件后缀) #save("/model", ".java") ##使用宏定义设置包后缀 #setPackageSuffix("model") ##使用全局变量实现默认包导入 $!autoImport import com.alibaba.fastjson.JSONObject; import lombok.Data; import javax.persistence.Column; import javax.persistence.Table; import java.io.Serializable; import java.util.Date; /** * @Title: $!{tableInfo.comment}($!{tableInfo.name})实体类 * @Description: * @Version:1.0.0 * @Since:jdk1.8 * @author $author * @date $!time.currTime() */ @Data @Table(name = "$tableInfo.obj.name") public class $!{tableInfo.name} implements Serializable { private static final long serialVersionUID = $!tool.serial(); #foreach($column in $tableInfo.fullColumn) #if(${column.comment})/** * ${column.comment} */#end @Column(name = "$column.obj.name") private $!{tool.getClsNameByFullName($column.type)} $!{column.name}; #end @Override public String toString(){ return JSONObject.toJSONString(this); } }

使用配置

1.前提

该插件使用IDEA连接数据库,若未连接数据库,则需手动添加数据库.

MySql数据库添加示例:

点击IDEA右侧的database,点击+号,选择DataSource->MySQL,需要MySql驱动的jar,可以从maven仓库里面选择对应的jar。

示例图:



2.使用

连接mysql之后,选择对应的表,这里就选择db_version,右键该表,选择EasyCode->Generate Code,然后选择刚刚创建的组(MyGroup),选择生成代码的路径,这里到了com.xxx.xxx即可,如果有不存在的package,会自动创建,点击ok自动生成代码。再次做同样的点击可以选择覆盖响应代码。

测试示例

1.数据新增

2.分页查询

3.数据修改

一些使用错误解决办法

1. Error:java: 无效的源发行版: 11

操作: 'File->Project Structure'
修改jdk的版本

运行提示 Command line is too long

解法:

修改项目下 .idea\workspace.xml,找到标签 <component name="PropertiesComponent"> , 在标签里加一行 <property name="dynamic.classpath" value="true" />

Idea 光标变成了 insert光标状态

是因为使用了插件ideavim,打开file -> settings 点击 Plugins 然后再右边搜索框输入IdeaVim,出来结果后将后面复选框中得勾去掉就可以了

其他

关于IDEA,在很久之前就开始使用了,主要是因为使用eclipse间歇先崩溃,有几次代码没有及时保存导致心态炸裂,所以就开始使用IDEA,因为个人习惯,使用一项新的东西,就会进行记录,因此就有了此手记。

音乐推荐

一首很好听的古风曲~

原创不易,如果感觉不错,希望给个推荐!您的支持是我写作的最大动力!

版权声明:

作者:虚无境

博客园出处:http://www.cnblogs.com/xuwujing

CSDN出处:http://blog.csdn.net/qazwsxpcm    

个人博客出处:https://xuwujing.github.io/

最新文章

  1. Unity中各类物理投射性能横向比较
  2. 工具mark
  3. Django--BBS项目
  4. 收集的URL
  5. select2插件常用方法汇总
  6. Java多线程缓存器简单实现
  7. 快速理解web语义化
  8. Linux - Bash shell的功能;内建命令type
  9. Linux解压缩命令tar
  10. Hanlp分词1.7版本在Spark中分布式使用记录
  11. idea html,js修改不用重启进程
  12. Odoo 去掉 恼人的 &quot;上午&quot;和&quot;下午&quot;
  13. mysql安装时,提示:Failed to start service MYSQL80
  14. 挖财大牛讲 Springboot工作流程
  15. DFS(DP)---POJ 1014(Dividing)
  16. Python基础笔记系列十二:requests模块的简单应用
  17. Numpy的ndarry
  18. HTTP Slow Attack测试工具SlowHTTPTest
  19. Hibernate 关于实体映射常用注解
  20. 经典dfs(depth-first search)

热门文章

  1. 刷题记录:Codeforces Round #734 (Div. 3)
  2. 获取Windows正在运行的窗口进程
  3. 「学习笔记」单调队列优化dp
  4. Linux之搭建FTP服务
  5. 如何将原生微信小程序页面改成原生VUE框架的H5页面
  6. sedona(Geospark)读取csv
  7. Windows编程之线程
  8. 大规模数据分析统一引擎Spark最新版本3.3.0入门实战
  9. 邮箱的代理发送Send as权限不生效
  10. 《Java基础——抽象与接口》