Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/main/java/learn/epam/mlhh/controllers/HelloController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import learn.epam.mlhh.WebSecurityConfig;
import learn.epam.mlhh.entity.Candidate;
import learn.epam.mlhh.repository.CandidateAddRepo;
import learn.epam.mlhh.service.CandidateService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -19,8 +18,7 @@ public class HelloController {

@Autowired
private CandidateService candidateService;
@Autowired
private CandidateAddRepo addRepo;


@RequestMapping(value="/", method=RequestMethod.GET)
public String home(Map<String, Object> model) {
Expand All @@ -45,21 +43,21 @@ public String Table(Map<String, Object> model) {
else logger.error("Database error");
return "table";
}
@RequestMapping(value = "/add", method = RequestMethod.GET)
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String add(Map<String, Object> model) {

Iterable<Candidate> candidates = addRepo.findAll();
Iterable<Candidate> candidates = candidateService.findAll();
model.put("candidates", candidates);
return "add";
}

@RequestMapping(value = "/add", method = RequestMethod.POST)
@RequestMapping(value = "/addData", method = RequestMethod.POST)
public String addData(@RequestParam String name, @RequestParam Integer age, @RequestParam String gender, @RequestParam String region,
@RequestParam BigDecimal salary, @RequestParam String developer, @RequestParam Integer experience, @RequestParam String keyword, Map<String, Object> model) {

Candidate candidate = new Candidate(name, age, gender, region, salary, developer, experience, keyword);
addRepo.save(candidate);
Iterable<Candidate> candidates = addRepo.findAll();
candidateService.createCandidate(candidate);
Iterable<Candidate> candidates = candidateService.findAll();
model.put("candidates", candidates);
return "add";
}
Expand Down

This file was deleted.

6 changes: 3 additions & 3 deletions src/main/resources/templates/add.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
<div class="container">
<div class="row">
<div class="col-md-12">
<!--<input method="get">-->

<h1>Добавление данных в БД</h1>

<div>
<form method="post">
<form action="/addData" method="post">
<input type="text" name="name" placeholder="name"/>
<input type="text" name="age" placeholder="age"/>

<label for="gender">Gender:</label> &nbsp;
<label for="gender">Gender:</label>
<select name="gender" id="gender">
<option value="Male">Male</option>
<option value="Famale">Famale</option>
Expand Down