如何将select表格中的多个值插入数据库?

时间:2017-08-23 09:09:40

标签: java spring hibernate

我的提交表单:

<form method="post" action="${pageContext.request.contextPath }/">
    <div>
        <label>User:</label> 
        <select name="customer">
            <option value="">Select Customer</option>
            <c:forEach var="c" items="${ cList }">
                <option value="${ c.id }">${ c.name }</option>
            </c:forEach>
        </select>
    </div><br>
    <div>
        <label>Hobby:</label> 
        <select name="product" multiple size="8">
            <!-- <option value="">Select Items</option> -->
            <c:forEach var="p" items="${ pList }">
                <option value = "${ p.id }">${ p.productName }</option>
            </c:forEach>
        </select>
    </div>
    <br><br>
    <input type="submit" value="Send">
</form>

我的控制器:

@RequestMapping(value = "/", method = RequestMethod.POST)
public String postHome(Model model, HttpServletRequest request, @ModelAttribute Transcation t){
    transactionDao.addTransaction(t);
    return "home";
}

在TransactionDaoImpl中:

@Override
@Transactional
public void addTranscation(Transcation t) {
    session = sessionFactory.openSession();
    session.save(t);
    session.close();
}

根据您的想法,我必须进行哪种类型的修改才能执行插入操作。

0 个答案:

没有答案