Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Manuel Ruiz Fernández
/
freemarker
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Merge Requests
0
Pipelines
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
649118c2
authored
May 04, 2023
by
Francisco Javier
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
freemarket con h2
parent
73c49d74
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
7 additions
and
190 deletions
src/main/java/com/example/FreeMarket/FreeMarketApplication.java
src/main/java/com/example/FreeMarket/controller/EmployeeController.java
src/main/java/com/example/FreeMarket/controller/SalasController.java
src/main/java/com/example/FreeMarket/model/Employee.java
src/main/java/com/example/FreeMarket/repository/EmployeeRepository.java
src/main/resources/application.properties
src/main/resources/templates/index.ftl
src/main/resources/templates/showEmployees.ftl
src/test/java/com/example/FreeMarket/FreeMarketApplicationTests.java
src/main/java/com/example/FreeMarket/FreeMarketApplication.java
View file @
649118c2
package
com
.
example
.
FreeMarket
;
package
com
.
example
.
FreeMarket
;
import
com.example.FreeMarket.model.Employee
;
import
com.example.FreeMarket.model.Sala
;
import
com.example.FreeMarket.model.Sala
;
import
com.example.FreeMarket.repository.EmployeeRepository
;
import
com.example.FreeMarket.repository.SalaRepository
;
import
com.example.FreeMarket.repository.SalaRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.CommandLineRunner
;
import
org.springframework.boot.CommandLineRunner
;
...
@@ -15,9 +13,6 @@ import java.util.List;
...
@@ -15,9 +13,6 @@ import java.util.List;
public
class
FreeMarketApplication
implements
CommandLineRunner
{
public
class
FreeMarketApplication
implements
CommandLineRunner
{
@Autowired
@Autowired
private
EmployeeRepository
employeeRepository
;
@Autowired
private
SalaRepository
salaRepository
;
private
SalaRepository
salaRepository
;
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
...
@@ -27,19 +22,5 @@ public class FreeMarketApplication implements CommandLineRunner {
...
@@ -27,19 +22,5 @@ public class FreeMarketApplication implements CommandLineRunner {
@Override
@Override
public
void
run
(
String
...
args
)
throws
Exception
{
public
void
run
(
String
...
args
)
throws
Exception
{
employeeRepository
.
save
(
new
Employee
(
"Ramesh"
,
"Fadatare"
,
"ramesh@gmail.com"
));
employeeRepository
.
save
(
new
Employee
(
"Tom"
,
"Cruise"
,
"tom@gmail.com"
));
employeeRepository
.
save
(
new
Employee
(
"John"
,
"Cena"
,
"john@gmail.com"
));
employeeRepository
.
save
(
new
Employee
(
"tony"
,
"stark"
,
"stark@gmail.com"
));
// get list of employees
List
<
Employee
>
employees
=
employeeRepository
.
findAll
();
employees
.
forEach
(
employee
->
System
.
out
.
println
(
employee
.
toString
()));
salaRepository
.
save
(
new
Sala
(
"6 mesas"
,
"1 planta"
,
"3m cuadrados"
));
salaRepository
.
save
(
new
Sala
(
"2 mesas"
,
"2 planta"
,
"6m cuadrados"
));
salaRepository
.
save
(
new
Sala
(
"3 mesas"
,
"3 planta"
,
"9m cuadrados"
));
List
<
Sala
>
salas
=
salaRepository
.
findAll
();
salas
.
forEach
(
sala
->
System
.
out
.
println
(
sala
.
toString
()));
}
}
}
}
src/main/java/com/example/FreeMarket/controller/EmployeeController.java
deleted
100644 → 0
View file @
73c49d74
package
com
.
example
.
FreeMarket
.
controller
;
import
com.example.FreeMarket.model.Employee
;
import
com.example.FreeMarket.repository.EmployeeRepository
;
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.servlet.ModelAndView
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
@Controller
public
class
EmployeeController
{
@Autowired
private
EmployeeRepository
employeeRepository
;
/*@GetMapping("/")
public String index(Model model) {
return "index";
}*/
@GetMapping
(
"/showEmployees"
)
public
ModelAndView
showCities
()
{
List
<
Employee
>
employees
=
employeeRepository
.
findAll
();
Map
<
String
,
Object
>
params
=
new
HashMap
<
String
,
Object
>();
params
.
put
(
"employees"
,
employees
);
return
new
ModelAndView
(
"showEmployees"
,
params
);
}
}
src/main/java/com/example/FreeMarket/controller/SalasController.java
View file @
649118c2
package
com
.
example
.
FreeMarket
.
controller
;
package
com
.
example
.
FreeMarket
.
controller
;
import
com.example.FreeMarket.model.Employee
;
import
com.example.FreeMarket.model.Sala
;
import
com.example.FreeMarket.model.Sala
;
import
com.example.FreeMarket.repository.SalaRepository
;
import
com.example.FreeMarket.repository.SalaRepository
;
import
jakarta.annotation.PostConstruct
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.ui.Model
;
...
@@ -15,7 +13,6 @@ import org.springframework.web.servlet.ModelAndView;
...
@@ -15,7 +13,6 @@ import org.springframework.web.servlet.ModelAndView;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.logging.Logger
;
@Controller
@Controller
public
class
SalasController
{
public
class
SalasController
{
...
...
src/main/java/com/example/FreeMarket/model/Employee.java
deleted
100644 → 0
View file @
73c49d74
package
com
.
example
.
FreeMarket
.
model
;
import
jakarta.persistence.*
;
@Entity
@Table
(
name
=
"employees"
)
public
class
Employee
{
private
long
id
;
private
String
firstName
;
private
String
lastName
;
private
String
emailId
;
public
Employee
()
{
}
public
Employee
(
String
firstName
,
String
lastName
,
String
emailId
)
{
this
.
firstName
=
firstName
;
this
.
lastName
=
lastName
;
this
.
emailId
=
emailId
;
}
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
AUTO
)
public
long
getId
()
{
return
id
;
}
public
void
setId
(
long
id
)
{
this
.
id
=
id
;
}
@Column
(
name
=
"first_name"
,
nullable
=
false
)
public
String
getFirstName
()
{
return
firstName
;
}
public
void
setFirstName
(
String
firstName
)
{
this
.
firstName
=
firstName
;
}
@Column
(
name
=
"last_name"
,
nullable
=
false
)
public
String
getLastName
()
{
return
lastName
;
}
public
void
setLastName
(
String
lastName
)
{
this
.
lastName
=
lastName
;
}
@Column
(
name
=
"email_address"
,
nullable
=
false
)
public
String
getEmailId
()
{
return
emailId
;
}
public
void
setEmailId
(
String
emailId
)
{
this
.
emailId
=
emailId
;
}
@Override
public
String
toString
()
{
return
"Employee [id="
+
id
+
", firstName="
+
firstName
+
", lastName="
+
lastName
+
", emailId="
+
emailId
+
"]"
;
}
}
src/main/java/com/example/FreeMarket/repository/EmployeeRepository.java
deleted
100644 → 0
View file @
73c49d74
package
com
.
example
.
FreeMarket
.
repository
;
import
com.example.FreeMarket.model.Employee
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.stereotype.Repository
;
@Repository
public
interface
EmployeeRepository
extends
JpaRepository
<
Employee
,
Long
>
{
}
src/main/resources/application.properties
View file @
649118c2
spring.freemarker.template-loader-path
:
classpath:/templates
spring.freemarker.template-loader-path
:
classpath:/templates
spring.freemarker.suffix
:
.ftl
spring.freemarker.suffix
:
.ftl
spring.datasource.url
=
jdbc:h2:~/h2db/dawlibros;MODE=LEGACY;AUTO_SERVER=TRUE
spring.datasource.username
=
dawuser
spring.datasource.password
=
dawuser
\ No newline at end of file
src/main/resources/templates/index.ftl
View file @
649118c2
...
@@ -15,11 +15,9 @@
...
@@ -15,11 +15,9 @@
<div
class=
"panel-heading"
>
<div
class=
"panel-heading"
>
<h2>
Home Page
</h2>
<h2>
Home Page
</h2>
</div>
</div>
<a
href=
"show
Employees"
>
Show Employees (Retrieve employee data from database
)
</a>
<a
href=
"show
Salas"
>
Ver Salas (Recuperar datos de salas de la base de datos.
)
</a>
<br/>
<br/>
<a
href=
"showSalas"
>
Show Salas (Retrieve employee data from database)
</a>
<a
href=
"home"
>
home
</a>
<br/>
<a
href=
"home"
>
home (Retrieve employee data from database)
</a>
</div>
</div>
</div>
</div>
</body>
</body>
...
...
src/main/resources/templates/showEmployees.ftl
deleted
100644 → 0
View file @
73c49d74
<!DOCTYPE html>
<html>
<head>
<title>
Employee List
</title>
<meta
charset=
"UTF-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<link
href=
"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
rel=
"stylesheet"
integrity=
"sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin=
"anonymous"
>
<link
rel=
"stylesheet"
href=
"css/style.css"
>
</head>
<body>
<div
class=
"container"
>
<div
class=
"panel panel-primary"
>
<div
class=
"panel-heading"
>
<h2>
Employee List
</h2>
</div>
<div
class=
"panel-body"
>
<table
class=
"table table-striped"
>
<thead>
<tr>
<th>
Firstname
</th>
<th>
Lastname
</th>
<th>
Email
</th>
</tr>
</thead>
<tbody>
<
#
list
employees
as
employee
>
<tr>
<td>
${employee.firstName}
</td>
<td>
${employee.lastName}
</td>
<td>
${employee.emailId}
</td>
</tr>
</
#
list>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
\ No newline at end of file
src/test/java/com/example/FreeMarket/FreeMarketApplicationTests.java
deleted
100644 → 0
View file @
73c49d74
package
com
.
example
.
FreeMarket
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.test.context.SpringBootTest
;
@SpringBootTest
class
FreeMarketApplicationTests
{
@Test
void
contextLoads
()
{
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment