我正在为我的jsp Web应用程序编写javadoc。因此,我有一个称为AcceptOrder的类(根据Command模式创建并位于服务层)。此类包含方法execute,并从DAO层调用方法acceptOrder。类位于服务层。

/**

* Class allows customer order (which was assigned by dispatcher) be accepted      by driver.
*
*
*/


public class AcceptOrder implements Command {

private static final String USER_ATTRIBUTE = "user";
private static final String ORDER_ID_ATTRIBUTE = "order_id";
private static final String DAO_COMMAND_EXCEPTION_MESSAGE = "Exception on executing DAO command";
private static final String WRONG_ORDER_ID_EXCEPTION_MESSAGE = "Wrong order ID";
/** {@inheritDoc}
 * <p> Accepts user order, which was assigned by dispatcher.
 * @param request request object
 * @param response response object
 */
@Override
public String execute(HttpServletRequest request, HttpServletResponse response) throws CommandException {
    DriverDao driverDao = MySqlDaoFactory.getInstance().getDriverDao();

    try {
        User user = (User) request.getSession().getAttribute(USER_ATTRIBUTE);
        int userId = user.getId();
        int orderId = Integer.valueOf(request.getParameter(ORDER_ID_ATTRIBUTE));
        driverDao.acceptOrder(orderId, userId);
    } catch (DaoException e) {
        throw new CommandException(DAO_COMMAND_EXCEPTION_MESSAGE, e);
    } catch (NumberFormatException e) {
        throw new CommandException(WRONG_ORDER_ID_EXCEPTION_MESSAGE, e);
    }
    return PageManager.getInstance().generatePageRequest(CommandName.SHOW_DRIVER_ORDER);
}

}

另外,我在驱动程序DAO类中(在DAO层中)有一个称为acceptOrder的方法,该方法连接到数据库并根据参数应用一些更改。
@Override
    public void acceptOrder(int orderId, int userId) throws DaoException {
        ConnectionPool connectionPool = null;
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet result = null;
        try {
            connectionPool = ConnectionPool.getInstance();
            connection = connectionPool.takeConnection();
            preparedStatement = connection.prepareStatement(SQL_ACCEPT_ORDER);
            preparedStatement.setInt(1, userId);
            preparedStatement.setInt(2, orderId);
            preparedStatement.executeUpdate();
        } catch (SQLException e) {
            throw new DaoException(STATEMENT_EXCEPTION_MESSAGE, e);
        } catch (ConnectionPoolException e) {
            throw new DaoException(CONNECTION_POOL_EXCEPTION_MESSAGE, e);
        } finally {
            connectionPool.closeConnection(connection, preparedStatement, result);
        }
    }

所以问题是:我应该为它编写什么javadoc,并且我执行命令方法的javadoc是否正确?两种方法的说明中应写什么。好像它们的描述是一样的-接受客户订单。

最佳答案

我认为您应该更好地解释该方法的作用,抛出异常的情况,返回值,实际返回的内容以及原因。如何调用此方法,示例。您可以在类级别解释常见用法,使用的依赖项,常规工作流程,验证和建模。

关于具有相同目标的服务和DAO层类的javadoc,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30004578/

10-15 10:42