Step by step to create your strongest Idea

A long, long time ago, there was Eclipse and a paid MyEclipse, until IntelliJ IDEA, a Czech software development company that really knows programmers, came along.

I can’t say eclipse has gone to the end, at least IntelliJ IDEA has occupied half of the country.

In fact, Eclipse is also very easy to use, I also installed a lot of plug-ins, created a lot of code templates, but also replaced a JAR package, code hints can be the same as idea, write code, than idea is not bad, but later turned to the idea camp.

A few flowers.

I am a person who likes tinkering tools. It can be said that my idea is the best to use. It is so immodest 🤣

Next, let me take you to build your strongest Idea.

I won’t go into shortcuts. Everyone has different habits, and Windows and Mac systems are different. For most of my shortcuts, I use the Eclipse shortcut 🥶

The first is code templates, orLive Templates

Here we can customize the code template, in fact many people know, I have dozens of custom code template, here are a few of my favorite, and the most commonly used.

Logs related

Writing code can’t avoid printing a log, but writing a log is a waste of time, and a log can’t be written randomly, and it’s easy to track.

I used class name _ method name _ variable name to print the log. But it would kill you to write it down.

So I created a log1 code template, don’t forget to configure it for the Java program, choose all if you don’t mind

log.info("$ClassName$_$MethodName$_$VAR1$:{}", $VAR1$);
Copy the code

Something like $ClassName is a variable, and we have to tell idea what it means.

We clickEdit variables, you can edit variable information.

You can see there’s a lot of expressions in there

So let’s talk about these three

  • className()You can tell by the name. It’s the class name
  • methodName()As you can see from the name, this is the method name
  • variableOfType("")This is to letideaAutomatic inference, automatic filling in the most suitable.

You just type in log1, and that last one you can select as prompted.

Why is it called log of one?

Since this is a variable, logs are usually typed with several variables, so I have log1-log5, which can support up to 5 variables. Also, the log level is INFO, and I created a log1e to print the error level.

Assertions related

Assertions are really useful in Spring. A lot of times we use assert.istrue (). It would be nice if the data in the expression could be automatically populated.

  • variableOfType("")This is to letideaAutomatic inference, automatic filling in the most suitable.

I’ve defined an ass1. Assert.istrue ($VAR$.size() == 1, “$END$! “) ); The primary user determines the size of the list. $VAR$= variableOfType(“”); $END$= variableOfType(“”);

  • There areassdTheta has to be greater than 0

    Assert.isTrue($VAR$.size() > 0, "$END$! ") );
  • assleIs less than 0

    Assert.isTrue($VAR$.size() <= 0, "$END$!" );
  • assn, the requirement cannot be empty

    Assert.isTrue($VAR$ ! = null, "$END$! );
  • assnnIs required to be empty

    Assert. IsTrue ($VAR$== null, "$END$! );
  • asss, requires the string to be non-empty

    Assert. IsTrue (StringUtils. IsNotBlank ($VAR $), "$END $!" );
  • asst, the expression istrue

    Assert. IsTrue ($VAR $, $END $! "" );

You can see that most of the scene I have configured the template, no way, is lazy 😂

Interface related

With Swagger and a bunch of comments every time I write an interface, I configured two templates, PM and GM.

See firstgm

Gm is the interface for GET requests.

@ApiOperation("$VAR2$")
@ApiImplicitParams({
  @ApiImplicitParam(name = "", value = "", required = true),
})
@GetMapping(value = "/$VAR1$", name = "$VAR2$")
public HttpResult $VAR1$(){  $END$  return HttpResult.success(); } Copy the code

Here $VAR1$and $VAR2$are also variableOfType

The request path is the same as the method name. The value of the ApiOperation is the same as the name of the GetMapping.

And then thepm

PM is the same, but GetMapping is PostMapping instead

@ApiOperation("$VAR2$")
@ApiImplicitParams({
  @ApiImplicitParam(name = "", value = "", required = true),
})
@PostMapping(value = "/$VAR1$", name = "$VAR2$")
public HttpResult $VAR1$() {  $END$  return HttpResult.success(); } Copy the code

Last one: underline to hump naming

A lot of times the database has added a new field, but it is named with underscore interval, we copy to the class, manually change one by one, very troublesome.

So I created a template XSCS, the only defect is that after conversion, can not delete before, to manually delete before, I checked the variables in the template is not supported to delete.

$SELECTION$$END$$VAR$
Copy the code

Variable configuration

$SELECTION$indicates the string conversion to be selected.

The string before the cursor is 🤣, which I manually deleted

conclusion

So that’s it for today, because code templates are a very useful thing to do, because it saves us a lot of rework, so if you have a piece of code that you write a lot, and it doesn’t make much difference, you can try to configure it as a code template.

Welcome everyone to follow my public account, study together, progress together. Refueling 🤣

This article was typeset using MDNICE