zoukankan      html  css  js  c++  java
  • index(js)與Controller

    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>外币</title>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/icon.css">
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/demo.css">
    <style type="text/css">
    span.info{display:block; text-align:center; padding:5px; margin-top:15px;}
    </style>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.min.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.easyui.min.js"></script>

    <script type="text/javascript">
    $(function(){

    var dg=$("#dg").datagrid({
    //toolbar : "#tb",
    striped : true,
    nowrap:false,
    collapsible:true,
    loadMsg:"数据载入中......",
    pagination:true,
    fitColumns:true,
    //fit : true,
    pageSize:50,
    rownumbers:true,
    singleSelect:true,
    method:"POST",
    url:"<%=request.getContextPath()%>/Currency/CurrencyList",
    idField:"code",
    columns:[[
    {field:"code",title:"編號",100},
    {field:"desc1",title:"中文名",100},
    {field:"desc2",title:"备注",100},
    {field:"rate",title:"對人民幣匯率",100},

    ]],
    toolbar: [{
    text: '添加',
    iconCls: 'icon-add',
    handler: function() {

    openDialog("dialog","添加外币","<%=request.getContextPath()%>/Currency/CurrencyAdd");

    }
    }, '-', {
    text: '修改',
    iconCls: 'icon-edit',
    handler: function() {
    var row = $("#dg").datagrid("getSelected");
    console.log(row);
    if(row==null || typeof row == "undefined")
    firendlytip("請選擇要修改的外币?");
    else{
    var code = row.code;
    openDialog("dialog","修改外币","<%=request.getContextPath()%>/Currency/CurrencyModify?code="+code);
    }
    }
    }, '-',{
    text: '删除',
    iconCls: 'icon-remove',
    handler: function(){
    var row = $("#dg").datagrid("getSelected");
    if(row==null || typeof row == "undefined")
    delAppInfo(null);
    else{
    var code = row.code;
    delAppInfo(code);
    }
    }
    } ],
    onDblClickRow:function(rowIndex,rowData){
    openDialog("dialog","修改外币","<%=request.getContextPath()%>/Currency/CurrencyModify?code="+rowData.code);
    }
    })

    var p = dg.datagrid('getPager');
    $(p).pagination({
    pageSize: 50,//每页显示的记录条数,默认为10
    pageList: [10,50,100,150],//可以设置每页记录条数的列表
    beforePageText: '第',//页数文本框前显示的汉字
    afterPageText: '页 共 {pages} 页',
    displayMsg: '当前显示 {from} - {to} 条记录 共 {total} 条记录',
    });

    function firendlytip(tip){
    $('#dd').dialog({
    title: '提示',
    300,
    height: 150,
    closed: false,
    cache: false,
    modal: true,
    content:"<span class='info'>"+tip+"</span>",
    buttons:[{text:"確認",handler:function(){
    $('#dd').dialog("close");
    }}]
    });
    }
    function openDialog(dialog,title,url){
    $("#frame").attr("src",url);
    $('#'+dialog).dialog({
    title: title,
    closed: false,
    cache: false,
    maximizable:true,
    modal: true
    });
    }

    function delAppInfo(code){
    if(code==null){
    $('#dd').dialog({
    title: '提示',
    300,
    height: 150,
    closed: false,
    cache: false,
    modal: true,
    content:"<span class='info'>請選擇要刪除的數據</span>",
    buttons:[{text:"確認",handler:function(){
    $('#dd').dialog("close");
    }}]
    });
    }else{
    $('#dd').dialog({
    title: '提示',
    300,
    height: 150,
    closed: false,
    cache: false,
    modal: true,
    content:"<span class='info'>確定要刪除["+code+"]嗎?</span>",
    buttons:[
    {
    text:"確認",
    handler:function(){
    $.post("<%=request.getContextPath()%>/Currency/DeleteCurrency",{code:code},function(tx){
    if(tx=="success"){
    parent.$.messager.show({
    title : '提示',
    msg : '刪除成功'
    });

    /* $.messager.alert('提示','操作成功'); */
    $('#dg').datagrid('reload');
    }
    });

    $('#dd').dialog("close");
    }
    },
    {
    "text":"取消",
    handler:function(){
    $('#dd').dialog("close");
    }
    }]
    });
    }
    }

    $("#search").click(function(){
    dg.datagrid({
    url:'${pageContext.request.contextPath}/Currency/CurrencyList',
    queryParams:{ //可成功传参数
    code:$("#id").val(),
    name:$("#name").val()
    }
    });

    var p = dg.datagrid('getPager');
    $(p).pagination({
    pageSize: 50,//每页显示的记录条数,默认为10
    pageList: [10,50,100,150],//可以设置每页记录条数的列表
    beforePageText: '第',//页数文本框前显示的汉字
    afterPageText: '页 共 {pages} 页',
    displayMsg: '当前显示 {from} - {to} 条记录 共 {total} 条记录',
    });
    });
    });
    </script>

    </head>
    <body class="easyui-layout" data-options="fit:true,border:false">
    <div>
    <div>
    <div id="tb" style="padding:3px">
    <form id="form1">
    <span>编号:</span>
    <input id="code" type="text" value="" data-options="iconCls:'icon-search'" class="easyui-textbox" name="code"/>

    <span>名稱:</span>
    <input id="name" type="text" name="name" data-options="iconCls:'icon-search'" class="easyui-textbox" />

    <a id="search" href="javascript:void(0);" class="easyui-linkbutton"
    iconCls="icon-search" >搜索</a>

    </form>
    </div>
    </div>

    <table id="dg" title="预设折扣" style="100%;height:800px">
    </table>
    <div id="dd">
    </div>
    <div id="dialog" class="easyui-dialog" data-options="iconCls:'icon-save',resizable:true,modal:true,closed:true" style="95%; min-height:700px;height:95%;">
    <iframe id="frame" style="100%; height:100%;" frameborder="0" src=""></iframe>
    </div>

    </div>
    </body>
    </html></html>

    ///////////////////////////////////////CurrencyController (Controller)////////////////////////////////////////////////////////////////

    package com.dw.controller;

    import java.io.IOException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.List;

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;


    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Qualifier;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.ModelAttribute;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.RequestParam;

    import com.dw.bean.Pagebean;
    import com.dw.entity.Currency;
    import com.dw.entity.DiscHd;
    import com.dw.entity.Outline;
    import com.dw.entity.Reason;
    import com.dw.service.ICurrencyService;
    import com.dw.util.Utility;

    @Controller
    public class CurrencyController extends BaseController {



    @Autowired
    @Qualifier("CurrencyService")
    private ICurrencyService CurrencyService;

    /* @RequestMapping(value = "Currency/CurrencyIndex", method = RequestMethod.GET)
    public String Index(Currency currency,@ModelAttribute("code") String code){

    return "Currency/CurrencyIndex";
    }*/

    @RequestMapping(value = "Currency/CurrencyAdd", method = RequestMethod.GET)
    public String CurrencyAdd(Model model){

    /* SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
    java.util.Date date=new java.util.Date();
    String str=sdf.format(date);

    SimpleDateFormat sdf1=new SimpleDateFormat("HH:mm:ss");
    java.util.Date date1=new java.util.Date();
    String str1=sdf1.format(date1);


    System.out.println(str);
    System.out.println(str1);*/
    SimpleDateFormat sdf=new SimpleDateFormat("HH:mm:ss");
    java.util.Date date=new java.util.Date();
    String str=sdf.format(date);
    model.addAttribute("str", str);

    return "Currency/CurrencyAdd";
    }
    @RequestMapping(value="Currency/CurrencyModify",method=RequestMethod.GET)
    public String CurrencyModify(Model model,@RequestParam("code") String code){
    Currency ks=CurrencyService.getCurrencyByID(code);
    model.addAttribute("ks",ks);
    SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
    java.util.Date date=new java.util.Date();
    String str=sdf.format(date);
    model.addAttribute("str", str);
    return "Currency/CurrencyModify";
    }

    //POST'S REGION
    @RequestMapping(value = "Currency/CurrencyList", method = RequestMethod.POST)
    public void CurrencyList(Pagebean pagebean,
    HttpServletResponse response,
    @RequestParam(required=false,value="code") String code,
    @RequestParam(required=false,value="desc1") String desc1
    ) throws IOException{


    int currentPage = pagebean.getPage()<=0?1:pagebean.getPage();
    int sizePage = pagebean.getRows()==0?50:pagebean.getRows();
    int offset=(currentPage-1)*sizePage;
    if(null==code) code="";
    if(null==desc1) desc1="";
    int total=CurrencyService.getTotal();
    List<Currency> list=CurrencyService.getCurrency(offset, sizePage);
    /*List<Reason> list=ReasonService.getReason(code,name,offset, sizePage);*/
    writePagination(total, list, response);


    }

    @RequestMapping(value = "Currency/CheckExisted", method = RequestMethod.POST)
    public void CheckExisted(Currency currrency,
    @RequestParam("code") String code,
    HttpServletResponse response){
    try {
    String res="false";
    if(null!=code){
    code = code.trim();
    Currency ks = CurrencyService.getCurrencyByID(code);
    if(null==ks)
    res="true";
    }
    response.setHeader("Content-type", "text/json;charset=UTF-8");
    // 如果是默認繁體中文查看,則設置為UTF-8.
    response.setCharacterEncoding("UTF-8");
    response.getWriter().write(res);
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }



    @RequestMapping(value="Currency/CurrencySave" ,method=RequestMethod.POST)
    public void Save(Currency currency,HttpServletResponse response,HttpSession session)throws IOException{
    SimpleDateFormat sdf=new SimpleDateFormat("HH:mm:ss");
    java.util.Date date=new java.util.Date();
    String str=sdf.format(date);

    SimpleDateFormat sdf1=new SimpleDateFormat("HH:mm:ss");
    java.util.Date date1=new java.util.Date();
    String str1=sdf1.format(date1);
    String result="failed";
    if(null!=currency){
    Object obj=session.getAttribute("outline");
    Outline out=null;
    if(obj instanceof Outline){
    out=(Outline)obj;
    }
    currency.setOutline(out.getId());
    currency.setOutline("6");
    currency.setUpdatedBy("0000001");
    currency.setCanChange("FALSE");
    currency.setSetStaff("9900036");
    currency.setSetDate(date);
    currency.setSetTime(date1);
    /* System.out.println(str+"@@@@@@@@@@"+date);
    System.out.println(str1+"!!!!!!!!!"+date1);*/
    CurrencyService.Save(currency);

    result="success";
    }
    response.setHeader("Content-type", "text/html;charset=UTF-8");
    // 如果是默認繁體中文查看,則設置為UTF-8
    response.setCharacterEncoding("UTF-8");
    response.getWriter().write(result);
    }

    @RequestMapping(value="Currency/UpdateCurrency",method=RequestMethod.POST)
    public void Update(Currency currency,HttpServletResponse response) throws IOException{
    String result="failed";
    SimpleDateFormat sdf=new SimpleDateFormat("HH:mm:ss");
    java.util.Date date=new java.util.Date();
    /* String str=sdf.format(date); */
    SimpleDateFormat sdf1=new SimpleDateFormat("HH:mm:ss");
    java.util.Date date1=new java.util.Date();
    /* String str1=sdf1.format(date1); */
    if(null!=currency){


    currency.setOutline("6");
    currency.setUpdatedBy("0000001");
    currency.setCanChange("FALSE");
    currency.setSetStaff("9900036");
    currency.setSetDate(date);
    currency.setSetTime(date1);
    System.out.println(date+"xz");
    System.out.println(date1+"sj");
    CurrencyService.Update(currency);
    result="success";
    }
    response.setHeader("Content-type", "text/html;charset=UTF-8");
    response.setCharacterEncoding("UTF-8");
    response.getWriter().write(result);
    }

    @RequestMapping(value = "Currency/DeleteCurrency", method = RequestMethod.POST)
    public void Delete(Model model,
    @RequestParam("code") String code,
    @ModelAttribute("ZD") String ZD,
    HttpServletResponse response
    ) throws IOException{
    String result ="failed";
    if(null!=code){
    Currency ks =CurrencyService.getCurrencyByID(code);
    if(null!=ks){


    CurrencyService.Delete(ks);
    result = "success";

    }
    }

    response.setHeader("Content-type", "text/html;charset=UTF-8");
    // 如果是默認繁體中文查看,則設置為UTF-8
    response.setCharacterEncoding("UTF-8");
    response.getWriter().write(result);

    }

    }

  • 相关阅读:
    Vue 2.x windows环境下安装
    VSCODE官网下载缓慢或下载失败 解决办法
    angular cli 降级
    Win10 VS2019 设置 以管理员身份运行
    XSHELL 连接 阿里云ECS实例
    Chrome浏览器跨域设置
    DBeaver 执行 mysql 多条语句报错
    DBeaver 连接MySql 8.0 报错 Public Key Retrieval is not allowed
    DBeaver 连接MySql 8.0报错 Unable to load authentication plugin 'caching_sha2_password'
    Linux系统分区
  • 原文地址:https://www.cnblogs.com/OP-RONG/p/4201593.html
Copyright © 2011-2022 走看看