From. Net to Java (2) idea installation and environment configuration

Run if you can't beat it 2020-11-09 11:36:37
from. java idea installation environment


Never give up .Net To the pit Java( One )

The so-called work wants to do well , You must sharpen your tools first , do java The same goes for development , In the comparison of the most popular java IDE(eclipse,myeclipse、IDEA) after , I made a decision to IDEA. Need to know , The level of code writing can be a piece of shit , But development tools must use the best , It's like a person with poor martial arts , If you don't have a decent weapon in your hand , There's no way to get around , I was chopped to death in minutes . I used to use eclipse,myeclipse When , Because it's used in the past VS The gap is too big , It made me want to give up writing for a time java Code , until IDEA Appearance , Like a light in the dark . I'm an efficient person , Could have been 2s The code of the end of the bell , You have to spend 10s, I can't stand it , Isn't it a waste of life ? For example , People of the same level fight , A bare hand , One with a machete , Who has a good chance of winning ? Unless you're strong enough , Strong enough not to be stagnant , Plants, trees, bamboo and stone can hurt people . So the kind of people who use Notepad to write code , Or enough cattle , Or it's invisible and forced to die . Good and false in things , There is a big difference between the old and the new , The old bird will make good use of all kinds of useful auxiliary development tools . What do you do with these tools ? Improve development efficiency ! Produce = Time * efficiency . Time is all about 8h, No matter how much you work overtime 24h, And efficiency is often beyond 4 Times , That means maybe you 24h You can't do anything else 8h, Because the efficiency is different .

srping boot The emergence of the may be able to java Developers from 996 Free from the curse in , So you can work less overtime . use Spring Boot Development is essentially a routine Spring Project development , It just takes advantage of Spring Boot Startup programs and automatic configuration simplify the development process , Improve development efficiency .Spring Boot Project development code implementation is still using Spring mvc+spring+mybatis etc. , Of course, it can integrate almost all open source projects .

PS: If you encounter any problems during the configuration process , You can leave a message below or check my personal announcement , Answer online anytime , And some of the things I've been working on these days Java Learning manual , Interview questions , development tool ,PDF Document book tutorial , If you need it, you can share it for free . Get down to business :

java Environment configuration

download java JDK, Suggest 1.8 Above version .

Here's what I downloaded :jdk_8.0.1310.11_64.exe

Then install , My installation directory here is C:\Program Files\Java\jdk1.8.0_131, It will be used later .

Configure environment variables

New system variable JAVA_HOME, value :C:\Program Files\Java\jdk1.8.0_131

Edit environment variables Path, Add... To the front of the variable value %JAVA_HOME%\bin;, Pay attention to the last one ; Separate .

IDEA Install and crack

Now the latest version is IntelliJ IDEA 2018.2 了 , What I downloaded before is IntelliJ IDEA 2018.1.4 x64, Because mine is win10 64bit System .

Once the download is complete , Click next. Next is OK , But at the last step, be sure to pay attention to , Otherwise, the attack may fail , That's when the finish screen finally appears , Be sure to remove the check in front of whether to run immediately .

(1) Edit on the computer C:\Windows\System32\drivers\etc Under the hosts file

Add the following line of code :

0.0.0.0 account.jetbrains.com

Save and close .

(2) open http://idea.lanyus.com/, Get the registration code

 

 

open IDEA,

 

 IDEA To configure

IDEA After installation , We're going to personalize it , I think the most important two points are , One is the configuration of shortcut keys , One is the configuration of code display style , Like I'm used to VS Code display style of , Then we can customize it .

I made a configuration file , Download address :https://files.cnblogs.com/files/jiekzou/settings.zip

Once the download is complete , After decompressing it is a settings.jar file , And then in IDEA Import the configuration in .

The final display is as follows :

 

About IDEA Code format shortcut key for , The default is :Ctrl+Alt+L, This conflicts with many software lock screen shortcuts , So I suggest that it be modified , I've changed it here to and VS Code formatting shortcuts are the same :Ctrl+K,Ctrl+F. This is a combination of two shortcut keys .

File——Settings

stay VS The case is insensitive to code hints in , and IDEA Sensitive by default , Because of personal habits , So I need to put IDEA The code smart prompt is also changed to case insensitive .

 

stay IDEA Code written in or copied into , Its namespace is what packages automatically introduce , If more than one bag appears , Then you need to import it manually , It's also very simple to introduce , Click to the code location with the mouse , then Atl+Enter, Select the specified package . although java There is no attribute in the legend ,C# In fact, the medium attribute is like java In the same way through a get Methods and a set Method , It's just C# It was packaged , and java Need to write by yourself , however IDEA There are shortcut keys to automatically generate field properties in :Alt+Insert.

No matter what kind of IDE, It is necessary to remember all kinds of shortcut keys , Why? ? efficiency ! efficiency ! Or efficiency !

first spring boot web Program

what's spring boot?

My understanding is that :spring boot=spring+spring mvc+ a pile java Technology stack related framework + The idea that convention is greater than configuration .

spring boot It's not a new technology , It's like ajax equally , It's a combination of existing technologies . The appearance of it , Will greatly improve java Application development efficiency . meanwhile , The appearance of it , Completely overturn the past. I'm very interested in java The understanding of ( In addition to the configuration ,TMD Or configuration ). Lightweight 、 Pluggable 、 Microservices .

File——New——Project

About https://start.spring.io/, Let's open it up and see what this is

 

This is not exactly a build project jar Package interface , Generate directly in this interface jar package , And then use eclipse Opening is the same .

Be careful : Create... In this way spring boot project , It's connected to the Internet , Download some from the website jar package . If you want to create a project offline , You can choose Maven.

Because it is web project , So we choose web, About spring boot edition , The latest version is 2.1.0, I use its last stable version here 1.5.14. We see some versions with SNAPSHOT word , It shows that it's a flash version .

 

Keep clicking next , The final project results are listed below :

 

So let's see pom.xml, It is maven To manage all kinds of jar A configuration file that the package depends on ,maven amount to .net Medium nuget, It's a package management tool .

 

We see <parent> The version number is declared in the node , And it's as a parent node , This means that its child node can inherit the version dependency of the parent node . Which are its child nodes , Namely <dependencies> below groupId and <parent> in groupId Consistent dependence . This pom.xml Documents in , It's the product of our previous visual configuration , Some of the information in it is what we filled in before . Then follow up , When we need to expand , Just modify the configuration file directly .

About pom.xml Detailed explanation , Please refer to :pom.xml Detailed explanation

If you are in the pom.xml When you add code to , There's no smart tip , So you need to update .

  Next , Let's take a look at FirstdemoApplication This class

We see a @SpringBootApplication annotation , Let's look at its source code as follows :

 

You can see it in the source code , Actually @SpringBootApplication = ( The default attribute )@Configuration + @EnableAutoConfiguration + @ComponentScan.

Let's take a look at what these three annotations mean in turn .

@Configuration Is a class level comment , Indicates that the object is a bean Source of definition .@Configuration Class passing @bean Public method statements for annotations bean. @Configuration The annotation class of indicates that this class can be used Spring.

@Bean Annotations are used to represent a method instantiation , Configuration and initialization are done by Spring IoC A new object for container management .

@Configuration Generally speaking, it is related to @Bean Use with annotations , use @Configuration Annotation class is equivalent to XML Middle configuration beans, use @Bean Annotation method is equivalent to XML Middle configuration bean.

@EnableAutoConfiguration The package in which the annotated class is located has a specific meaning , And use it as the default configuration .

@ComponentScan The annotation will automatically scan all marked with @Component annotation Class , And register into bean, Including, of course @Component Next sub note @Service,@Repository,@Controller.

application.properties

This is the configuration file for the application , Follow .net In the project web.config almost . But I'm more used to using application.yml This file replaces application.properties

modify application.properties, Name it application.properties-bak, In fact, it is to disable the configuration file , But I don't want to delete it directly .

Then add a file application.yml, Pay attention to and application.properties Under the same level of directory .

Add configuration item :

I'm going to change it here tomcat The boot port of the server is 8082, because IDEA srping boot The project comes with tomcat, So we don't need to configure external tomcat.

Create a new controller TestController, It's the naming convention for this controller and .net mvc The standards in China are consistent , All are Controller ending . The code is as follows :

@RequestMapping("/hello") and @RequestMapping(value = "/hello" It is equivalent. .

@RequestMapping(value = "/hello",method =RequestMethod.GET) and  @GetMapping("/hello") It is equivalent. .
@RestController Annotation equivalent @ResponseBody + @Controller.

If necessary, return to the specified page , You need to use @Controller Coordinates with the view parser InternalResourceViewResolver Talent .
If you need to go back JSON,XML Or custom mediaType Content to page , You need to add to the corresponding method @ResponseBody annotation .

Be careful :@RestController annotation , amount to @Controller+@ResponseBody The combination of two notes , return json Data does not need to be preceded by a method @ResponseBody Note the , But use @RestController This annotation , Can't go back to jsp,html page , The view parser cannot parse jsp,html page

Run the program :

Thermal deployment

before this , If we change the code every time , You have to restart the server , And rerun the code , So with the hot deployment , Changed the code , All we need to do is IDEA Click on Build, You can see the effect directly , No need to restart the server .

pom.xml Add the following dependencies to the file :

After adding dependencies , stay IDEA The following prompt box will pop up in the lower right corner of

 

Click on “Import Changes" Will download automatically j The dependent jar package .

modify pom.xml,

 

If you don't want to go manually after each modification Build, Can be in IDEA Configure automatic Build

Then press the key combination :Shift+ALT+Ctrl+/ , choice “Registry”, enter , find “complier.automake.allow.when.app.running”, Click the tick to .

advantage : Simple , Support Spring-boot project , Support member level modification and hot deployment .

shortcoming : Only support spring-boot project .

Read configuration file

Modify the configuration file application.yml, Add the following code :

 

New profile class WebSiteConfig, The field name is consistent with the name in the configuration item .

 

In the controller class TestController Modify the code in :

 

 

Does it feel like using vs Development asp.net mvc The project is as simple as that ? Even better than .net It's convenient to operate the configuration file .

 

版权声明
本文为[Run if you can't beat it]所创,转载请带上原文链接,感谢

  1. 【计算机网络 12(1),尚学堂马士兵Java视频教程
  2. 【程序猿历程,史上最全的Java面试题集锦在这里
  3. 【程序猿历程(1),Javaweb视频教程百度云
  4. Notes on MySQL 45 lectures (1-7)
  5. [computer network 12 (1), Shang Xuetang Ma soldier java video tutorial
  6. The most complete collection of Java interview questions in history is here
  7. [process of program ape (1), JavaWeb video tutorial, baidu cloud
  8. Notes on MySQL 45 lectures (1-7)
  9. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  10. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  11. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  12. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  13. 【递归,Java传智播客笔记
  14. [recursion, Java intelligence podcast notes
  15. [adhere to painting for 386 days] the beginning of spring of 24 solar terms
  16. K8S系列第八篇(Service、EndPoints以及高可用kubeadm部署)
  17. K8s Series Part 8 (service, endpoints and high availability kubeadm deployment)
  18. 【重识 HTML (3),350道Java面试真题分享
  19. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  20. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  21. [re recognize HTML (3) and share 350 real Java interview questions
  22. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  23. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  24. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  25. RPC 1: how to develop RPC framework from scratch
  26. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  27. RPC 1: how to develop RPC framework from scratch
  28. 一次性捋清楚吧,对乱糟糟的,Spring事务扩展机制
  29. 一文彻底弄懂如何选择抽象类还是接口,连续四年百度Java岗必问面试题
  30. Redis常用命令
  31. 一双拖鞋引发的血案,狂神说Java系列笔记
  32. 一、mysql基础安装
  33. 一位程序员的独白:尽管我一生坎坷,Java框架面试基础
  34. Clear it all at once. For the messy, spring transaction extension mechanism
  35. A thorough understanding of how to choose abstract classes or interfaces, baidu Java post must ask interview questions for four consecutive years
  36. Redis common commands
  37. A pair of slippers triggered the murder, crazy God said java series notes
  38. 1、 MySQL basic installation
  39. Monologue of a programmer: despite my ups and downs in my life, Java framework is the foundation of interview
  40. 【大厂面试】三面三问Spring循环依赖,请一定要把这篇看完(建议收藏)
  41. 一线互联网企业中,springboot入门项目
  42. 一篇文带你入门SSM框架Spring开发,帮你快速拿Offer
  43. 【面试资料】Java全集、微服务、大数据、数据结构与算法、机器学习知识最全总结,283页pdf
  44. 【leetcode刷题】24.数组中重复的数字——Java版
  45. 【leetcode刷题】23.对称二叉树——Java版
  46. 【leetcode刷题】22.二叉树的中序遍历——Java版
  47. 【leetcode刷题】21.三数之和——Java版
  48. 【leetcode刷题】20.最长回文子串——Java版
  49. 【leetcode刷题】19.回文链表——Java版
  50. 【leetcode刷题】18.反转链表——Java版
  51. 【leetcode刷题】17.相交链表——Java&python版
  52. 【leetcode刷题】16.环形链表——Java版
  53. 【leetcode刷题】15.汉明距离——Java版
  54. 【leetcode刷题】14.找到所有数组中消失的数字——Java版
  55. 【leetcode刷题】13.比特位计数——Java版
  56. oracle控制用户权限命令
  57. 三年Java开发,继阿里,鲁班二期Java架构师
  58. Oracle必须要启动的服务
  59. 万字长文!深入剖析HashMap,Java基础笔试题大全带答案
  60. 一问Kafka就心慌?我却凭着这份,图灵学院vip课程百度云