Commit 5217c61a by Javier Ferreira

form para agregar tecnologias nuevas

parent a2013f11
package com.roshka.controller;
import com.roshka.modelo.Tecnologia;
import com.roshka.repositorio.TecnologiaRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class TecnologiaController {
TecnologiaRepository tecRepo;
@Autowired
public TecnologiaController(TecnologiaRepository tecRepo){
this.tecRepo = tecRepo;
}
@GetMapping("/tecnologia")
public String addtecnologiaView(Model model) {
model.addAttribute("tecnologia", new Tecnologia());
return "tecnologia-form";
}
@PostMapping("/tecnologia")
public String addtecnologia(@ModelAttribute("tecnologia") Tecnologia tecnologia) {
tecRepo.save(tecnologia);
return "redirect:/";
}
}
...@@ -29,7 +29,7 @@ public class Tecnologia { ...@@ -29,7 +29,7 @@ public class Tecnologia {
this.id = id; this.id = id;
} }
public String getNombre() { public String getNombre() {
return nombre.toLowerCase(); return nombre;
} }
public void setNombre(String nombre) { public void setNombre(String nombre) {
this.nombre = nombre; this.nombre = nombre;
......
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<title>Hello, world!</title>
<style type="text/css" media="screen">
body {
background-color: rgba(98, 0, 255, 0)
} </style>
</head>
<body>
<form:form action="/tecnologia" method="post" modelAttribute="tecnologia">
<form:label path="nombre">name: </form:label> <form:input type="text" path="nombre"/>
<input type="submit" value="submit"/>
</form:form>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment