html頁面記錄訪問次數

寫了一個簡單的訪問次數,但是還存在一定的問題,僅能夠實現頁面效果。如果有大佬願意指明,請評論告訴小弟,小弟會很開心的。
效果圖:
在這裏插入圖片描述
1.dao接口

	 //根據id查訪問量
     Integer selectCounterById(@Param(value = "id") Integer id);
     //修改訪問量的次數
     void updateCounter(@Param(value = "id") Integer id, @Param(value = "counter") Integer counter);

2.mapper.xml

<!--根據id查訪問量-->
    <select id="selectCounterById" parameterType="com.gl.lab.entity.SecurityManual" resultType="Integer">
        select
            sm.COUNTER
        from SECURITY_MANUAL sm
        where id=#{id}
    </select>
    <!--修改訪問量的次數-->
    <update id="updateCounter" parameterType="com.gl.lab.entity.SecurityManual">
        update SECURITY_MANUAL
        set
            COUNTER = #{counter,jdbcType=DECIMAL}
        where ID = #{id,jdbcType=VARCHAR}
    </update>

3.service接口

	//查詢訪問次數
    Integer queryCounter() throws Exception;

4.serviceImpl

	//查詢訪問次數
    @Override
    public Integer queryCounter() throws Exception {
        Integer counter = securityManualMapper.selectCounterById(1);
        int i = ++counter;
        securityManualMapper.updateCounter(1, i);
        System.out.println(i);
        return i;
    }

5.controller

    @RequestMapping("queryCount")
    public Integer queryCount() throws Exception{
        Integer counter = securityManualService.queryCounter();
        return counter;
    }

6.html頁面

<!DOCTYPE html>
<html>
<head>
	導入自己需要的css、js
</head>
<body>
	 訪問次數:<span id="fangwen_count"></span>
	 
    <script src="js/jquery.min.js"></script>
	<script>
		  $(document).ready(function(){
       	  $.get("xx/securityManual/queryCount",function (result) {
            console.log(result);
            var i = result;
            //alert(i)
            $("#fangwen_count").text(i)
        });
    })
	</script>
</body>
</html>

這樣就差不多寫完了,寫的不好,多有擔待哇!!!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章