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
7f0b359f
authored
May 04, 2023
by
mrf00020
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Ejemplo prof no funciona
parent
155d4c0e
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
264 additions
and
33 deletions
pom.xml
src/main/java/com/example/fmaker/Employee.java
src/main/java/com/example/fmaker/EmployeeController.java
src/main/java/com/example/fmaker/EmployeeRepository.java
src/main/java/com/example/fmaker/FmakerApplication.java
src/main/java/com/example/fmaker/MainAplication.java
src/main/resources/application.properties
src/main/resources/templates/index.ftl
src/main/resources/templates/showemployees.ftl
src/main/webapp/WEB-INF/index.ftl
src/test/java/com/example/fmaker/FmakerApplicationTests.java → src/test/java/com/example/fmaker/MainAplicationTests.java
pom.xml
View file @
7f0b359f
...
@@ -55,6 +55,11 @@
...
@@ -55,6 +55,11 @@
<artifactId>
tomcat-embed-jasper
</artifactId>
<artifactId>
tomcat-embed-jasper
</artifactId>
<scope>
provided
</scope>
<scope>
provided
</scope>
</dependency>
</dependency>
<dependency>
<groupId>
javax.persistence
</groupId>
<artifactId>
javax.persistence-api
</artifactId>
<version>
2.2
</version>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
src/main/java/com/example/fmaker/Employee.java
0 → 100644
View file @
7f0b359f
package
com
.
example
.
fmaker
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.GenerationType
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
@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
+
"]"
;
}
}
\ No newline at end of file
src/main/java/com/example/fmaker/EmployeeController.java
0 → 100644
View file @
7f0b359f
package
com
.
example
.
fmaker
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
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
com.example.fmaker.Employee
;
import
com.example.fmaker.EmployeeRepository
;
@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/fmaker/EmployeeRepository.java
0 → 100644
View file @
7f0b359f
package
com
.
example
.
fmaker
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.stereotype.Repository
;
import
com.example.fmaker.Employee
;
@Repository
public
interface
EmployeeRepository
extends
JpaRepository
<
Employee
,
Long
>{
}
\ No newline at end of file
src/main/java/com/example/fmaker/FmakerApplication.java
deleted
100644 → 0
View file @
155d4c0e
package
com
.
example
.
fmaker
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
@SpringBootApplication
public
class
FmakerApplication
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
FmakerApplication
.
class
,
args
);
}
}
src/main/java/com/example/fmaker/MainAplication.java
0 → 100644
View file @
7f0b359f
package
com
.
example
.
fmaker
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.CommandLineRunner
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
java.util.List
;
import
com.example.fmaker.Employee
;
import
com.example.fmaker.EmployeeRepository
;
@SpringBootApplication
public
class
MainAplication
implements
CommandLineRunner
{
@Autowired
private
EmployeeRepository
repository
;
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
MainAplication
.
class
,
args
);
}
@Override
public
void
run
(
String
...
args
)
throws
Exception
{
repository
.
save
(
new
Employee
(
"Ramesh"
,
"Fadatare"
,
"ramesh@gmail.com"
));
repository
.
save
(
new
Employee
(
"Tom"
,
"Cruise"
,
"tom@gmail.com"
));
repository
.
save
(
new
Employee
(
"John"
,
"Cena"
,
"john@gmail.com"
));
repository
.
save
(
new
Employee
(
"tony"
,
"stark"
,
"stark@gmail.com"
));
// get list of employees
List
<
Employee
>
employees
=
repository
.
findAll
();
employees
.
forEach
(
employee
->
System
.
out
.
println
(
employee
.
toString
()));
}
}
src/main/resources/application.properties
View file @
7f0b359f
spring.freemarker.template-loader-path
:
classhpath:/templates
spring.freemarker.suffix
:
.ftl
src/main/resources/templates/index.ftl
0 → 100644
View file @
7f0b359f
<!DOCTYPE html>
<html>
<head>
<title>
Home page
</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"
>
</head>
<body>
<div
class=
"container"
>
<div
class=
"panel panel-primary"
>
<div
class=
"panel-heading"
>
<h2>
Home Page
</h2>
</div>
<a
href=
"showEmployees"
>
Show Employees (Retrieve employee data from database)
</a>
</div>
</div>
</body>
</html>
showEmployees.ftl
<!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/main/resources/templates/showemployees.ftl
0 → 100644
View file @
7f0b359f
<!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/main/webapp/WEB-INF/index.ftl
deleted
100644 → 0
View file @
155d4c0e
<html>
<head>
<title>
${title}
</title>
</head>
<body>
<h1>
${title}
</h1>
<p>
${exampleObject.name} by ${exampleObject.developer}
</p>
<ul>
<
#
list
systems
as
system
>
<li>
${system_index + 1}. ${system.name} from ${system.developer}
</li>
</
#
list>
</ul>
</body>
</html>
\ No newline at end of file
src/test/java/com/example/fmaker/
FmakerAp
plicationTests.java
→
src/test/java/com/example/fmaker/
MainA
plicationTests.java
View file @
7f0b359f
...
@@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test;
...
@@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest
;
@SpringBootTest
@SpringBootTest
class
FmakerAp
plicationTests
{
class
MainA
plicationTests
{
@Test
@Test
void
contextLoads
()
{
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