• 论坛模块_实现功能1_写基本代码


    论坛模块_实现功能1_写基本代码

    分析功能

      5个功能。

      7个请求。

    实现功能

      Action, 7个方法

      Service

      Dao

      Jsp

    ForumAction

      list()版块列表1个

      show()显示单个版块(主题列表)1个

    TopicAction

      show()显示单个主题(主帖+回帖列表)1个

      addUI(), add()2个

    ReplyAction

      addUI(), add()回帖2个

    创建Action类继承BaseAction。并写其中的方法

    ForumAction.java

    public class ForumAction extends BaseAction<Forum> {
        /**板块列表*/
        public String list() {
            return "list";
        }
        /**显示单个版块(主题列表)*/
        public String show() {
            return "show";
        }
    }

    TopicAction.java

    public class TopicAction extends BaseAction<Topic> {
        /** 显示单个主题(主帖+回帖列表) */
        public String show() {
            return "show";
        }
        /** 发表新主题页面 */
        public String addUI() {
            return "addUI";
        }
        /** 发表新主题 */
        public String add() {
            return "toShow";//转到新主题的显示页面
        }
    }

     ReplyAction.java

    public class ReplyAction extends BaseAction<Reply> {
        /** 发表新回复页面 */
        public String addUI() {
            return "addUI";
        }
        /** 发表新回复 */
        public String add() {
            return "toTopicShow";//转到新主题的显示页面
        }
    }

    写页面

    配置,在每个Action上面加上注解,交给容器管理,让struts2从容器当中得到action响应请求

    @Controller

    @Scope("prototype")

    struts.xml文件中添加

    <!-- 论坛:版块相关功能 -->
            <action name="forum_*" class="forumAction" method="{1}">
                <result name="list">/WEB-INF/jsp/forumAction/list.jsp</result>
                <result name="show">/WEB-INF/jsp/forumAction/show.jsp</result>
            </action>
            
            <!-- 论坛:主题相关功能 -->
            <action name="topic_*" class="topicAction" method="{1}">
                <result name="show">/WEB-INF/jsp/topicAction/show.jsp</result>
                <result name="addUI">/WEB-INF/jsp/topicAction/addUI.jsp</result>
                <result name="toShow" type="redirectAction">topic_show</result>
            </action>
            
            <!-- 论坛:回复相关功能 -->
            <action name="reply_*" class="replyAction" method="{1}">
                <result name="addUI">/WEB-INF/jsp/replyAction/addUI.jsp</result>
                <result name="toTopicShow" type="redirectAction">topic_show</result>
            </action>

    准备service接口及实现类,并配置、声明

    ReplyService.java

    public interface ReplyService extends DaoSupport<Reply>{
    }

    TopicService.java

    public interface ReplyService extends DaoSupport<Reply>{
    }

    ReplyServiceImpl.java

    @Service
    @Transactional
    public class ReplyServiceImpl extends DaoSupportImpl<Reply> implements ReplyService{
    }

    TopicServiceImpl.java

    @Service
    @Transactional
    public class TopicServiceImpl extends DaoSupportImpl<Topic> implements TopicService{
    }

    在BaseAction中声明

    现在可以在Action中直接用Service了

    接下来填空,加Action方法、Service方法、填页面、实现功能

  • 相关阅读:
    Linux下打包发布Qt应用程序
    嵌入式中的BSP---BSP到底是什么?
    (转)Spring 工具类 ConfigurationClassParser 分析得到配置类 -- springboot一样处理过程
    React Hooks之useState、useEffect使用
    数组排序多种方法汇总
    封装判断浏览器是否是IE浏览器
    封装addEventListener,removeEventListener指定元素添加事件及兼容问题js
    js判断是否超过几行
    react日期格式化组件
    Windows smynesc免费经典儿时小游戏分享给大家
  • 原文地址:https://www.cnblogs.com/justdoitba/p/7965545.html
Copyright © 2020-2023  润新知