1,HelloWorld 2, login form 3, data storage 4, login
Download STS If you get lost Introducing Spring Tool Suite to Windows-Qiita
1,File⇒New⇒Spring Starter Project 1,「Name」=「HelloWorld」 2,「Package」=「com.login」 1,Web⇒Spring Web
1, Right-click on "com.login". New⇒Class 1、「Name」=「HomeController」
1, Overwrite the following in the created class
HomeController
package com.login;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class HomeController {
@GetMapping("/hello")
public String home(Model model) {
model.addAttribute("hello","Hello World!");
return "hello";
}
}
1, Add the following to pom.xml
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
1, src / main / resources Right click on "templates". New⇒Other
Enter "html".
Select "HTML File". 1、「File name」=「hello.html」
Overwrite the following in the created "hello.html".
hello.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1 th:text="${hello}"></h1>
</body>
</html>
Right click on the project "Hello World". "Run As" ⇒ "Spring Boot App" 1, enter on the browser ⇒ "localhost: 8080 / hello"
Teacher: (The result is the same as writing "Hello World" in a file with an html extension, but you will notice the great potential by scratching the server side.) Takashi: Teacher, isn't this the same as writing "Hello World" in a file with an html extension? teacher:··· By running the server, it will display the number of 30 billion or anything in order from 1. With the human brain, you can create and decipher codes that take time to understand. What's more, you can even display practice sentences to become "AHO" when the numbers are multiples of 3 and numbers with 3!
CreateAho
@GetMapping("/hello")
public String home(Model model) {
List<String> aho=new ArrayList<String>();
int a,b,c;
for(int i=1;i<=1000;i++) {
a=i/10;
b=i/100;
c=i/1000;
if(i%3==0 || i%10==3 || a%10==3|| b%10==3||c%10==3) {
aho.add("AHO");
continue;
}
aho.add(String.valueOf(i));
}
model.addAttribute("hello", aho);
return "hello";
}
① Create Java project (Spring) (2) Create Controller class (perform mapping) ③ Create Html file (use server side function) ④ Edit the project configuration file (Maven xml) ⑤ Web page display using Web server software (apache)
Recommended Posts