Saturday, March 3, 2018

Name Greeter in Spring Boot

I am just a beginner in Spring MVC and Spring Boot this code will show how to mapped and pass a name and display on the template webpage.  I hope you will find my work useful.

I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental is  +63 (034) 4335675.




Sample Program Output


Program Listing

Demoapplication.java

package com.jake.demoapp;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplicationpublic class DemoappApplication {

   public static void main(String[] args) {
      SpringApplication.run(DemoappApplication.class, args);
   }
}

GreetingController.java

package com.jake.demoapp;

/** * Created by Jacob on 3/3/2018. */
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class GreetingController {
    @RequestMapping("/greeting")
    public String greeting(@RequestParam(value = "name", required = false, defaultValue = "World !!!") String name, Model model) {
        model.addAttribute("name", name);
        return "greeting";
    }

}

greeting.html

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Getting Started: Serving Web Content</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<style>
    p {
        font-family: Arial;
        font-weight: bold;
        size:25px;
        color:blue;
    }
</style>
<body>
<p th:text="'Hello, ' + ${name} + '!'" />
</body>
</html>






No comments:

Post a Comment