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
      ]]>

      

  • 相关阅读:
    Java实战之03Spring-01Spring概述
    Java实战之02Hibernate-08二级缓存
    Java实战之02Hibernate-07与效率性能相关配置
    css3 移入移出动画
    ng2 搭建本地开发环境
    ng2模板语法/内置指令速查表
    node + npm 命令
    什么是作用域?什么是上下文?浅解
    get? post? put? delete? head? trace? options? http请求方法
    什么是http?
  • 原文地址:https://www.cnblogs.com/z360519549/p/5653831.html
Copyright © 2011-2022 走看看