SpringBootdevelopmentGuidelines GEMS25
SpringBootdevelopmentGuidelines GEMS25
● Add plugin for jsp – help-eclipse market place – search for jsp – Eclipse
enterprise java web developer toolkit…
● Create spring boot web application on url https://start.spring.io/
● Select
o Maven, Java (17), Spring boot version > 3+ (At present 3.3.0)
o proj metadata - group = com.springboot, artifact = demoproj01
o It will form package and name (do not change it)
o Packaging = jar, Java version = Java17
o Add required dependencies [Spring Web, Thymeleaf, Lombok,
Spring data JPA, Validation
o Click Generate.
● This generates the project zip file. Extract it and paste it in workspace.
● Load this project from file import->“open project from file system”
● Open pom.xml and add following dependencies (without this it will
download application)
<!--
https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-jasper -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<!--
https://mvnrepository.com/artifact/jakarta.servlet.jsp.jstl/jakarta.servlet.jsp.jstl-api -->
<dependency>
<groupId>jakarta.servlet.jsp.jstl</groupId>
<artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
</dependency>
@GetMapping("/home")
public ResponseEntity<List<String>> home() {
List<String> messages = new ArrayList<String>();
messages.add("Good morning");
messages.add("Hello");
try {
return ResponseEntity.status(HttpStatus.CREATED).body(messages);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
}
}
}
@Controller
@RequestMapping("/")
public class HelloController {
@GetMapping("/home")
public String home(Model model) {
model.addAttribute("messages", HomeService.messages());
return "home";
}
}
@GetMapping("/home")
public ModelAndView home(ModelAndView mav) {
@Controller
@RequestMapping("/")
public class HomeController {
@GetMapping ("/welcome")
public ModelAndView welcome() {
System.out.println("Insode welcome");
ModelAndView mav = new ModelAndView();
mav.addObject("welcome_message", "Welcome to the Kailash Tours");
mav.setViewName("ask_name");
return mav;
}
@PostMapping ("/display")
public ModelAndView displayName(@RequestParam(name = "user_name") String user)
{
System.out.println("In display: " + user);
ModelAndView mav = new ModelAndView();
mav.addObject("greetings", "Hi " + user);
mav.setViewName("greetings");
return mav;
}
}