前言

本篇文章主要介绍的关于本人在使用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/

手记系列之二 ----- 关于IDEA的一些使用方法经验的更多相关文章

  1. 手记系列之三 ----- 关于使用Nginx的一些使用方法和经验

    前言 本篇文章主要介绍的关于本人在使用Nginx的一些使用方法和经验~ Nginx介绍 介绍 Nginx("engine x")是一款是由俄罗斯的程序设计师Igor Sysoev所 ...

  2. iOS内存管理系列之二:自动释放与便捷方法

    有时候一个所有者创建一个对象后,会立刻将该对象的指针传递给其它所有者.这时,这个创建者不希望再拥有这个对象,但如果立刻给它发送一个release消息会导致这个对象被立刻释放掉——这样其它所有者还没有来 ...

  3. 【疯狂造轮子-iOS】JSON转Model系列之二

    [疯狂造轮子-iOS]JSON转Model系列之二 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇<[疯狂造轮子-iOS]JSON转Model系列之一> ...

  4. 【原】Android热更新开源项目Tinker源码解析系列之二:资源文件热更新

    上一篇文章介绍了Dex文件的热更新流程,本文将会分析Tinker中对资源文件的热更新流程. 同Dex,资源文件的热更新同样包括三个部分:资源补丁生成,资源补丁合成及资源补丁加载. 本系列将从以下三个方 ...

  5. MySQL 系列(二) 你不知道的数据库操作

    第一篇:MySQL 系列(一) 生产标准线上环境安装配置案例及棘手问题解决 第二篇:MySQL 系列(二) 你不知道的数据库操作 本章内容: 查看\创建\使用\删除 数据库 用户管理及授权实战 局域网 ...

  6. ES6+ 现在就用系列(二):let 命令

    系列目录 ES6+ 现在就用系列(一):为什么使用ES6+ ES6+ 现在就用系列(二):let 命令 ES6+ 现在就用系列(三):const 命令 ES6+ 现在就用系列(四):箭头函数 => ...

  7. CRL快速开发框架系列教程二(基于Lambda表达式查询)

    本系列目录 CRL快速开发框架系列教程一(Code First数据表不需再关心) CRL快速开发框架系列教程二(基于Lambda表达式查询) CRL快速开发框架系列教程三(更新数据) CRL快速开发框 ...

  8. Web 前端开发精华文章推荐(jQuery、HTML5、CSS3)【系列十二】

    2012年12月12日,[<Web 前端开发人员和设计师必读文章>系列十二]和大家见面了.梦想天空博客关注 前端开发 技术,分享各种增强网站用户体验的 jQuery 插件,展示前沿的 HT ...

  9. C#微信公众号开发系列教程二(新手接入指南)

    http://www.cnblogs.com/zskbll/p/4093954.html 此系列前面已经更新了两篇博文了,都是微信开发的前期准备工作,现在切入正题,本篇讲解新手接入的步骤与方法,大神可 ...

随机推荐

  1. JavaScript基础回顾知识点记录1

    js执行顺序为从上往下执行 js中有6种数据类型 基本数据类型为: String Number Boolean Null Undefined 引用数据类型为: Object 使用typeof 查看对象 ...

  2. 应用性能监控:SkyWalking

    目录 SkyWalking 简介 SkyWalking 搭建 平台后端(Backend) 平台前端(UI) Java Agent(Java 应用监控) Java Agent 下载 Java 演练项目 ...

  3. 从代码到发包,一个程序全搞定!Gitea 推出软件包自托管功能 Package Registry

    2022 年 7 月的最后一天,随着 Gitea 1.17.0 版本的正式发布,Gitea 开源社区推出了一项名为 Package Registry 的包管理功能,与 Gitea 代码仓库无缝集成,类 ...

  4. TextView 中文本内容换行

    TextView 中文本内容换行 首先如图所示,我的第一栏围城的书名和书的介绍是在同一行 但是我想让书名和书的介绍分开个站一行 这时我只要在我的数组文本中的文本用 "\n" 就可以 ...

  5. 5种kafka消费端性能优化方法

    摘要:带你了解基于FusionInsight HD&MRS的5种kafka消费端性能优化方法. 本文分享自华为云社区<FusionInsight HD&MRSkafka消费端性能 ...

  6. 【项目实战】pytorch实现逻辑斯蒂回归

    视频指导:https://www.bilibili.com/video/BV1Y7411d7Ys?p=6 一些数据集 在pytorch框架下,里面面有配套的数据集,pytorch里面有一个torchv ...

  7. 使用filebeat收集k8s上pod里的容器日志配置文件模板

    具体使用有待商榷 filebeat.inputs: - type: container paths: - /var/log/containers/*.log processors: - add_kub ...

  8. Logstash:在 Docker 中部署 Logstash

    文章转载自:https://elasticstack.blog.csdn.net/article/details/116516923 创建一个目录 docker-logstash.在该目录下,有如下的 ...

  9. (五)JPA - 原生SQL实现增删改查

    6.原生SQL JPA除了对JPQL提供支持外,还对原生SQL语句也提供了支持.下面小节一起来看看吧. 6.1 查询单个 示例代码: @Test public void getSingle() { E ...

  10. MES系统和ERP系统的区别是什么?

    首先得明白一点:MES(Manufacturing Execution System,即制造执行系统)系统跟ERP(Enterprise Resource Planning,企业资源计划)系统是两个完 ...