"Pratique a linguagem de programação e o framework mais utilizado por grandes corporações somente com seu Smartphone Android e sem necessidade de alterar configurações avançadas como "root" ou instalação de aplicativos suspeitos."
.
You will build a classic “Hello World!” endpoint which any browser can connect to. You can even tell it your name, and it will respond in a more friendly way.
- An Android phone or an Android Virtual Device (AVD)
- A command line Android app, I recommend Termux
- A Java™ Development Kit (JDK)
- Basic Linux command line knowledge
- Will and curiosity
Use start.spring.io to create a “web” project. In the “Dependencies” dialog search for and add the “web” dependency as shown in the screenshot. Hit the “Generate” button, download the zip.
Locate the downloaded demo.zip file path.
Copy it to the home Termux folder
cd && cp /storage/emulated/0/Download/demo.zip demo.zip
Unzip it and go to the demo unzipped folder
unzip demo.zip && cd demo
Verify if you have Java installed on your system
java -version
If no, update your system and install it
apt update -y && apt upgrade -y && apt install openjdk-17-jdk
Remove the original file DemoApplication.java located at src/main/java/com/example/demo folder.
rm src/main/java/com/example/demo/DemoApplication.java
Now create and edit a new DemoApplication.java adding the code below
nano -l -A -S -m src/main/java/com/example/demo/DemoApplication.java
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@GetMapping("/hello")
public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
return String.format("Hello %s!", name);
}
}
Save
CTRL + o
Exit
CTRL + x
./mvnw spring-boot:run
It will take some seconds to compile and show the results like this:
Open your browser and in the address bar at the top enter https://localhost:8080/hello .
You should get a nice friendly response like this:
What is displayed if you add ?name=HigorVaz
to the end of the URL?
.