首页 > 代码库 > 每日记载内容总结35

每日记载内容总结35

1.js实现关闭浏览器当前窗口

function closeWindow(){        var userAgent = navigator.userAgent;        if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Presto") != -1) {            window.location.replace("about:blank");        } else {            window.opener = null;            window.open("", "_self");            window.close();        }    }

 

2.nginx 的测试,启动,停止与重启

测试:nginx -t (可检验配置文件等内容是否正确)

启动:直接点击Nginx目录下的nginx.exe    或者    cmd运行start nginx

关闭:nginx -s stop    或者    nginx -s quit (stop表示立即停止nginx,不保存相关信息    quit表示正常退出nginx,并保存相关信息)

重启:nginx -s reload

 

3.Restrictions.ilke与Restrictions.like的区别

前者可以忽略大小写查询 而后者类似于sql中的 like

如果是使用HQL,可以使用lower或者upper函数来实现

from User u where lower(u.username)=lower(’Mp3′)
如果使用Criteria,首先使用Restrictions创建Criterion

如果是字符串相等匹配Restrictions.eq(’username’,‘mp3′).ignoreCase()

如果是字符串模糊匹配Restrictions.ilike(’username’,‘mp3′)或者Restrictions.like(’username’,‘mp3′).ignoreCase()
(摘自百度知道)

4.hibernate实现模糊查询的方法:(来源:http://newleague.iteye.com/blog/953499)

(1)第一种方式:QBC查询(Expression.like)

String name = "", info = "";if (sub != null && sub.getSubname() != null) {name = sub.getSubname();}if (sub != null && sub.getSubinfo() != null) {info = sub.getSubinfo();}Criteria cr = session.createCriteria(Subject.class);cr.add(Expression.like("subname","%"+name+"%"));cr.add(Expression.like("subinfo","%"+info+"%")); 

(2)第二种方式:QBC查询(Restrictions.ilike)

 

cr.add(Restrictions.or(Restrictions.ilike("postTitle", getKeyword(),                    MatchMode.ANYWHERE), Restrictions.ilike("postContent", getKeyword(),                    MatchMode.ANYWHERE)));

 

 

 

(3)第三种方式:HQL查询语句

String   sql="";sql   = "from Pfapp  where name like :subname ";Query query = session.createQuery(sql); query.setString("subname","%"+subnamevalue+"%");

 

5.使用Jsoup获取手机归属地信息

package test.data;import org.jsoup.Jsoup;import org.jsoup.nodes.Document;import org.jsoup.select.Elements;public class GetData {    public static void main(String[] args) throws Exception{        String result = getLocation("18385552222");        //根据返回的文本内容,获取手机归属地信息        System.out.println(result.replace("<!-- <td></td> -->", "").replace("&nbsp;", " "));    }            public static String getLocation(String phoneNum) throws Exception{        //从ip138网站请求并且获取信息        String url = "http://www.ip138.com:8080/search.asp";        //匹配返回的字符串标签        String titleCssQuery = "td.tdc2";        //传参数,action=mobile&moblie=手机号        Document document = Jsoup.connect(url).data("action", "mobile").data("mobile", phoneNum).get();        if(null == document){            return "";        }        //对返回的页面内容进行指定标签的获取         Elements totalElement = document.select(titleCssQuery);         String ele = totalElement.eq(1).html();        return ele;    }}

 

每日记载内容总结35