Guest User

Untitled

a guest
Feb 11th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.98 KB | None | 0 0
  1. @Entity
  2. @Table(name = "library")
  3. public class Book {
  4. private int id;
  5. private String title;
  6. private String description;
  7. private String author;
  8. private String isbn;
  9. private Integer printYear;
  10. private Boolean readAlready;
  11.  
  12. @Id
  13. @Column(name = "id")
  14. public int getId() {
  15. return id;
  16. }
  17.  
  18. public void setId(int id) {
  19. this.id = id;
  20. }
  21.  
  22. @Basic
  23. @Column(name = "title")
  24. public String getTitle() {
  25. return title;
  26. }
  27.  
  28. public void setTitle(String title) {
  29. this.title = title;
  30. }
  31.  
  32. @Basic
  33. @Column(name = "description")
  34. public String getDescription() {
  35. return description;
  36. }
  37.  
  38. public void setDescription(String description) {
  39. this.description = description;
  40. }
  41.  
  42. @Basic
  43. @Column(name = "author")
  44. public String getAuthor() {
  45. return author;
  46. }
  47.  
  48. public void setAuthor(String author) {
  49. this.author = author;
  50. }
  51.  
  52. @Basic
  53. @Column(name = "isbn")
  54. public String getIsbn() {
  55. return isbn;
  56. }
  57.  
  58. public void setIsbn(String isbn) {
  59. this.isbn = isbn;
  60. }
  61.  
  62. @Basic
  63. @Column(name = "printYear")
  64. public Integer getPrintYear() {
  65. return printYear;
  66. }
  67.  
  68. public void setPrintYear(Integer printYear) {
  69. this.printYear = printYear;
  70. }
  71.  
  72. @Basic
  73. @Column(name = "readAlready")
  74. public Boolean getReadAlready() {
  75. return readAlready;
  76. }
  77.  
  78. public void setReadAlready(Boolean readAlready) {
  79. this.readAlready = readAlready;
  80. }
  81.  
  82. <?xml version='1.0' encoding='utf-8'?>
  83. <!DOCTYPE hibernate-configuration PUBLIC
  84. "-//Hibernate/Hibernate Configuration DTD//EN"
  85. "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
  86. <hibernate-configuration>
  87. <session-factory>
  88. <property name="connection.url">jdbc:mysql://localhost:3306/test</property>
  89. <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
  90. <property name="connection.username">root</property>
  91. <property name="connection.password">root</property>
  92.  
  93. <mapping class="well.model.Book"/>
  94.  
  95. <!-- DB schema will be updated if needed -->
  96. <!-- <property name="hbm2ddl.auto">update</property> -->
  97. </session-factory>
  98. </hibernate-configuration>
  99.  
  100. <?xml version="1.0" encoding="UTF-8"?>
  101. <beans xmlns="http://www.springframework.org/schema/beans"
  102. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  103. xmlns:context="http://www.springframework.org/schema/context"
  104. xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
  105. xsi:schemaLocation="http://www.springframework.org/schema/beans
  106. http://www.springframework.org/schema/beans/spring-beans.xsd
  107. http://www.springframework.org/schema/context
  108. http://www.springframework.org/schema/context/spring-context.xsd
  109. http://www.springframework.org/schema/mvc
  110. http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  111.  
  112. <context:component-scan base-package = "well.controllers" />
  113.  
  114. <bean class = "org.springframework.web.servlet.view.InternalResourceViewResolver">
  115. <property name = "prefix" value = "/WEB-INF/jsp/" />
  116. <property name = "suffix" value = ".jsp" />
  117. </bean>
  118.  
  119. <bean id="hibernate" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
  120. <property name="configLocation" value="classpath:hibernate.cfg.xml" />
  121. </bean>
  122.  
  123. <bean id="bookDao" class="well.dao.BookDaoImpl">
  124. <property name="sessionFactory" ref="hibernate"/>
  125. </bean>
  126.  
  127. <bean id="bookService" class="well.service.BookServiceImpl">
  128. <property name="bookDao" ref="bookDao"/>
  129. </bean>
  130.  
  131. <mvc:default-servlet-handler/>
  132. <mvc:annotation-driven/>
  133.  
  134. <tx:annotation-driven transaction-manager="transactionManager"/>
  135.  
  136. <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
  137. <property name="sessionFactory" ref="hibernate"/>
  138. </bean>
  139.  
  140.  
  141. </beans>
  142.  
  143. @Controller
  144. public class MainController {
  145. private BookService bookService;
  146.  
  147. @Autowired
  148. @Qualifier(value = "bookService")
  149. public void setBookService(BookService bookService) {
  150. this.bookService = bookService;
  151. }
  152.  
  153. @RequestMapping(value = "books" , method = RequestMethod.GET)
  154. public String bookList(Model model) {
  155. model.addAttribute("bookList", bookService.getListBooks());
  156. return "books";
  157. }
  158.  
  159. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  160. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
  161.  
  162.  
  163. <html>
  164. <head>
  165. <title>Заголовок: ${title}</title>
  166. </head>
  167. <body>
  168. <a href="/">Back to main menu</a>
  169.  
  170. <br/>
  171. <br/>
  172.  
  173. <h1>BookList</h1>
  174. <c:if test="${!empty bookList}">
  175. <table>
  176. <thead>
  177. <tr>
  178. <th>id</th>
  179. <th>title</th>
  180. <th>description</th>
  181. <th>author</th>
  182. <th>isbn</th>
  183. <th>printYear</th>
  184. <th>readAlready</th>
  185. </tr>
  186. </thead>
  187. <tbody>
  188.  
  189. <c:forEach items="${bookList}" var="book" >
  190. <tr>
  191. <td>${book.id}</td>
  192. <td>${book.title}</td>
  193. <td>${book.description}</td>
  194. <td>${book.author}</td>
  195. <td>${book.isbn}</td>
  196. <td>${book.printYear}</td>
  197. <td>${book.readAlready}</td>
  198. </tr>
  199. </c:forEach>
  200. </tbody>
  201. </table>
  202. </c:if>
  203.  
  204. <h1>AddBook</h1>
  205.  
  206.  
  207. </body>
  208. </html>
  209.  
  210. 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]
  211. и т.д. ...
Add Comment
Please, Sign In to add comment