И так , по порядку:
Book.java
@Entity
@Table(name = "library")
public class Book {
private int id;
private String title;
private String description;
private String author;
private String isbn;
private Integer printYear;
private Boolean readAlready;
@Id
@Column(name = "id")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Basic
@Column(name = "title")
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@Basic
@Column(name = "description")
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Basic
@Column(name = "author")
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
@Basic
@Column(name = "isbn")
public String getIsbn() {
return isbn;
}
public void setIsbn(String isbn) {
this.isbn = isbn;
}
@Basic
@Column(name = "printYear")
public Integer getPrintYear() {
return printYear;
}
public void setPrintYear(Integer printYear) {
this.printYear = printYear;
}
@Basic
@Column(name = "readAlready")
public Boolean getReadAlready() {
return readAlready;
}
public void setReadAlready(Boolean readAlready) {
this.readAlready = readAlready;
}
hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<mapping class="well.model.Book"/>
<!-- DB schema will be updated if needed -->
<!-- <property name="hbm2ddl.auto">update</property> -->
</session-factory>
</hibernate-configuration>
dispatcher-servlet.xml
<?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"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
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
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:component-scan base-package = "well.controllers" />
<bean class = "org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name = "prefix" value = "/WEB-INF/jsp/" />
<property name = "suffix" value = ".jsp" />
</bean>
<bean id="hibernate" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml" />
</bean>
<bean id="bookDao" class="well.dao.BookDaoImpl">
<property name="sessionFactory" ref="hibernate"/>
</bean>
<bean id="bookService" class="well.service.BookServiceImpl">
<property name="bookDao" ref="bookDao"/>
</bean>
<mvc:default-servlet-handler/>
<mvc:annotation-driven/>
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="hibernate"/>
</bean>
</beans>
MainController.java
@Controller
public class MainController {
private BookService bookService;
@Autowired
@Qualifier(value = "bookService")
public void setBookService(BookService bookService) {
this.bookService = bookService;
}
@RequestMapping(value = "books" , method = RequestMethod.GET)
public String bookList(Model model) {
model.addAttribute("bookList", bookService.getListBooks());
return "books";
}
books.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>Заголовок: ${title}</title>
</head>
<body>
<a href="/">Back to main menu</a>
<br/>
<br/>
<h1>BookList</h1>
<c:if test="${!empty bookList}">
<table>
<thead>
<tr>
<th>id</th>
<th>title</th>
<th>description</th>
<th>author</th>
<th>isbn</th>
<th>printYear</th>
<th>readAlready</th>
</tr>
</thead>
<tbody>
<c:forEach items="${bookList}" var="book" >
<tr>
<td>${book.id}</td>
<td>${book.title}</td>
<td>${book.description}</td>
<td>${book.author}</td>
<td>${book.isbn}</td>
<td>${book.printYear}</td>
<td>${book.readAlready}</td>
</tr>
</c:forEach>
</tbody>
</table>
</c:if>
<h1>AddBook</h1>
</body>
</html>
при вызове в контроллере
model.addAttribute("bookList", bookService.getListBooks());
получаю вот такую ошибку:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.service.UnknownUnwrapTypeException: Cannot unwrap to requested type [javax.sql.DataSource]
и т.д. ...
Почему он ругается?
Айфон мало держит заряд, разбираемся с проблемой вместе с AppLab
Перевод документов на английский язык: Важность и ключевые аспекты
После скачивания и подключения библиотек Apache POI из сайта poiapache
Есть VideoView, в нем по методу setVideoView(Uriparse("somePathUrlVideo")) загружается видео через интернет, проблема в том, что загрузка очень долгая, несколько секунд,...