GreetingService.java
spring_boot/code/beginner/src/main/java/com/example/demo/service/GreetingService.java
package com.example.demo.service;
import org.springframework.stereotype.Service;
/**
* Service that generates greeting messages.
* <p>
* {@code @Service} is a stereotype of {@code @Component}; Spring registers this class as a bean
* and injects it wherever needed (e.g. into {@link com.example.demo.controller.HelloController}).
* Business logic that does not handle HTTP directly belongs in a service layer.
*/
@Service
public class GreetingService {
/**
* Builds a greeting string for the given name.
*
* @param name the name to include in the greeting (e.g. "Student")
* @return greeting in the form "Hello, <name>!"
*/
public String greet(String name) {
return "Hello, " + name + "!";
}
}
Artículos relacionados
DemoApplication.java
DemoApplication.java — java source code from the spring boot learning materials (spring_boot/code/advanced/src/main/java/com/example/demo/DemoApplication.java).
Leer artículo →CustomHealthIndicator.java
CustomHealthIndicator.java — java source code from the spring boot learning materials (spring_boot/code/advanced/src/main/java/com/example/demo/actuator/CustomHealthIndicator.java).
Leer artículo →SecurityConfig.java
SecurityConfig.java — java source code from the spring boot learning materials (spring_boot/code/advanced/src/main/java/com/example/demo/config/SecurityConfig.java).
Leer artículo →ProductController.java
ProductController.java — java source code from the spring boot learning materials (spring_boot/code/advanced/src/main/java/com/example/demo/controller/ProductController.java).
Leer artículo →PublicController.java
PublicController.java — java source code from the spring boot learning materials (spring_boot/code/advanced/src/main/java/com/example/demo/controller/PublicController.java).
Leer artículo →ProductCreateRequest.java
ProductCreateRequest.java — java source code from the spring boot learning materials (spring_boot/code/advanced/src/main/java/com/example/demo/dto/ProductCreateRequest.java).
Leer artículo →