ant property 总结

时间:2024.4.27

特点

大小写敏感; 不可改变,先到先得,谁先设定,之后的都不能改变。

怎样设置

1、设置name和value属性值,比如:<property name="srcdir"

value="${basedir}/src"/>

2、 设置name和refid属性值,比如:<property name="srcpath"

refid="dao.compile.classpath"/>,其中dao.compile.classpath在别的地方定义。

3、设置name和location属性值,比如:<property name="srcdir"

location="src"/>,即将srcdir的值设 置为:当前项目根目录的/src目录。

4、设置file属性值,比如:<property file="build.properties"/>, 导入build.properties属性文件中的属性值

5、设置resource属性值,比如:<propety resource="build.properties"/>,导入build.properties属性文件中的属性值

6、设置url属性值,比如:<property

url="/wiflish/build.properties"/>,导入

/wiflish/build.properties属性文件中的属性值。

7、设置环境变量,比如:<property environment="env"/>,设置系统的环境变量为前缀env.

<property name="tomcat.home" value="${env.CATALINA_HOME}"/> 将系统的tomcat安装目录设置到 tomcat.home属性中。

内置属性

Ant’s built-in properties:

System properties

antproperty总结

antproperty总结

用法 ${key_name},如:${os.name},它将得到当前操作系统的名称。

需注意

1. 内置属性basedir

-- 不需要定义就可以直接使用,${basedir},得到当前工程的绝对路径 -- 当在<project>标签的basedir属性中指定basedir时,之后工程中出现的所有相对路径都是相对于这个basedir所指向的路径,且${basedir}的值也将变为<project>标签中的basedir属性所指定的值。

2. property的不变性在使用<available><ant><antcall>时会被打破

3. 可以在命令行通过-DpropertyName=propertyValue的方式指定property,注意,-D于propertyName之间没有空格,使用这种方式指定的属性最先被赋值,它是在执行build文件之前就已经赋值了的。

antproperty总结


第二篇:hibernate -- HQL语句总结


1. 查询整个映射对象所有字段

//直接from查询出来的是一个映射对象,即:查询整个映射对象所有字段 String hql = "from Users";

Query query = session.createQuery(hql);

List<Users> users = query.list();

for(Users user : users){

System.out.println(user.getName() + " : " + user.getPasswd() + " : " + user.getId());

}

输出结果为:

name1 : password1 : 1

name2 : password2 : 2

name3 : password3 : 3

2.查询字段

//查询其中几个字段

String hql = " select name,passwd from Users";

Query query = session.createQuery(hql);

//默认查询出来的list里存放的是一个Object数组

List<Object[]> list = query.list();

for(Object[] object : list){

String name = (String)object[0];

String passwd = (String)object[1];

System.out.println(name + " : " + passwd);

}

输出结果为:

name1 : password1

name2 : password2

name3 : password3

3.修改默认查询结果(query.list())不以Object[]数组形式返回,以List形式返回

//查询其中几个字段,添加new list(),注意list里的l是小写的。也不需要导入包,这样通过query.list()出来的list里存放的不再是默认的Object数组了,而是List集合了

String hql = " select new list(name,passwd) from Users"; Query query = session.createQuery(hql);

//默认查询出来的list里存放的是一个Object数组,但是在这里list里存放的不再是默认的Object数组了,而是List集合了

List<List> list = query.list();

for(List user : list){

String name = (String)user.get(0);

String passwd = (String)user.get(1);

System.out.println(name + " : " + passwd);

}

/**

输出结果为:

name1 : password1

name2 : password2

name3 : password3

*/

4.修改默认查询结果(query.list())不以Object[]数组形式返回,以Map形式返回

//查询其中几个字段,添加new map(),注意map里的m是小写的。也不需要导入包,这样通过query.list()出来的list里存放的不再是默认的Object数组了,而是map集合了

String hql = " select new map(name,passwd) from Users"; Query query = session.createQuery(hql);

//默认查询出来的list里存放的是一个Object数组,但是在这里list里存放的不再是默认的Object数组了,而是Map集合了

List<Map> list = query.list();

for(Map user : list){

//一条记录里所有的字段值都是map里的一个元素,key是字符串0,1,2,3....,value是字段值

// 如果将hql改为:String hql = " select new map(name as username,passwd as password) from Users";,那么key将不是字符串0,1,2...了,而是"username","password"了

String name = (String)user.get("0");//get("0");是get(key),注意:0,1,2...是字符串,而不是整形

String passwd = (String)user.get("1");

System.out.println(name + " : " + passwd);

}

/**

输出结果为:

name1 : password1

name2 : password2

name3 : password3

*/

5.修改默认查询结果(query.list())不以Object[]数组形式返回,以自定义类型返回

6.条件查询

//条件查询,参数索引值从0开始,索引位置。通过setString,setParameter设置参数

String hql = "from Users where name=? and passwd=?"; Query query = session.createQuery(hql);

//第1种方式

// query.setString(0, "name1");

// query.setString(1, "password1");

//第2种方式

query.setParameter(0, "name1",Hibernate.STRING); query.setParameter(1, "password1",Hibernate.STRING); List<Users> list = query.list();

for(Users users : list){

System.out.println(users.getId());

}

//条件查询,自定义索引名(参数名):username,:password.通过

setString,setParameter设置参数

String hql = "from Users where name=:username and

passwd=:password";

Query query = session.createQuery(hql);

//第1种方式

// query.setString("username", "name1");

// query.setString("password", "password1");

//第2种方式,第3个参数确定类型

query.setParameter("username", "name1",Hibernate.STRING); query.setParameter("password",

"password1",Hibernate.STRING);

List<Users> list = query.list();

for(Users users : list){

System.out.println(users.getId());

}

//条件查询,通过setProperties设置参数

String hql = "from Users where name=:username and

passwd=:password";

Query query = session.createQuery(hql);

//MyUser类的2个属性必须和:username和:password对应 MyUser myUser = new MyUser("name1","password1"); query.setProperties(myUser);

List<Users> list = query.list();

for(Users users : list){

System.out.println(users.getId());

}

7.update 数据

执行SQL语句(为什么要用SQL语句,我想是为了执行某些复杂的SQL语句吧)

String sql="update Table set field = 'test'"

Session session = HibernateSessionFactory.getSession();

session.createSQLQuery(sql).executeUpdate();

ts.commit();

执行HQL语句

String hql="update Table set field = 'test'"

Session session = HiberanteSessionFactory.getSession();

Transaction ts = session.beginTransaction();

Query query = session.createQuery(hql);

query.executeUpdate();

ts.commit();

更多相关推荐:
符合英文写作习惯的Statement of purpose个人陈述范例

Statementofpurpose本文经修改后作者的学习目的和选择学校的原因显得很清晰明确十分令人信服对比原作者提供的中文稿和专家的修改稿读者可以清楚地看出中英文写作的区别AgraduatefromtheHa...

Statement of Purpose(ce)

StatementofPurposeCivilEngineeringSOPStatementofPurposeCivilEngineeringSOPInthisessayIoutlinemyacademican...

PS (Personal Statement) 和SP (Statement of Purpose)的写作精髓

PSPersonalStatement和SPStatementofPurpose的写作精髓我想说的是经过这次一对一边改边交流我的重大发现是原来大家的对PS的理解本身就是错的初衷就是错的当然回想两年前我也是一样错...

怎样写一份成功的personal statement~

转以下是第三方论点里面对PS很有帮助本人一直认为硕士申请过程中两个主观方面的努力是最重要的1根据自己的情况实事求是因人制宜选择适合的学校和专业2尽量把PS写好展现自己的优势和特点客观的东西因人而异说不清楚不过话...

Personal Statement个人陈述

IamathinkerbutnotonetothinkoutloudIlovemyselfbutamnotinlovewiththesoundofmyownvoiceIwanttobelovedbutnotat...

雅思写作教育类话题范文:Purpose of education

雅思写作教育类话题范文PurposeofeducationQuestionSomesaythepurposeofeducationistoprepareindividualstobeusefultosociet...

英语四级作文范文-大学的目的(On the Purpose of University Education)

Writing30minutesDirectionsForthispartyouareallowed30minutestowriteashortessayentitledOnthePurposeofUniversityEducat...

留学文书范文英语文学类English Lit program SOP

EnglishLitprogramSOPthoughtsandquestionsMorningallI39minthemidstofthrowingmyselfintocomposingmySOPstheearliestofwhi...

如何写Personal Statement(个人陈述)

一步步教你怎么写PS一PS是PersonalStatement的简称是我们申请美国研究生院的重要材料之一一份完美的PS有可能使你申请成功的机会大大增加同时PS也是很好的认识你自己的过程通过写PS你将更了解你自己...

Personal Statement 个人陈述范文

MMMDateofBirth073019xxPersonalStatementIstrivetobecomeaprominentresearcherandleaderofbusinessinthe21stcenturyMypurp...

个人说明范文Personal Statement

PersonalStatementIntroductionImNingjieWeifromasoutherncityinChinacalledNanjingIwasgraduatedfromanHNDcourseatNanjing...

How to Write a Personal Statement 个人陈述

HowtoWriteaPersonalStatement个人陈述hroughapersonalstatementyouintroduceyourselftotheuniversityitreflectsyour...

statement of purpose (10篇)