1

(0 відповідей, залишених у Java)

Добрий вечір,хочу запитати розумних людей як зробити сортування в JSP по стовпцю.
Що під цим я маю на увазі.
Я хочу натиснути зверху наприклад на "Прізвище" і щоб мені зробило сортування від А до Я.

http://rgho.st/6ds28sNGJ/thumb.png

Ось код jsp файлу якщо треба

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
 
<!DOCTYPE html>
<html lang="UK">
<head>
    <meta http-equiv="Content-Type\" content="text/html; charset=UTF-8\">
    <title>Роботаа</title>
 
    <style>
    body {
        font-family: sans-serif;
        }
        tr:first-child{
            font-weight: bold;
            background-color: #C6C9C4;
            font-size: 13px;
            
            
        }
         a { 
    text-decoration: none; 
   } 
       
    </style>
 
</head>
 
 
<body>
     <h2>Список Гостей</h2> 
    <table>
        <tr>
            <td>Прізвище</td><td>Ім'я</td><td>Тип номеру</td><td>Номер кімнати</td><td>Додаткові послуги</td><td>Типи витрат</td><td>Номер телефону</td><td>Тип Оплати</td><td>Тип картки</td><td>Номер картки</td><td>Сума оплати</td><td>Дата</td><td>Змінити дані</td><td>Видалити</td> 
        </tr>
        <c:forEach items="${guests}" var="guests">
            <tr>
            <td>${guests.surname}</td>
            <td>${guests.name}</td>
            <td>${guests.type_rooms}</td>
            <td>${guests.number_room}</td>
            <td>${guests.additional_Service}</td>
            <td>${guests.spending_Types}</td>
            <td>${guests.number_phone}</td>
            <td>${guests.payment}</td>
            <td>${guests.type_cards}</td>
            <td>${guests.number_cards}</td>
            <td>${guests.amount_payment}</td>
            <td>${guests.date}</td>
            <td><a href="<c:url value='/edit-${guests.id}-guests' />">Редагувати</a></td>
            <td><a href="<c:url value='/delete-${guests.id}-guests' />">Видалити</a></td>
            </tr>
        </c:forEach>
    </table>
    <br/>
    <a href="<c:url value='/new' />">Додати нового гостя</a>
</body>
</html>

Хто знає як зробити таке "чудо" буду вдячний.

2

(13 відповідей, залишених у Java)

EncodingFilter

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;
// Class enconding page on utf-8
public class EncodingFilter implements Filter {

    private String encoding = "utf-8";

    public void doFilter(ServletRequest request,

    ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
        request.setCharacterEncoding(encoding);
        filterChain.doFilter(request, response);
    }

    public void init(FilterConfig filterConfig) throws ServletException {
        String encodingParam = filterConfig.getInitParameter("encoding");
        if (encodingParam != null) {
            encoding = encodingParam;
        }
    }

    public void destroy() {
        // nothing todo
    }

}

Цей код я вставив у файл сервера = web.xml

<filter>
<filter-name>EncodingFilter</filter-name>
<filter-class>
    org.apache.catalina.filters.SetCharacterEncodingFilter
</filter-class>

<init-param>
    <param-name>encoding</param-name>
    <param-value>utf-8</param-value>
</init-param>

</filter>
<filter-mapping>
<filter-name>EncodingFilter</filter-name>
<url-pattern></url-pattern>
</filter-mapping>

3

(13 відповідей, залишених у Java)

Ура, все працює дуже дякую за джерело.

4

(13 відповідей, залишених у Java)

До чого саме. Бо я вже з цим всым заплутався

5

(13 відповідей, залишених у Java)

В мене є ще декілька файлів можливо в них щось.

HibernateConfiguration

package com.honchar.springmvc.configuration;

import java.util.Properties;
import javax.sql.DataSource;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.hibernate4.HibernateTransactionManager;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Configuration
@EnableTransactionManagement
@ComponentScan({ "com.honchar.springmvc.configuration" })
@PropertySource(value = { "classpath:application.properties" })
public class HibernateConfiguration {

    @Autowired
    private Environment environment;

    @Bean
    public LocalSessionFactoryBean sessionFactory() {
        LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
        sessionFactory.setDataSource(dataSource());
        sessionFactory.setPackagesToScan(new String[] { "com.honchar.springmvc.model" });
        sessionFactory.setHibernateProperties(hibernateProperties());
        return sessionFactory;
     }
    
    @Bean
    public DataSource dataSource() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName(environment.getRequiredProperty("jdbc.driverClassName"));
        dataSource.setUrl(environment.getRequiredProperty("jdbc.url"));
        dataSource.setUsername(environment.getRequiredProperty("jdbc.username"));
        dataSource.setPassword(environment.getRequiredProperty("jdbc.password"));
        return dataSource;
    }
    
    private Properties hibernateProperties() {
        Properties properties = new Properties();
        properties.put("hibernate.dialect", environment.getRequiredProperty("hibernate.dialect"));
        properties.put("hibernate.show_sql", environment.getRequiredProperty("hibernate.show_sql"));
        properties.put("hibernate.format_sql", environment.getRequiredProperty("hibernate.format_sql"));
        return properties;        
    }
    
    @Bean
    @Autowired
    public HibernateTransactionManager transactionManager(SessionFactory s) {
       HibernateTransactionManager txManager = new HibernateTransactionManager();
       txManager.setSessionFactory(s);
       return txManager;
    }
}

AppConfig

package com.honchar.springmvc.configuration;

import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.honchar.springmvc")
public class AppConfig {
    
    @Bean
    public ViewResolver viewResolver() {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setViewClass(JstlView.class);
        viewResolver.setPrefix("/WEB-INF/views/");
        viewResolver.setSuffix(".jsp");

        return viewResolver;
    }
    
    @Bean
    public MessageSource messageSource() {
        ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
        messageSource.setBasename("messages");
        return messageSource;
    }
}

appinitializer

package com.honchar.springmvc.configuration;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

public class AppInitializer implements WebApplicationInitializer {

    public void onStartup(ServletContext container) throws ServletException {

        AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
        ctx.register(AppConfig.class);
        ctx.setServletContext(container);

        ServletRegistration.Dynamic servlet = container.addServlet(
                "dispatcher", new DispatcherServlet(ctx));

        servlet.setLoadOnStartup(1);
        servlet.addMapping("/");
    }

}

6

(13 відповідей, залишених у Java)

jdbc.driverClassName = com.mysql.jdbc.Driver
jdbc.url = jdbc:mysql://localhost:3306/websystique?useUnicode=true&characterEncoding=UTF-8
jdbc.username = root
jdbc.password = admin
hibernate.dialect = org.hibernate.dialect.MySQLDialect
hibernate.show_sql = true
hibernate.format_sql = true

Не допомогло :(

7

(13 відповідей, залишених у Java)

http://replace.org.ua/post/113975/#p113975
Ось в цьому пості є ще коди від мого проекту.

8

(13 відповідей, залишених у Java)

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>

<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Реєстрація Гостей</title>

<style>

    .error {
        color: #ff0000;
    }
    body {
        font-family: sans-serif;}
    a{
        text-decoration: none;}
</style>

</head>

<body>

     <h2>Реєстрація Форма</h2>
 
    <form:form method="POST" modelAttribute="guests">
        <form:input type="hidden" path="id" id="id"/>
        <table>
            <tr>
                <td><label for="surname">Прізвище: </label> </td>
                <td><form:input path="surname" id="surname"/></td>
                <td><form:errors path="surname" cssClass="error"/></td>
            </tr>
        
        <tr>
                <td><label for="name">Ім'я: </label> </td>
                <td><form:input path="name" id="name"/></td>
                <td><form:errors path="name" cssClass="error"/></td>
            </tr>
            <tr>
                <td><label for="type_rooms">Тип кімнат: </label> </td>
                <td><form:input path="type_rooms" id="type_rooms"/></td>
                <td><form:errors path="type_rooms" cssClass="error"/></td>
            </tr>
            
            <tr>
                <td><label for="number_room">Номер кімнати: </label> </td>
                <td><form:input path="number_room" id="number_room"/></td>
                <td><form:errors path="number_room" cssClass="error"/></td>
            </tr>
    
            <tr>
                <td><label for="additional_Service">Додаткові послуги: </label> </td>
                <td><form:input path="additional_Service" id="additional_Service"/></td>
                <td><form:errors path="additional_Service" cssClass="error"/></td>
            </tr>
    
            <tr>
                <td><label for="spending_Types">Типи витрат: </label> </td>
                <td><form:input path="spending_Types" id="spending_Types"/></td>
                <td><form:errors path="spending_Types" cssClass="error"/></td>
            </tr>
            <tr>
                <td><label for="number_phone">Номер телефону: </label> </td>
                <td><form:input path="number_phone" id="number_phone"/></td>
                <td><form:errors path="number_phone" cssClass="error"/></td>
            </tr>
            <tr>
                <td><label for="payment">Тип Оплати: </label> </td>
                <td><form:input path="payment" id="payment"/></td>
                <td><form:errors path="payment" cssClass="error"/></td>
            </tr>
            <tr>
                <td><label for="type_cards">Тип картки: </label> </td>
                <td><form:input path="type_cards" id="type_cards"/></td>
                <td><form:errors path="type_cards" cssClass="error"/></td>
            </tr>
            <tr>
                <td><label for="number_cards">Номер картки: </label> </td>
                <td><form:input path="number_cards" id="number_cards"/></td>
                <td><form:errors path="number_cards" cssClass="error"/></td>
            </tr>
            <tr>
                <td><label for="amount_payment">Сума до оплати: </label> </td>
                <td><form:input path="amount_payment" id="amount_payment"/></td>
                <td><form:errors path="amount_payment" cssClass="error"/></td>
            </tr>
            <tr>
                <td><label for="date">Дата реєстрації: </label> </td>
                <td><form:input path="date" id="date"/></td>
                <td><form:errors path="date" cssClass="error"/></td>
            </tr>
    
            <tr>
                <td colspan="3">
                    <c:choose>
                        <c:when test="${edit}">
                            <input type="submit" value="Update"/>
                        </c:when>
                        <c:otherwise >
                            <input type="submit" value="Реєстрація"/>
                        </c:otherwise>
                    </c:choose>
                </td>
            </tr>
        </table>
    </form:form>
    <br/>
    <br/>
    Повернутися до <a href="<c:url value='/list' />">Списку з гостями</a>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Сторінка підтвердження реєстрації</title>

<style>

    body {
        font-family: sans-serif;}
    a{
        text-decoration: none;}
</style>
</head>
<body>
    message : ${success}
    <br/>
    <br/>
     Повернутися до <a href="<c:url value='/list' />">Списку всіх Гостей</a>
    
</body>

</html>

9

(13 відповідей, залишених у Java)

Вибачаюсь, що не скинув код незамітив.
Зараз скину код.
Все відображається в браузері.

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>

<!DOCTYPE html>
<html lang="UK">
<head>
    <meta http-equiv="Content-Type\" content="text/html; charset=UTF-8\">
    <title>Роботаа</title>

    <style>
    body {
        font-family: sans-serif;
        }
        tr:first-child{
            font-weight: bold;
            background-color: #C6C9C4;
            font-size: 13px;
            
            
        }
         a { 
    text-decoration: none; 
   } 
       
    </style>

</head>


<body>
     <h2>Список Гостей</h2> 
    <table>
        <tr>
            <td>Прізвище</td><td>Ім'я</td><td>Тип номеру</td><td>Номер кімнати</td><td>Додаткові послуги</td><td>Типи витрат</td><td>Номер телефону</td><td>Тип Оплати</td><td>Тип картки</td><td>Номер картки</td><td>Сума оплати</td><td>Дата</td><td>Змінити дані</td><td>Видалити</td> 
        </tr>
        <c:forEach items="${guests}" var="guests">
            <tr>
            <td>${guests.surname}</td>
            <td>${guests.name}</td>
            <td>${guests.type_rooms}</td>
            <td>${guests.number_room}</td>
            <td>${guests.additional_Service}</td>
            <td>${guests.spending_Types}</td>
            <td>${guests.number_phone}</td>
            <td>${guests.payment}</td>
            <td>${guests.type_cards}</td>
            <td>${guests.number_cards}</td>
            <td>${guests.amount_payment}</td>
            <td>${guests.date}</td>
            <td><a href="<c:url value='/edit-${guests.id}-guests' />">Редагувати</a></td>
            <td><a href="<c:url value='/delete-${guests.id}-guests' />">Видалити</a></td>
            </tr>
        </c:forEach>
    </table>
    <br/>
    <a href="<c:url value='/new' />">Додати нового гостя</a>
</body>
</html>

10

(13 відповідей, залишених у Java)

Всім привіт, проблема у мене з кирилицею. Коли додаю людей то в мене якісь знаки замість нормальних букв.

Ось приклад
http://rgho.st/8Bj4MR6Qc

Формат БД в MYSQL
http://rgho.st/8dJ9VDg8r

Незнаю як виправити дане чудо. Хто з таким стикався буду вдячний за допомогу. Дякую

Додаю через сторінку.
У мене нижче на сторінці є посилання "Добивати нового гостя" потім переходжу на сторінку з додаванням. Після цього загружаеться сторінка що користувач доданий але кирилица з непонятними знаками.

Як мені вивести дані з однієї таблиці в іншу в еклипсе. БД MySQL

У мене є кілька таблиць, але мені потрібно для початку зрозуміти, як зробити хоча б з двома.
Таблиці пов'язані типом даних "ManyToOne" прописував в Еклипс.
Є таблиця "Guest"  в яку я хочу вивести дані з 2-ї таблиці type_of_room.
Є поля в Двох таблицях "Тип номера"
Мені треба з 2-ї таблиці вивести дані в 1-у таблицю по цьому полю.
Тобто в мене є jsp сторінка і там форма створена на основі таблиці "Guest". Щоб я кожен раз не прописав тип номера я хочу вивести дані з таблиці type_of_room в цю форму щоб просто в тому полі зі списку вибрати конкретний тип.

Якщо хтось таке робив(сподіваюся робили) поясніть новачкові що до чого буду вдячний. Можу скинути сюди код що є може так буде легше щоб я зрозумів що треба дописати, додати. Дякую що вислухали.

App Contoller

package com.honchar.springmvc.controller;
 
import java.util.List;
import java.util.Locale;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
 
 
import com.honchar.springmvc.model.Guests;
import com.honchar.springmvc.service.GuestsService1;
 
@Controller
@RequestMapping("/")
public class AppController {
    
    @Autowired
    GuestsService1 service;
    
    @Autowired
    MessageSource messageSource;
    
    @RequestMapping(value = { "/", "/list" }, method = RequestMethod.GET)
    public String listGuests(ModelMap model) {
        
        List<Guests> guests = service.findAllGuests();
        model.addAttribute("guests", guests);
        return "allguestss";
    }
    
    @RequestMapping(value =  {"/new" }, method = RequestMethod.GET)
    public String newGuests(ModelMap model) {
        Guests guests = new Guests();
        model.addAttribute("guests", guests);
        model.addAttribute("edit", false);
        return "registration";
    }
    
    @RequestMapping(value = { "/new" }, method = RequestMethod.POST)
    public String saveGuests(@Valid Guests guests, BindingResult result,
            ModelMap model) {
 
        if (result.hasErrors()) {
            return "registration";
        }
        
        if(!service.isGuestsIdUinque(guests.getId())) {
            FieldError idError = new FieldError("guests","id", messageSource.getMessage("non.uique.id", new Integer[] {guests.getId()}, Locale.getDefault()));
            result.addError(idError);
            return "registration";
        }
        
        service.saveGuests(guests);
        model.addAttribute("success", "Guests " + guests.getName() + " registered successfully");
        return "success";
        
    }
    
    @RequestMapping(value =  { "/edit-{id}-guests" }, method = RequestMethod.GET)
    public String editGuests(@PathVariable int id, ModelMap model) {
        Guests guests = service.findGuestsById(id);
        model.addAttribute("guests", guests);
        model.addAttribute("edit", true);
        return "registration";
    }
    
    @RequestMapping(value =  { "/edit-{id}-guests" }, method = RequestMethod.POST)
    public String updateGuests(@Valid Guests guests, BindingResult result,
            ModelMap model, @PathVariable int id) {
        
        if (result.hasErrors()) {
            return "registration";
        }
        
        if(!service.isGuestsIdUinque(guests.getId())) {
            FieldError idError = new FieldError("guests","id", messageSource.getMessage("non.uique.id", new Integer[] {guests.getId()}, Locale.getDefault()));
            result.addError(idError);
            return "registration";
        }
        
        service.updateGuests(guests);
        
        model.addAttribute("success", "Guests " + guests.getName() + " update successfully");
        return "success";
 
    }
    
    @RequestMapping(value = { "/delete-{id}-guests"}, method =  RequestMethod.GET)
    public String deleteGuests(@PathVariable int id) {
        service.deleteGuestsById(id);
        return "redirect:/list";
    }
    
    
    
}

AbstractDao

package com.honchar.springmvc.dao;
 
import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
 
public abstract class AbstractDao<PK extends Serializable, T> {
    
    private final Class<T> persistentClass;
    
    @SuppressWarnings("unchecked")
    public AbstractDao(){
        this.persistentClass =(Class<T>) ((ParameterizedType) this.getClass().getGenericSuperclass()).getActualTypeArguments()[1];
    }
    
    @Autowired
    private SessionFactory sessionFactory;
 
    protected Session getSession(){
        return sessionFactory.getCurrentSession();
    }
 
    @SuppressWarnings("unchecked")
    public T getByKey(PK key) {
        return (T) getSession().get(persistentClass, key);
    }
 
    public void persist(T entity) {
        getSession().persist(entity);
    }
 
    public void delete(T entity) {
        getSession().delete(entity);
    }
    
    protected Criteria createEntityCriteria(){
        return getSession().createCriteria(persistentClass);
    }
 
}

GuestsDao1

package com.honchar.springmvc.dao;
 
import java.util.List;
import com.honchar.springmvc.model.Guests;
 
public interface GuestsDao1 {
    Guests findById (int id);
    void saveGuests(Guests guests);
    void deleteGuestsById(int id);
    List<Guests> findAllGuests();
    Guests findGuestsById(int id);
    
}

GuestsDaoImpl

package com.honchar.springmvc.dao;
 
import java.util.List;
 
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import com.honchar.springmvc.model.*;
 
@Repository("guestsDao1")
public class  GuestsDaoImpl1 extends AbstractDao<Integer, Guests> implements GuestsDao1 {
    public Guests findById (int id) {
        return getByKey(id);
    }
    public void saveGuests(Guests guests) {
        persist(guests);
    }
    public void deleteGuestsById(int id) {
        Query query = getSession().createSQLQuery("delete from Guests where id = :id");
        query.setInteger("id", id);
        query.executeUpdate();
    }
    @SuppressWarnings("unchecked")
    public List<Guests> findAllGuests() {
        Criteria criteria = createEntityCriteria();
        return (List<Guests>) criteria.list();
    }
    
    public Guests findGuestsById(int id) {
        Criteria criteria = createEntityCriteria();
        criteria.add(Restrictions.eq("id", id));
        return (Guests) criteria.uniqueResult();
    }
}

Таблица Guests в яку я хочу внести дані

package com.honchar.springmvc.model;
 
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.Digits;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
 
import org.springframework.format.annotation.DateTimeFormat;
 
 
@Entity
@Table(name="GUESTS")
public class Guests implements Serializable{
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;
    
    @Column(name = "SURNAME")
    private String surname;
    
    @Size(min=3, max=50)
    @Column(name = "NAME")
    private String name;
    
    @Column(name = "TYPE_ROOMS")
    private String type_rooms;
    
    @Column(name = "NUMBER_ROOM")
    private int number_room;
    
    @Column(name = "ADDITIONAL_SERVICE")
    private String additional_Service;
    
    @Column(name = "SPENDING_TYPES")
    private String spending_Types;
    
    @Column(name = "NUMBER_PHONE")
    private int number_phone;
    
    @Column(name = "PAYMENT")
    private String payment;
    
    @Column(name = "TYPE_CARDS")
    private String type_cards;
    
    @Column(name = "NUMBER_CARDS")
    private int number_cards;
    
    @NotNull
    @Digits(integer=8, fraction=2)
    @Column(name = "AMOUNT_PAYMENT", nullable = false)
    private BigDecimal amount_payment;
    
    @Temporal(TemporalType.DATE)
    @DateTimeFormat(pattern="dd/MM/yyyy") 
    @Column(name = "DATE" )
    private Date date;
    
    @OneToMany(mappedBy="guests", cascade = CascadeType.ALL)
    private List<types_of_rooms> type_of_rooms;
    
    @OneToMany(mappedBy="guests", cascade = CascadeType.ALL)
    private List<type_of_payment> type_payment;
    
    @OneToMany(mappedBy="guests", cascade = CascadeType.ALL)
    private List<type_of_cards> types_cards;
    
    @OneToMany(mappedBy="guests", cascade = CascadeType.ALL)
    private List<spending_types> types_spending;
    
    @OneToMany(mappedBy="guests", cascade = CascadeType.ALL)
    private List<additional_services> add_services;
    
    public Guests() {
        
    }
    
    public Guests(String surname, String name, String type_rooms, int number_room, String additional_Service, 
            String spending_Types, int number_phone,String payment,String type_cards,
            int number_cards, BigDecimal amount_payment, Date date) {
        this.surname = surname;
        this.name = name;
        this.type_rooms = type_rooms;
        this.number_room = number_room;
        this.additional_Service = additional_Service; 
        this.spending_Types = spending_Types;
        this.number_phone = number_phone;
        this.payment = payment;
        this.type_cards = type_cards;
        this.number_cards = number_cards;
        this.amount_payment = amount_payment;
        this.date = date;
    }
    
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    
    public String getSurname() {
        return surname;
    }
    public void setSurname(String surname) {
        this.surname = surname;
    }
    
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name =  name;
    }
    
    public String getType_rooms() {
        return type_rooms;
    }
    public void setType_rooms(String type_rooms) {
        this.type_rooms = type_rooms;
    }
    
    public int getNumber_room() {
        return number_room;
    }
    public void setNumber_room(int number_room) {
        this.number_room = number_room;
    }
    
    public String getAdditional_Service() {
        return additional_Service;
    }
    public void setAdditional_Service(String additional_Service) {
        this.additional_Service = additional_Service;
    }
        
    public String getSpending_Types() {
        return spending_Types;
    }
    public void setSpending_Types(String spending_Types) {
        this.spending_Types =  spending_Types;
    }
    
    public int getNumber_phone() {
        return number_phone;
    }
    public void setNumber_phone(int number_phone) {
        this.number_phone = number_phone;
    }
    
    public String getPayment() {
        return payment;
    }
    public void setPayment(String payment) {
        this.payment = payment;
    }
    
    public String getType_cards() {
        return type_cards;
    }
    public void setType_cards(String type_cards) {
        this.type_cards = type_cards;
    }
    
    public int getNumber_cards() {
        return number_cards;
    }
    public void setNumber_cards(int number_cards) {
        this.number_cards = number_cards;
    }
    
    public BigDecimal getAmount_payment() {
        return amount_payment;
    }
    public void setAmount_payment(BigDecimal amount_payment) {
        this.amount_payment = amount_payment;
    }
    
    public Date getDate() {
        return date;
    }
    public void setDate(Date date) {
        this.date =  date;
    }
 
    public List<types_of_rooms> getType_of_rooms() {
        return type_of_rooms;
    }
    public void setTypes_of_rooms(List<types_of_rooms> type_of_rooms) {
        this.type_of_rooms = type_of_rooms; 
    }
    
    public  List<type_of_payment> getType_payment() {
        return type_payment;
    }
    public void setType_payment(List<type_of_payment> type_payment) {
        this.type_payment = type_payment;   
    }
    
    public  List<type_of_cards> getTypes_cards() {
        return types_cards;
    }
    public void setTypes_cards(List<type_of_cards> types_cards) {
        this.types_cards = types_cards; 
    }
    
    public  List<spending_types> getTypes_spending() {
        return types_spending;
    }
    public void setTypes_spending(List<spending_types> types_spending) {
        this.types_spending = types_spending;   
    }
    public  List<additional_services> getAdd_services() {
        return add_services;
    }
    public void setAdd_service(List<additional_services> add_services) {
        this.add_services = add_services;   
    }
    
    
    @Override
    public String toString(){
        return "Guests [id=" + id +", surname=" + surname + ", name=" + name + 
                ", type_rooms=" + type_rooms + ",additional_Service=" + additional_Service + 
                ", spending_Types=" + spending_Types+ ", number_phone=" + number_phone +",payment=" 
                + payment + ",type_cards=" + type_cards+ ",number_cards=" + number_cards +",amount_payment=" + amount_payment +", date=" + date + "]";
    }
    
}

Таблица types_of_rooms з якої дані хочу перенести у вигляді списка

package com.honchar.springmvc.model;
 
import java.io.Serializable;
import java.util.List;
import javax.persistence.*;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
 
 
@Entity
@Table(name = "TYPES_OF_ROOMS",catalog = "springmvc")
public class types_of_rooms implements Serializable {
    
    @Id
    @GeneratedValue (strategy = GenerationType.AUTO)
    @Column(name = "ROOMS_ID")
    private long roomsId;
    
    @Column(name ="TYPE_ROOMS")
    private String type_rooms;
    
    @ManyToOne(optional = false)
    @JoinColumn(name = "TYPE_ROOMS", referencedColumnName = "TYPE_ROOMS", insertable = false, updatable = false)
    private Guests guests;
    
    public Guests getGuests () {
        return guests;
    }
    public void setGuests(Guests guests) {
        this.guests = guests;
    }
    
    public long getRoomsId() {
        return roomsId;
    }
    
    public void setRoomsId (long roomsId) {
        this.roomsId = roomsId;
    }
    
    public String getType_rooms() {
        return type_rooms;
    }
    
    public void setType_rooms(String type_rooms) {
        this.type_rooms = type_rooms;
    }
 
    @Override
    public String toString() {
        return "types_of_rooms [roomsId=" + roomsId + ", type_rooms = " + type_rooms +"]";
    }
}

GuestsService1

package com.honchar.springmvc.service;
 
import java.util.List;
import com.honchar.springmvc.model.Guests;
 
public interface GuestsService1 {
    Guests findById (int id);
    void saveGuests(Guests guests);
    void updateGuests(Guests guests);
    void deleteGuestsById(int id);
    List<Guests> findAllGuests();
    Guests findGuestsById(int id);
    boolean isGuestsIdUinque(Integer id);
}

GuestsServiceImpl1

package com.honchar.springmvc.service;
 
import java.util.List;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import com.honchar.springmvc.dao.GuestsDao1;
import com.honchar.springmvc.model.Guests;
import com.honchar.springmvc.model.*;
 
@Service("guestsService1")
@Transactional
public class GuestsServiceImpl1 implements GuestsService1 {
 
    @Autowired
    private GuestsDao1 dao;
    
    public Guests findById(int id) {
        return dao.findById(id);
    }
 
    public void saveGuests(Guests guests) {
        dao.saveGuests(guests);
    }
    public void updateGuests(Guests guests) {
        Guests entity = dao.findById(guests.getId());
        if(entity!=null){
            entity.setSurname(guests.getSurname());
            entity.setName(guests.getName());
            entity.setType_rooms(guests.getType_rooms());
            entity.setNumber_room(guests.getNumber_room());
            entity.setAdditional_Service(guests.getAdditional_Service());
            entity.setSpending_Types(guests.getSpending_Types());
            entity.setNumber_phone(guests.getNumber_phone());
            entity.setPayment(guests.getPayment());
            entity.setType_cards(guests.getType_cards());
            entity.setNumber_cards(guests.getNumber_cards());
            entity.setAmount_payment(guests.getAmount_payment());
            entity.setDate(guests.getDate());
        }
    }
 
    public void deleteGuestsById(int id) {
        dao.deleteGuestsById(id);
    }
    
    public List<Guests> findAllGuests() {
        return dao.findAllGuests();
    }
 
    public Guests findGuestsById(int id) {
        return dao.findGuestsById(id);
    }
 
    public boolean isGuestsIdUinque(Integer id) {
        Guests guests = findGuestsById(id);
        return ( guests == null || ((id != null) && (guests.getId() == id)));
    }
 
}