macOS builds Spring Boot development environment, the specific content is as follows
Software and hardware environment
macOS Sierra
java 1.8.0_65
maven 3.5.0
idea 2017.1.5
Preface
I recently got into some knowledge about Java web and learn about Spring Boot, a popular development framework recently. From the perspective of a developer who has never been involved in Java web and spring, spring boot is indeed a very good framework with simple configuration and easy to get started. It is a good entry point for children who want to enter Java web.
maven installation
Here you choose maven as the build tool, and you can also use other things, such as gradle, etc. Go to the apache site to download the latest stable version of the zip package, unzip it to the specified directory, for example, here is /Users/djstava/Workshop/tools, and then edit the /Users/djstava/.bash_profile file, and add statements at the end of the file
export PATH=$PATH:/Users/djstava/Workshop/tools/apache-maven-3.5.0/bin
After the setup is complete, execute it in Terminal
source ~/.bash_profile
After the above operation, finally check whether the settings are correct and execute it in the terminal.
mvn -version
IDE selection
I choose jetbrains' IntelliJ IDEA here, of course you can also choose other ones, such as eclipse.
Create the first application and create a new project
Click Create New Project
Select Spring Initializer on the left, and select Java 1.8 by Project SDK.
Next is to fill in some basic project information, choose Maven Project for Type, choose Jar for Packaging, and you can write other things at will.
Dependency selection web, as shown in the figure
After the project is created successfully, the first construction process will be slower. After waiting for completion, click the green button in front of the main function in DemoApplication.java to start the project.
Open the browser and enter localhost:8080 to view
The browser output above is normal. Next, we add some code to make it display something. Create a new java class
HelloController.java source code
package com.xugaoxiang;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;/** * Created by djstava on 15/07/2017. */@RestControllerpublic class HelloController { @RequestMapping("/hello") public String hello() { return "Hello Spring Boot!"; }}Restart the project, view the browser, enter the address localhost:8080/hello
Project Explanation
@RestController and @RequestMapping, these are 2 very important annotations. @RestController is responsible for handling http requests, and @RequestMapping is responsible for mapping the url.
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.