-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TODOs #3
Open
marekmasek
wants to merge
2
commits into
martineez:main
Choose a base branch
from
marekmasek:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
TODOs #3
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,119 +1,130 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>cz.inventi.academy</groupId> | ||
<artifactId>springweb</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<packaging>war</packaging> | ||
<name>Basic Spring Web</name> | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>cz.inventi.academy</groupId> | ||
<artifactId>springweb</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<packaging>war</packaging> | ||
<name>Basic Spring Web</name> | ||
|
||
<properties> | ||
<!-- Common --> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<java.version>1.8</java.version> | ||
<spring.version>4.1.6.RELEASE</spring.version> | ||
<junit.version>4.12</junit.version> | ||
<properties> | ||
<!-- Common --> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<java.version>1.8</java.version> | ||
<spring.version>4.1.6.RELEASE</spring.version> | ||
<junit.version>4.12</junit.version> | ||
|
||
<!-- Web --> | ||
<jsp.version>2.2</jsp.version> | ||
<jstl.version>1.2</jstl.version> | ||
<servlet.version>3.1.0</servlet.version> | ||
<hibernate.validator.version>5.2.2.Final</hibernate.validator.version> | ||
<!-- Web --> | ||
<jsp.version>2.2</jsp.version> | ||
<jstl.version>1.2</jstl.version> | ||
<servlet.version>3.1.0</servlet.version> | ||
<hibernate.validator.version>6.2.3.Final</hibernate.validator.version> | ||
|
||
<!-- Logging --> | ||
<slf4j.version>1.7.12</slf4j.version> | ||
<logback.version>1.1.3</logback.version> | ||
</properties> | ||
<!-- Logging --> | ||
<slf4j.version>1.7.12</slf4j.version> | ||
<logback.version>1.1.3</logback.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<!-- Spring MVC --> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-webmvc</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
<dependencies> | ||
<!-- Spring MVC --> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-webmvc</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
|
||
<!-- Other Web dependencies --> | ||
<dependency> | ||
<groupId>org.hibernate</groupId> | ||
<artifactId>hibernate-validator</artifactId> | ||
<version>${hibernate.validator.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>javax.servlet-api</artifactId> | ||
<version>${servlet.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.servlet.jsp</groupId> | ||
<artifactId>jsp-api</artifactId> | ||
<version>${jsp.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>jstl</artifactId> | ||
<version>${jstl.version}</version> | ||
</dependency> | ||
<!-- Other Web dependencies --> | ||
<dependency> | ||
<groupId>org.hibernate</groupId> | ||
<artifactId>hibernate-validator</artifactId> | ||
<version>${hibernate.validator.version}</version> | ||
</dependency> | ||
|
||
<!-- Logging --> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>${slf4j.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<version>${logback.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>javax.servlet-api</artifactId> | ||
<version>${servlet.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.servlet.jsp</groupId> | ||
<artifactId>jsp-api</artifactId> | ||
<version>${jsp.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>jstl</artifactId> | ||
<version>${jstl.version}</version> | ||
</dependency> | ||
|
||
<!-- Testing --> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-test</artifactId> | ||
<version>${spring.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>${junit.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.3</version> | ||
<configuration> | ||
<source>${java.version}</source> | ||
<target>${java.version}</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<version>2.7</version> | ||
<configuration> | ||
<encoding>${project.build.sourceEncoding}</encoding> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-war-plugin</artifactId> | ||
<version>2.6</version> | ||
<configuration> | ||
<warName>springweb-${project.version}</warName> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<!-- Logging --> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>${slf4j.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<version>${logback.version}</version> | ||
</dependency> | ||
|
||
<!-- Testing --> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-test</artifactId> | ||
<version>${spring.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>${junit.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.3</version> | ||
<configuration> | ||
<source>${java.version}</source> | ||
<target>${java.version}</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<version>2.7</version> | ||
<configuration> | ||
<encoding>${project.build.sourceEncoding}</encoding> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-war-plugin</artifactId> | ||
<version>3.3.2</version> | ||
<configuration> | ||
<warName>springweb-${project.version}</warName> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.cargo</groupId> | ||
<artifactId>cargo-maven3-plugin</artifactId> | ||
<version>1.9.2</version> | ||
<configuration> | ||
<container> | ||
<containerId>tomcat9x</containerId> | ||
<type>embedded</type> | ||
</container> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
51 changes: 31 additions & 20 deletions
51
src/main/java/cz/inventi/academy/springweb/controller/MainController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,61 @@ | ||
package cz.inventi.academy.springweb.controller; | ||
|
||
import java.util.Locale; | ||
|
||
import javax.validation.Valid; | ||
|
||
import cz.inventi.academy.springweb.model.Book; | ||
import cz.inventi.academy.springweb.service.BookService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.MessageSource; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.validation.BindingResult; | ||
import org.springframework.web.bind.annotation.ModelAttribute; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
import cz.inventi.academy.springweb.model.Book; | ||
import javax.validation.Valid; | ||
|
||
//TODO: Write annotation for controller | ||
import static org.springframework.context.i18n.LocaleContextHolder.getLocale; | ||
import static org.springframework.web.bind.annotation.RequestMethod.GET; | ||
import static org.springframework.web.bind.annotation.RequestMethod.POST; | ||
|
||
@Controller | ||
public class MainController { | ||
|
||
// TODO: Define bookService and messageSource parameter and inject it via spring annotation | ||
@Autowired | ||
private BookService bookService; | ||
@Autowired | ||
private MessageSource messageSource; | ||
|
||
@RequestMapping("/") | ||
public String index() { | ||
return "index"; | ||
} | ||
|
||
// TODO: Add @RequestMapping with correct parameters (value, method) | ||
@RequestMapping(value = "/list", method = GET) | ||
public String list(Model model) { | ||
// TODO: Load all books | ||
// TODO: Add books to model | ||
model.addAttribute("books", bookService.loadBooks()); | ||
return "list"; | ||
} | ||
|
||
// TODO: Add @RequestMapping with correct parameters (value, method) | ||
@RequestMapping(value = "/edit", method = GET) | ||
public String formEdit(Model model) { | ||
// TODO: Add new book to model | ||
model.addAttribute("book", new Book()); | ||
return "edit"; | ||
} | ||
|
||
// TODO: Add @RequestMapping with correct parameters (value, method) | ||
public String formSave(//TODO: Use correct types (validate input book)) { | ||
// TODO: When there are no error, then save book and add text message ("info.book.saved") to model from resource bundle | ||
@RequestMapping(value = "/edit", method = POST) | ||
public String formSave(Model model, @Valid @ModelAttribute("book") Book book, BindingResult bindingResult) { | ||
if (!bindingResult.hasErrors()) { | ||
bookService.save(book); | ||
model.addAttribute("info", messageSource.getMessage("info.book.saved", null, getLocale())); | ||
} | ||
|
||
return "edit"; | ||
} | ||
|
||
// TODO: Add @RequestMapping with correct parameters (value, method) | ||
public String delete(//TODO: Use correct types (e.g. PathVariable)) { | ||
// TODO: Delete book by id | ||
// TODO: Load all books | ||
// TODO: Add books to model | ||
@RequestMapping(value = "/delete/{id}", method = GET) | ||
public String delete(Model model, @PathVariable long id) { | ||
bookService.delete(id); | ||
model.addAttribute("books", bookService.loadBooks()); | ||
return "redirect:/list"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 5 additions & 4 deletions
9
src/main/java/cz/inventi/academy/springweb/service/BookServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:context="http://www.springframework.org/schema/context" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> | ||
|
||
<context:component-scan base-package="cz.inventi.academy.springweb"/> | ||
|
||
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> | ||
<property name="basename" value="messages"/> | ||
<property name="defaultEncoding" value="UTF-8"/> | ||
</bean> | ||
|
||
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/> | ||
|
||
<!-- TODO: Define component scan and message source resource bundle (UTF-8) --> | ||
</beans> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<property name="defaultEncoding" value="UTF-8"/>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@martineez ahoj, to kodovani tam mam, mam to odebrat?