45 lines
1.4 KiB
Java
45 lines
1.4 KiB
Java
package com.webproglabs.lab1.lab1;
|
||
|
||
import org.springframework.web.bind.annotation.GetMapping;
|
||
import org.springframework.web.bind.annotation.RequestParam;
|
||
import org.springframework.web.bind.annotation.RestController;
|
||
|
||
import java.time.LocalDateTime;
|
||
import java.time.format.DateTimeFormatter;
|
||
import java.util.Random;
|
||
|
||
@RestController
|
||
public class Lab1Controller {
|
||
@GetMapping("/ilove")
|
||
public String ilove(@RequestParam(value = "thing", defaultValue = "cookies") String thing) {
|
||
return String.format("I love %s!", thing);
|
||
}
|
||
|
||
@GetMapping("/ask")
|
||
public String question(@RequestParam(value = "question", defaultValue = "Задайте вопрос") String question) {
|
||
if (question.contains("Задайте вопрос")) return question;
|
||
String[] answers = new String[] {
|
||
"Не знаю",
|
||
"Да",
|
||
"Нет",
|
||
"Спросите у мамы"
|
||
};
|
||
Random random = new Random();
|
||
return answers[random.nextInt(4)];
|
||
}
|
||
|
||
@GetMapping("/touppercase")
|
||
public String tuupper(@RequestParam(value = "content", defaultValue = "Введите строку") String content) {
|
||
return content.toUpperCase();
|
||
}
|
||
|
||
@GetMapping("/date")
|
||
public String date () {
|
||
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
|
||
LocalDateTime now = LocalDateTime.now();
|
||
return dtf.format(now);
|
||
}
|
||
|
||
|
||
}
|