zoukankan      html  css  js  c++  java
  • 获取表中字段最大值,并且保存在前台页面中

    //获取Userid
    function getUserId(){ 
        $.getJSON('<%=basePath %>user/getUserId.do',
            function(data){	
                alert(eval(data).userId);	
                document.getElementById("userId").value=data.userId;
        });	
    }       


    <input id="userId" name="userId"  value=""  type="text"  readonly="readonly"/><input  value="获取最大的Userid"  onclick="javascript:getUserId();" type="button" style="100px"/>

      UserSlaveController 获取参数

    	@ResponseBody                                                    //@ResponseBody 返回的是数据,不加 @ResponseBody 返回的是页面。 
    	@RequestMapping(value="/user/getUserId.do")//method=RequestMethod.POST
    	public JSONObject getUserId(HttpServletRequest request, HttpServletResponse response)throws Exception {
    	    response.setContentType("text/html");
    	    request.setCharacterEncoding("utf-8");
    	    response.setCharacterEncoding("utf-8");
    
    	    JSONObject jsonObject = new JSONObject();
    	    
    	    Integer userId = 0;
    	        try
    	        {	          
    	            userId = userSlaveService.getUserId();	           
    	        }
    	        catch (Exception e)
    	        {
    	            Loger.logtxt("user", "获取id异常:" + e.toString());
    	        }
    	        
    	        jsonObject.accumulate("userId", userId);
    	        System.out.println(jsonObject.toString());     //输出: {"userId":182888}
    	        System.out.println(jsonObject.values());       //输出: [182888]
    	        return jsonObject;                             //返回json,在上面的jsp页面中接收,并且保存值到input中。
    	}
    

      UserSlaveService.java 接口声明方法 :  public Integer getUserId()throws Exception;

      UserSlaveServiceImpl.java 实现UserSlaveService接口:

      @Override
      public Integer getUserId() throws Exception {
        return userDAO.getUserId();
      }

      IUserDAO.java 接口声明方法:  public Integer getUserId()throws Exception;   

      user.xml 中的查询:

      <select id="getUserId" resultType="java.lang.Integer">

      <![CDATA[
        SELECT (MAX(userid)+1) AS userid FROM userinfo
      ]]>

      

  • 相关阅读:
    无休止的项目,何来快感!!
    [From HTTP to AWS][4]使用LibcURL with OpenSSL support
    [From HTTP to AWS][2]Analyze TCP/IP Packets
    The setup of Piaoger
    从Adobe Subscription editions扯到破坏性创新
    SaaS窘境[欣赏然后翻译之]
    Algodoo,很棒的物理引擎
    浮水法POJ2528
    蛤的旅行
    题解 CF712A 【Memory and Crow】
  • 原文地址:https://www.cnblogs.com/z360519549/p/5653831.html
Copyright © 2011-2022 走看看