大型JAVA程序中的类,用于在JSP页面上显示字符串信息(来自数据库)

时间:2018-11-14 15:07:33

标签: java sql jsp

当前正在处理Java类,以显示手动放入数据库(如导航器)中的信息,并将其拉入该程序并显示在jsp页面上。 (主要侧重于从描述Column-字符串信息中提取信息)。该程序已经连接到数据库,并将信息提取到数据库中并显示出来,但是复制它供我使用时超出了我的技能和知识。主程序使用Struts和操作类进行显示。我创建了以下类(尚不确定它是否已完全完成),也将代码放入了struts中,但对于类中的代码并调用jsp页面来显示它却感到困惑。谢谢您对此事的任何帮助,任何建议和指导都将为您带来很大的帮助。

NEWS CLASS 
@Entity
@Table(name = "NEWS")
public class News implements Serializable {

    private Long id;
    private Date newsDate;
    private String title;
    private String description;
    private String activeInd;

    @Id
    @GeneratedValue
    @Column(name = "id")
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the date
     */
    @Temporal(TemporalType.DATE)  
    @Column(name = "NEWS_DATE")
    public Date getNewsDate() {
        return newsDate;
    }

    /**
     * @param date the date to set
     */
    public void setNewsDate(Date date) {
        this.newsDate = date;
    }

    /**
     * @return the title
     */
    @Column(name = "TITLE")
    public String getTitle() {
        return title;
    }

    /**
     * @param title the title to set
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * @return the description
     */
    @Column(name = "DESCRIPTION")
    public String getDescription() 
    {
        return description;
    }

    /**
     * @param description the description to set
     */
    public void setDescription(String description) 
    {
        this.description = description;
        System.out.print(this.description);
    }

    /**
     * @return the activeInd
     */
    @Column(name = "ACTIVE_IND")
    public String getActiveInd() {
        return activeInd;
    }

    /**
     * @param activeInd the activeInd to set
     */
    public void setActiveInd(String activeInd) {
        this.activeInd = activeInd;
    }

}  

public class NewsDAO extends AbstractHDAO implements INewsDAO 
{
    public News find(Long newsId) 
    {
        News news = (News) super.find(News.class, newsId);
        return news;
    }
    public List getList() 
    {
        return super.findAll(News.class);
    }
    public void save(News news)
    {
        super.save(news);
    }

    public List<News> findAll(ArrayList<Object> activeIndicatorStatusList) 
    {
        List<QueryCriteria> queryCriterias = new ArrayList<QueryCriteria>(); 
         List result = super.findByCriteria(News.class, queryCriterias);
         if(result != null && !result.isEmpty())
         {
             return Collections.checkedList(result, News.class);
         }else{
             return null;
         }        
    }
}

public interface INewsDAO 
{
    public News find(Long id);

    List<News> getList();

    public void save(News news);

    public List<News> findAll(ArrayList<Object> activeIndicatorStatusList);


}

public interface INewsService 
{

    News get(Long id);

    void add(News news);

    List getList();
}

public class NewsServiceImpl implements INewsService {

    private INewsDAO newsDAO;
    private IConfigurableItemService configurableItemService = null;
    private List<ConfigurableItem> _categoryList = null;

    public News get(Long id) 
    {
        News news = getNewsDAO().find(id);
        if (news != null) 
        {
            if (news.getActiveInd() == null) 
            {
                news.setActiveInd(ApplicationConstants.STATUS_NO);
            }
        }
        return news;
       //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void add(News news) 
    {
        HttpServletRequest request = ServletActionContext.getRequest();
        getNewsDAO().save(news);
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public List getList() 
    {
        return newsDAO.getList();
    }
    public INewsDAO getNewsDAO() 
    {
        return newsDAO;
    }
    public void setNewsDAO(INewsDAO newsDAO)
    {
        this.newsDAO = newsDAO;
    }
    public IConfigurableItemService getConfigurableItemService() 
    {
        return configurableItemService;
    }

    public void setConfigurableItemService(IConfigurableItemService configurableItemService) 
    {
        this.configurableItemService = configurableItemService;
    }
    public List<News> getList(ArrayList<Object> activeIndicatorStatusList) 
    {

        List<News> newsList = getNewsDAO().findAll(activeIndicatorStatusList);    
        return newsList;     
    }
}

public class DisplayNewsListAction extends ActionSupport implements Preparable, ModelDriven
{
    private INewsService newsService = null;
    private IConfigurableItemService _configurableItemService = null;
    private int _count = 0;
    private List<News> newsList = null;
    private News news = null;
    private List<ConfigurableItem> _categoryList = null;

    public DisplayNewsListAction(INewsService newsService) 
    {
        this.newsService = newsService;
    }


     public String display() throws Exception 
     {

        return "success";

     }

    @Override
    public String execute() throws Exception 
    {
       return Action.SUCCESS;
    }

     public INewsService getNewsService() 
     {
        return newsService;
    }
     public void setNewsService(INewsService newsService) 
     {
        this.newsService = newsService;
     }
     public IConfigurableItemService getConfigurableItemService() 
     {
        return _configurableItemService;
     }

    /**
     * @param configurableItemService the _configurableItemService to set
     */
    public void setConfigurableItemService(IConfigurableItemService configurableItemService) 
    {
        this._configurableItemService = configurableItemService;
    }
     public int getCount() 
     {
        return _count;
    }

    /**
     * @param count the _count to set
     */
    public void setCount(int count)
    {
        this._count = count;
    }
     public List<News> getNewsList() 
     {
        return newsList;
     }

    public void setNewsList(List<News> newsList) 
    {
        this.newsList = newsList;
    }
    public News getNews() 
    {
        return news;
    }
    public void setNews(News news) 
    {
        this.news = news;
    }

    public Object getModel() 
    {
        return newsList;
    }
    public List<ConfigurableItem> getCategoryList() 
    {
        return _categoryList;
    }
    public void setCategoryList(List<ConfigurableItem> categoryList) 
    {
        this._categoryList = categoryList;
    }
     public void prepare() throws Exception {

        try{
        ArrayList<Object> activeIndicatorStatusList = new ArrayList<Object>();
        setCategoryList(getConfigurableItemService().getList(ConfigurableItemType.FAQ_CATEGORY.getCode()));
        /**Make sure the category OTHERS is at the last of the list*/
         if (getCategoryList() != null && getCategoryList().size() > 0) {
            for (ConfigurableItem configurableItem : getCategoryList()) {
                if ("OTH".equalsIgnoreCase(configurableItem.getLowValue())) {
                    getCategoryList().remove(configurableItem);
                    getCategoryList().add(configurableItem);
                    break;

                }
            }
        }
        activeIndicatorStatusList.add(ApplicationConstants.STATUS_YES);
        newsList = newsService.getList();       
        }
        catch(Exception ex)
        {
            addActionError("Error: "  + ex);
        }
    }
}

0 个答案:

没有答案