[JAVA] "Teacher, I want to implement a login function in Spring" ① Hello World

Introduction

1,HelloWorld 2, login form 3, data storage 4, login

download

Download STS If you get lost Introducing Spring Tool Suite to Windows-Qiita

Creating a project

1,File⇒New⇒Spring Starter Project 1.jpg 1,「Name」=「HelloWorld」 2,「Package」=「com.login」 2.jpg 1,Web⇒Spring Web 3.jpg

Class creation

1, Right-click on "com.login". New⇒Class 4.jpg 1、「Name」=「HomeController」 5.jpg

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>

10.jpg

Create HTML file

1, src / main / resources Right click on "templates". New⇒Other 6.jpg

  1. Enter "html".

  2. Select "HTML File". 7.jpg 1、「File name」=「hello.html」 8.jpg

  3. 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>

Run

Right click on the project "Hello World". "Run As" ⇒ "Spring Boot App" 9.jpg 1, enter on the browser ⇒ "localhost: 8080 / hello" WS000003.JPG

Impressions

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";
    }

Confirmation of what you did

① 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

"Teacher, I want to implement a login function in Spring" ① Hello World
I tried to make a login function in Java
I want to define a function in Rails Console
I want to implement a product information editing function ~ part1 ~
Let's create a TODO application in Java 2 I want to create a template with Spring Initializr and make a Hello world
I want to use a little icon in Rails
I want to click a GoogleMap pin in RSpec
I want to add a delete function to the comment function
I want to find a relative path in a situation using Path
I want to make a function with kotlin and java!
Even in Java, I want to output true with a == 1 && a == 2 && a == 3
I want to create a Parquet file even in Ruby
Spring Boot Hello World in Eclipse
Implement simple login function in Rails
I want to Flash Attribute in Spring even if I set a reverse proxy! (do not do)
I made a function to register images with API in Spring Framework. Part 2 (Client Edition)
[Rails] A simple way to implement a self-introduction function in your profile
I tried to implement Ajax processing of like function in Rails
I want to add a browsing function with ruby on rails
[Ruby] I want to put an array in a variable. I want to convert to an array
Let's write a test code for login function in Spring Boot
I want to develop a web application!
I want to write a nice build.gradle
I want to write a unit test!
Try to implement login function with Spring-Boot
[Practice! ] Display Hello World in Spring Boot
I want to use @Autowired in Servlet
[Rails] I want to send data of different models in a form
I want to select multiple items with a custom layout in Dialog
I wanted to implement a slide show in a fashionable way with slick.
I want to display a PDF in Chinese (Korean) with thin reports
My memorandum that I want to make ValidationMessages.properties UTF8 in Spring Boot
I want to ForEach an array with a Lambda expression in Java
[Java Spring MVC] I want to use DI in my own class
Output Hello World in kotlin's simple main function
I tried to implement polymorphic related in Nogizaka.
I want to use arrow notation in Ruby
[Rails / JavaScript / Ajax] I tried to create a like function in two ways.
[Swift] How to implement the LINE login function
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (Javassist second decoction)
[Ruby] I want to do a method jump!
I tried to implement deep learning in Java
I want to pass APP_HOME to logback in Gradle
[Android] Implement a function to display passwords quickly
I wanted to make (a == 1 && a == 2 && a == 3) true in Java
I want to simply write a repeating string
How to add a classpath in Spring Boot
I want to design a structured exception handling
rsync4j --I want to touch rsync in Java.
How to implement a like feature in Rails
[Xcode] I want to manage images in folders
I want to be eventually even in kotlin
Try to display hello world with spring + gradle
How to make a follow function in Rails
I tried to implement a server using Netty
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (black magic edition)
I want to get the value in Ruby
I tried to create a shopping site administrator function / screen with Java and Spring
I tried to move Hello World (+ α) written in C language from JavaScript [WebAssembly]
I want to use PowerMock in a class that combines parameterized tests and ordinary tests
[Rails] I want to display the link destination of link_to in a separate tab