SSH前后端数据交互

jsp页面

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>sss
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
  <head>

    <title>My JSP 'index.jsp' starting page</title>
  </head>

  <body>
   <s:form action="role_editUI">
   <s:hidden name="id"></s:hidden>
   <s:textfield name="name"></s:textfield>
   <s:textarea name="description"></s:textarea>
   <s:submit name="提交"></s:submit>
   </s:form>
  </body>
</html>

form标注为role-editUI
然后在struts.xml里面配置action

 <action name="role_*" class="roleAction" method="{1}">
          <result name="list">/WEB-INF/JSP/roleAction/list.jsp</result>
          <result name="addUI">/WEB-INF/JSP/roleAction/addUI.jsp</result>
          <result name="editUI">/WEB-INF/JSP/roleAction/editUI.jsp</result>
          <result name="toList" type="redirectAction">role_list</result>
      </action>

editUI.jsp对应的方法为类roleAction下面的editUI()方法

package cn.itcast.oa.view.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import cn.itcast.oa.domain.Role;
import cn.itcast.oa.service.RoleService;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
@Controller
@Scope("prototype")
public class RoleAction extends ActionSupport{
    private Long id;
    private String name;
    private String description;
    @Resource
    private RoleService roleService;
    /**
     * 列表
     * @return
     * @throws Exception
     */
    public String list() throws Exception{
        List<Role> roleList = roleService.findAll();
        ActionContext.getContext().put("roleList", roleList);
        return "list";
    }
    /**
     * 删除
     * @return
     * @throws Exception
     */
    public String delete() throws Exception{
        return "toList";
    }
    /**
     * 添加
     * @return
     * @throws Exception
     */
    public String add() throws Exception{
         Role role = new Role();
         role.setName(name);
         role.setDescription(description);
         roleService.save(role);
        return "toList";
    }
    /**
     * 修改
     * @return
     * @throws Exception
     */
    public String edit() throws Exception{
        //要更新到数据库
        Role role = roleService.getById(id);
        role.setName(name);
        role.setDescription(description);
        roleService.update(role);
        return "toList";
    }
    /**
     * 添加页面
     * @return
     * @throws Exception
     */
    public String addUI() throws Exception{
        return "addUI";
    }
    /**
     * 修改页面
     * @return
     * @throws Exception
     */
    public String editUI() throws Exception{
        //准备回显的数据
        Role role=roleService.getById(id);
        //ActionContext.getContext().getValueStack().push(role);
        this.name=role.getName();
        this.description=role.getDescription();
        return "editUI";
    }
}

然后通过service和hibernate就可以达到编辑的效果。

已标记关键词 清除标记
相关推荐
<p> <b><span style="background-color:#FFE500;">【超实用课程内容】</span></b> </p> <p> <br /> </p> <p> <br /> </p> <p> 本课程内容包含讲解<span>解读Nginx的基础知识,</span><span>解读Nginx的核心知识、带领学员进行</span>高并发环境下的Nginx性能优化实战,让学生能够快速将所学融合到企业应用中。 </p> <p> <br /> </p> <p style="font-family:Helvetica;color:#3A4151;font-size:14px;background-color:#FFFFFF;"> <b><br /> </b> </p> <p style="font-family:Helvetica;color:#3A4151;font-size:14px;background-color:#FFFFFF;"> <b><span style="background-color:#FFE500;">【课程如何观看?】</span></b> </p> <p style="font-family:Helvetica;color:#3A4151;font-size:14px;background-color:#FFFFFF;"> PC端:<a href="https://edu.csdn.net/course/detail/26277"><span id="__kindeditor_bookmark_start_21__"></span></a><a href="https://edu.csdn.net/course/detail/27216">https://edu.csdn.net/course/detail/27216</a> </p> <p style="font-family:Helvetica;color:#3A4151;font-size:14px;background-color:#FFFFFF;"> 移动端:CSDN 学院APP(注意不是CSDN APP哦) </p> <p style="font-family:Helvetica;color:#3A4151;font-size:14px;background-color:#FFFFFF;"> 本课程为录播课,课程永久有效观看时长,大家可以抓紧时间学习后一起讨论哦~ </p> <p style="font-family:"color:#3A4151;font-size:14px;background-color:#FFFFFF;"> <br /> </p> <p class="ql-long-24357476" style="font-family:"color:#3A4151;font-size:14px;background-color:#FFFFFF;"> <strong><span style="background-color:#FFE500;">【学员专享增值服务】</span></strong> </p> <p class="ql-long-24357476" style="font-family:"color:#3A4151;font-size:14px;background-color:#FFFFFF;"> <b>源码开放</b> </p> <p class="ql-long-24357476" style="font-family:"color:#3A4151;font-size:14px;background-color:#FFFFFF;"> 课件、课程案例代码完全开放给你,你可以根据所学知识,自行修改、优化 </p> <p class="ql-long-24357476" style="font-family:"color:#3A4151;font-size:14px;background-color:#FFFFFF;"> 下载方式:电脑登录<a href="https://edu.csdn.net/course/detail/26277"></a><a href="https://edu.csdn.net/course/detail/27216">https://edu.csdn.net/course/detail/27216</a>,播放页面右侧点击课件进行资料打包下载 </p> <p> <br /> </p> <p> <br /> </p> <p> <br /> </p>
©️2020 CSDN 皮肤主题: Age of Ai 设计师:meimeiellie 返回首页