0

これが私のDAOです:

public ReportType getByName(String type) {
    EntityManager em = emf.createEntityManager();
    try {
        ReportType rptype2 = em.find(ReportType.class, type);

        return rptype2;
    } catch (Exception e) {
        e.printStackTrace();
        em.close();
    }
    return null;
}

ここに私のアクションがあります:

ReportDAO dao = new ReportDAO();
    List<ReportType> reportType = dao.show();
    list = new ArrayList<>();
    for (ReportType reportType1 : reportType) {
        list.add(reportType1.getName());
    }
    ReportTypeDAO rpDAO = new ReportTypeDAO();
    reporttype = rpDAO.getByName(type);

これが私のjspです:

 <h3>Type: <s:select list="list" name="type"></s:select>

ここに私のテーブルがあります:

CREATE TABLE [dbo].[Report_Type](
[id] [int] IDENTITY(1,1) NOT NULL,
[name] [nvarchar](100) NULL,

提出すると文字列形式(名前)のレコードが届くのですが、このレコードIDを取得したいです。解決策はありますか?

4

2 に答える 2

0

listKey と listValue を使用して、select で ID と名前を指定する必要があります。

<s:select label="My Label"
       name="name"
       list="list"
       listKey="id"
       listValue="name"
      "/>
于 2015-05-06T17:17:40.033 に答える