Get the App
SLTechnology News&Howtos  ›  Development  › 

How to get started with SpringBoot for .NET programmers

Shulou Source: shulou.com Published: 2022-06-02 11:03:50 10月03日 Update

Net programmer how to enter SpringBoot, I believe that many inexperienced people do not know what to do, so this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

Preface

How to get started with Spring Boot as a. Net programmer. You don't need to use Eclipse, nor do you need to use IDEA. I'm used to VS, other IDE. But I have to say that VS Code is very good. I like it as soon as I use it. Microsoft provides VS Code with plug-ins to write Java, and you can happily write Java on VS Code.

I. Environmental construction

(1) install Java and configure environment variables. (there are many tutorials, which will not be discussed here.)

(2) install Maven and configuration. Reference https://www.cnblogs.com/eagle6688/p/7838224.html

(3) install VS Code

(4) install the Java development plug-in and configure VS Code's Java development environment. (Microsoft simplifies this step for us. Download the Vs Code Java installer, install it directly and write Java code. Download and connect to http://aka.ms/vscode-java-installer-win. This installer can be run repeatedly.)

Second, build the Maven project

(1) visit http://start.spring.io/

(2) Select Maven Project, Java and Spring Boot version 2.1.6, as shown in the figure.

Click Generate the Project to download the project package

(3) Open this folder with VS Code after decompression

The officially recommended project structure in version 2.16 is as follows:

Structures like this are more often used at present:

3. Write the interface and enter Hello World

(1) add modules that support web to pom.xml, and then save

Org.springframework.bootspring-boot-starter-web

VS Code automatically downloads the module after saving, or you can right-click pom.xml and click Update project configuration to update the configuration manually.

There are two modules by default in the pom.xml file:

Spring-boot-starter: core modules, including autoconfiguration support, logging, and YAML, which can be removed if the spring-boot-starter-web web module is introduced, because spring-boot-starter-web automatically relies on spring-boot-starter.

Spring-boot-starter-test: test module, including JUnit, Hamcrest, Mockito.

(2) write Controller content

@ RestControllerpublic class HelloWorldController {@ RequestMapping ("/ hello") public String index () {return "HelloWorld";}}

@ begins with a comment from Spring

@ RestController means that all the methods in Controller are output in json format, so you don't have to write anything about jackjson configuration.

RequestMapping is used to map Web requests, including access paths and parameters, on classes or methods.

(3) debug, then add configuration, and automatically generate startup Java configuration file

Running and debugging

Browser access: http://localhost:8080/hello successfully output Hello World

Everything looks simple, and now you can happily write Spring Boot code in VS Code

After reading the above, have you mastered how .NET programmers can get started with SpringBoot? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Tags: Configuration modules programs methods programmers content files more environment project pleasure code plug-ins versions structures problems Microsoft development support output Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS MariaDB Linux MySQL Docker