zoukankan      html  css  js  c++  java
  • springmvc双循环表单存取值,面向对象

    jsp页面

    <table class="list" width="100%" targetType="navTab" asc="asc"
    desc="desc" layoutH="52">
    <thead>
    <tr>
    <th style="10%;" align="center">时间</th>
    <th style="10%;" align="center">代理商</th>
    <th style="10%;" align="center">姓名</th>
    <th style="10%;" align="center">月回款额(分成款)</th>
    <th style="50%;" align="center">
    <table style="100%;">
    <tr>操作人数记录
    </tr>
    <c:forEach items="${projectnamelist}" var="projectnamelist"
    varStatus="s">
    <td  align="center">${projectnamelist.projectname}</td>
    </c:forEach>
    </table>
    </th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${performancebilllist}" var="performancebill"
    varStatus="s">
    <tr target="performancebill_id" rel="${performancebill.id}"
    class="search2">
    <input type="hidden" id="institutionId" name="institutionId"
    value="${performancebill.institutionid}" />
    <input type="hidden" id="currentMonth" name="currentMonth"
    value="${performancebill.currentmonth}" />
    <input type="hidden" id="counselorid" name="counselorid"
    value="${performancebill.counselorid}" />
    <input type="hidden" id="operatorid" name="operatorid"
    value="${performancebill.operatorid}" />
    <td align="center">${performancebill.currentmonth}</td>
    <td align="center">${performancebill.agent}</td>
    <td align="center">
    <table>
    <tr>
    <td>${performancebill.counselorname}<c:if
    test="${performancebill.counselorname!=''}">(操作师)</c:if></td>
    </tr>
    <tr>
    <td>${performancebill.operatorname}<c:if
    test="${performancebill.operatorname!=''}">(咨询师)</c:if></td>
    </tr>
    </table>
    </td>
    <td align="center">${performancebill.subtotal}</td>
    <td>

    <c:forEach items="${projectnamelist}" var="project"
    varStatus="s">

    <td class="cnt" align="center"><input type="hidden"        //用隐藏的input存入值
    id="projectid" name="projectid" value="${project.id}" /><span
    id="projectcnt" name="projectcnt">0 </span></td>
    </c:forEach>                              //与<th>循环相对应

    </td>
    </tr>
    </c:forEach>
    </tbody>
    </table>

    -----------------------------------------------------------------------------------

    js脚本

    $(document).ready(function() { //当页面加载完成时启动方法
    //var saveDataAry = '';
    $(".search2").each(function() {    //class为search2的循环方法
    // alert( $(this).html());
    var institutionId = $(this).find("input[name='institutionId']").val();        //用name取值
    var currentMonth = $(this).find("input[name='currentMonth']").val();
    var counselorid = $(this).find("input[name='counselorid']").val();
    var operatorid = $(this).find("input[name='operatorid']").val();

    $(this).find("table[name='tableproject'] td").each(function() {             //找到name为tableproject的<table>下的<td>进行循环方法

    var projectid = $(this).find("input[name='projectid']").val();

    var projectcnt = $(this).find("span[name='projectcnt']");
    var jsondata = {
    "projectid" : projectid,
    "institutionid" : institutionId,
    "currentmonth" : currentMonth,
    "operatorid" : operatorid,
    "counselorid" : counselorid
    };

    var data = JSON.stringify(jsondata);               //stringify()用于从一个对象解析出字符串,parse()用于从一个字符串中解析出json对象
    // alert(data);
    $.ajax({
    url : '${ctx}/performancebill/getCnt',
    type : 'post',
    cache : false,
    data : data,
    async : false,
    contentType : 'application/json',
    dataType : "json",
    error : function() {
    alertMsg.warn('请按照提示正确填写!');
    },
    success : function(data) {
    projectcnt.text(data);}            //将返回值写入<td>

    });
    });
    });
    });

    -----------------------------------------------------------------------------------------------------------------------------------------------------

    Controller部分

    @Controller
    @RequestMapping("/performancebill")
    public class PerformancebillController {
    @Autowired
    PerformancebillService performancebillService;
    @Autowired
    ProjectService projectService;

    // 客户账单查询
    @RequestMapping("/list")
    public String performancebilllist(
    @RequestParam(required = false, defaultValue = "1") int page,
    @RequestParam(required = false, defaultValue = "20") int rows,
    // @RequestBody List<Detail> performancebill,
    HttpServletRequest request) {
    /*
    * for (Detail detail : performancebill) { List<Detail>
    * billlist=performancebillService
    * .selectperformancebill(detail.getProjectname
    * (),detail.getCurrentMonth(
    * ),detail.getInstitutionId(),detail.getOperatorname
    * (),detail.getCounselorname()); request.setAttribute("billlist",
    * billlist); }
    */
    // 分页
    PageHelper.startPage(page, rows);
    List<Performancebill> performancebilllist = performancebillService.getAll();
    List<Project> projectnamelist = projectService.getprojectname();
    request.setAttribute("projectnamelist", projectnamelist);
    request.setAttribute("performancebilllist", performancebilllist);
    request.setAttribute("pageInfo", new PageInfo<Performancebill>(performancebilllist));
    return "performancebill/performancebill";
    }

    // 客户账单查询
    @RequestMapping(value = "/getCnt", method = RequestMethod.POST)
    @ResponseBody
    public int getCnt(@RequestBody Performancebill bill,                    //ajax封装的json用对象接收
    HttpServletRequest request) {

    if (bill.getOperatorid() == 0 && bill.getCounselorid() == 0) {
    return 0;
    }

    int cnt = performancebillService.selectperformancebill(
    bill.getProjectid(), bill.getCurrentmonth(),
    bill.getInstitutionid(), bill.getOperatorid(),
    bill.getCounselorid());
    return cnt;
    }
    }

    -----------------------------------------------------------------------------------------------------------------------------------------------------

    Service部分          处理业务逻辑

    public int selectperformancebill(int projectid, String currentMonth,
    Integer institutionId, Integer operatorid, Integer counselorid) {

    Map<String, Object> param = new HashMap<String, Object>();               
    param.put("projectid", projectid);
    param.put("currentmonth", currentMonth);
    param.put("institutionid", institutionId);
    param.put("operatorid", operatorid);
    param.put("counselorid", counselorid);
    Performancebill selectperformancebill =performancebillMapper.selectperformancebill(param);          //方法返回值为整型,参数只能是一个,所以封装成Map集合
    if(selectperformancebill == null)
    {
    return 0;
    }
    return selectperformancebill.getProjectcnt() == null ? 0 : selectperformancebill.getProjectcnt();      

    }

    -----------------------------------------------------------------------------------------------------------------------------------------------

    Mapper部分连接数据库

    Performancebill selectperformancebill(Map<String, Object> param);

    ------------------------------------------------------------------------------------------------------------------------------

    PerformancebillMapper.xml部分  存放原生aql语句

    <select id="selectperformancebill" resultMap="BaseResultMap" parameterType="java.lang.Integer">
    select * From
    (
    SELECT currentMonth,IFNULL(institutionId,'') institutionid,
    IFNULL(SUM(subtotal),0)subtotal,count(1) projectcnt,
    IFNULL( ( SELECT institutionName FROM t_inst WHERE t_inst. id = v_t_detail. institutionId),'-') agent,
    IFNULL((SELECT f.username FROM t_sys_user f WHERE f.id=v_t_detail.operator),'') operatorname,
    IFNULL((SELECT g.username FROM t_sys_user g WHERE g.id=v_t_detail.counselor),'') counselorname,
    v_t_detail.operator as operatorid,
    v_t_detail.counselor as counselorid,
    v_t_detail.projectid as projectid
    FROM
    (
    SELECT DATE_FORMAT( t_detail.DATE,'%Y-%m') currentMonth,
    t_info.institutionId,
    t_detail.*
    FROM t_detail LEFT JOIN t_info ON t_detail.infoId = t_info.id
    ) v_t_detail

    GROUP BY currentMonth,institutionId ,operator,counselor,projectid
    ORDER BY currentMonth,institutionId,operator,counselor,projectid
    ) tmp
    where 1=1
    <if test="projectid!=null and projectid!=''">
    <![CDATA[ AND projectid =#{projectid} ]]>
    </if>
    <if test="currentmonth!=null and currentmonth!=''">
    <![CDATA[ AND currentMonth =#{currentmonth} ]]>
    </if>
    <if test="institutionid!=null and institutionid!=''">
    <![CDATA[ AND institutionId =#{institutionid} ]]>
    </if>
    <if test="operatorid!=null and operatorid!=''">
    <![CDATA[ AND operatorid =#{operatorid} ]]>
    </if>
    <if test="counselorid!=null and counselorid!=''">
    <![CDATA[ AND counselorid =#{counselorid} ]]>
    </if>
    </select>

    ---------------------------------------------------------

    新建一个model为Performancebill         作为对象存储数据

    当能力支撑不了野心时,就该静下心来学习!
  • 相关阅读:
    Pig设计模式概要以及与SQL的设计模式的对比
    Pig设计模式概要以及与SQL的设计模式的对比
    ArcGIS API for Silverlight 学习笔记
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
  • 原文地址:https://www.cnblogs.com/1234cjq/p/5810235.html
Copyright © 2011-2022 走看看