javaWeb开发笔记(实时更新)

42 篇文章 6 订阅
6 篇文章 0 订阅

在HttpServlet所实现的类中,调用下面代码,获取web服务器的根目录

String path = this.getServletConfig().getServletContext().getRealPath("/");

在HttpServlet所实现的类中,调用下面代码,获取访问接口后面的参数

<a class="btn btn-success buttonStyle " href="/downloadExcel?A2">下载模板</a>

@WebServlet("/downloadExcel")

String param = request.getQueryString();     //得到的值是A2

前端重定向页面

response.sendRedirect("/test.html");

jQuery防止刷新和关闭页面

$(function () {
    window.onbeforeunload = onbeforeunload_handler;
    window.onunload = onunload_handler;
    function onbeforeunload_handler(){
        var warning="确认退出?";
        return warning;
    }

    function onunload_handler(){
        var warning="加油!";
        alert(warning);
    }
});

CSS调整字体间距

letter-spacing:10px;   //css样式,字体间的间距为10px

隐藏与显示元素

$("元素").fadeOut(300);    //隐藏元素
$("元素").fadeIn(300);     //显示元素

Invalid bound statement (not found)

可能因为mapper没有和接口映射上.

pom.xml中添加下面代码

<build>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
    </resources>
</build>

jquery获取元素自身位置

<div id="identity">
    <label style="">管理员</label>
    <label>用户</label>
</div>


$("#identity label").click(function(){
    let index = $("#identity label").index(this);   //自身位置,从0开始
})

jquery类与JSON的互相转

let userJSON = JSON.stringify(类名);   //类转JSON
let userObj = JSON.parse(userJSON);    //JSON转类

fastJSON"JSON与对象的互转"

JSON.toJSONString(obj);   //对象转JSON

提取字符串中的数字

let str = $(".recommendBox_imgBox > label").eq(0).text().replace(/[^\d]/g, ' ');

获取网址信息

www.baidu.com/jdkfjdlksfjkl?sjdkfjdsfkl

window.location.host输出www.baidu.com
window.location.search输?sjdkfjdsfkl

 jQuery替换子串

let reg = new RegExp("/","g");
imgSrc = imgSrc.replace(reg,"AAAsplitAAA");   //把所有/转为AAAsplitAAA,g为全部

js生成随机数

生成0到3的随机数
Math.round(Math.random() * 3);

js把url中的编码后的中文参数转为中文

$("#title-2").text("系列:" + decodeURI(name));

java中JSON与对象的互转

<!--FASTJSON,阿里巴巴的json解析封装工具-->
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>1.2.78</version>
</dependency>

String strObj = JSON.toJSONString(articles);
Articles articles1 = JSON.parseObject(strObj, Articles.class);

MySQL显示列名

show columns from 表名;

js把URL%xx的中文值转中文

decodeURI(name);

 CSS内边距

box-sizing: border-box;

开发时的注意事项

context:property-placeholder标签

这个标签只能用一次,多文件配置中,这里使用了,其它的配置文件就不能使用了。

<context:property-placeholder location="classpath:druid.properties"/>

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值