struts2.3.1.1 hibernate3.6.9final spring3.1.0 proxool maven annotation
==============pom.xml==============
pom.xml
xsi:schemalocation=" ">
==============================web.xml========
web.xml
xmlns:xsi=" "
xsi:schemalocation="
">
=====================applicationcontext.xml===========
applicationcontext.xml
xmlns:xsi=" "
xmlns:context=" "
xmlns:aop=" "
xmlns:jee=" "
xmlns:tx=" "
xsi:schemalocation="
"
default-lazy-init="true">
=====================hibernate.cfg.xml====用处是生成表的作用==
"-//hibernate/hibernate configuration dtd 3.0//en"
" ">
jdbc:mysql://localhost:3306/mydemo?useunicode=true&characterencoding=utf-8
org.hibernate.dialect.mysqldialect
com.mysql.jdbc.driver
=================================log4j.properties=========
### set log levels ###
log4j.rootlogger = debug, stdout, d, e
### \u8f93\u51fa\u5230\u63a7\u5236\u53f0 ###
#kong zhi tai
log4j.appender.stdout = org.apache.log4j.consoleappender
log4j.appender.stdout.target = system.out
log4j.appender.stdout.layout = org.apache.log4j.patternlayout
#log4j.appender.stdout.layout.conversionpattern = %-d{yyyy-mm-dd hh:mm:ss} [%t:%r] - [%p] %m%n
### \u8f93\u51fa\u5230\u65e5\u5fd7\u6587\u4ef6 ###
log4j.appender.d = org.apache.log4j.dailyrollingfileappender
log4j.appender.d.file = ${webapp.root}/log/log.log
log4j.appender.d.append = true
log4j.appender.d.threshold = debug
log4j.appender.d.layout = org.apache.log4j.patternlayout
log4j.appender.d.layout.conversionpattern = %-d{yyyy-mm-dd hh:mm:ss} [%t:%r] - [%p] %m%n
### \u4fdd\u5b58\u5f02\u5e38\u4fe1\u606f\u5230\u5355\u72ec\u6587\u4ef6 ###
log4j.appender.e = org.apache.log4j.dailyrollingfileappender
log4j.appender.e.file = ${webapp.root}/log/error.log
log4j.appender.e.append = true
log4j.appender.e.threshold = error
log4j.appender.e.layout = org.apache.log4j.patternlayout
log4j.appender.e.layout.conversionpattern =%-d{yyyy-mm-dd hh\:mm\:ss} [%t\:%r] - [%p] %m%n
==========================================
proxool.properties
## ##公用数据库参数配置
show_sql=true
format_sql=true
hbm2ddl.auto=update
cglib.use_reflection_optimizer=true
connection.release_mode=auto
current_session_context_class=thread
connection.autocommit=true
maxactive=300
maxidle=30
maxwait=500
proxool.house-keeping-test-sql=select sysdate from dual
connection.provider_class=org.hibernate.connection.proxoolconnectionprovider
database.connection=org.hibernate.connection.proxoolconnectionprovider
proxool.alias=demostic
## ## mysql ## ##
database.dialect=org.hibernate.dialect.mysqldialect
database.driver=com.mysql.jdbc.driver
database.url=jdbc\:mysql\://127.0.0.1\:3306/mydemo?useunicode\=true&characterencoding\=utf-8
database.user=root
database.password=1
## ## orcale ## ##
##database.dialect=org.hibernate.dialect.oracledialect
##database.driver=oracle.jdbc.driver.oracledriver
##database.url=jdbc:oracle:thin:@127.0.0.1:1521:tcs
##database.user=demostic
##database.password=demostic
## ##缓存设置
hibernate.cache.provider_class=org.hibernate.cache.hashtablecacheprovider,org.hibernate.cache.ehcacheprovider
hibernate.cache.use_query_cache=false
hibernate.cache.use_second_level_cache=true
hibernate.cache.configurationresourcename=ehcache.xml
hibernate.connection.autocommit=true
## ##测试版数据库
=================================proxool.xml=====================
==========================================struts.properties==========
### struts default properties
###(can be overridden by a struts.properties file in the root of the classpath)
###
### specifies the configuration used to configure struts
### one could extend org.apache.struts2.config.configuration
### to build one's customize way of getting the configurations parameters into struts
# struts.configuration=org.apache.struts2.config.defaultconfiguration
### this can be used to set your default locale and encoding scheme
# struts.locale=en_us
struts.i18n.encoding=utf-8
### if specified, the default object factory can be overridden here
### note: short-hand notation is supported in some cases, such as "spring"
### alternatively, you can provide a com.opensymphony.xwork2.objectfactory subclass name here
struts.objectfactory = spring
### specifies the autowiring logic when using the springobjectfactory.
### valid values are: name, type, auto, and constructor (name is the default)
struts.objectfactory.spring.autowire = name
### indicates to the struts-spring integration if class instances should be cached
### this should, until a future spring release makes it possible, be left as true
### unless you know exactly what you are doing!
### valid values are: true, false (true is the default)
struts.objectfactory.spring.useclasscache = true
### if specified, the default object type determiner can be overridden here
### note: short-hand notation is supported in some cases, such as "tiger" or "notiger"
### alternatively, you can provide a com.opensymphony.xwork2.util.objecttypedeterminer implementation name here
### note: by default, com.opensymphony.xwork2.util.defaultobjecttypedeterminer is used which handles type detection
### using generics. com.opensymphony.xwork2.util.genericsobjecttypedeterminer was deprecated since xwork 2, it's
### functions are integrated in defaultobjecttypedeterminer now.
### to disable tiger support use the "notiger" property value here.
#struts.objecttypedeterminer = tiger
#struts.objecttypedeterminer = notiger
### parser to handle http post requests, encoded using the mime-type multipart/form-data
# struts.multipart.parser=cos
# struts.multipart.parser=pell
struts.multipart.parser=jakarta
# uses javax.servlet.context.tempdir by default
struts.multipart.savedir=
struts.multipart.maxsize=2097152
### load custom property files (does not override struts.properties!)
# struts.custom.properties=application,org/apache/struts2/extension/custom
### how request urls are mapped to and from actions
#struts.mapper.class=org.apache.struts2.dispatcher.mapper.defaultactionmapper
### used by the defaultactionmapper
### you may provide a comma separated list, e.g. struts.action.extension=action,jnlp,do
#struts.action.extension=do
struts.action.extension = action,do,
### used by filterdispatcher
### if true then struts serves static content from inside its jar.
### if false then the static content must be available at
struts.serve.static=true
### used by filterdispatcher
### this is good for development where one wants changes to the static content be
### fetch on each request.
### note: this will only have effect if struts.serve.static=true
### if true -> struts will write out header for static contents such that they will
### be cached by web browsers (using date, cache-content, pragma, expires)
### headers).
### if false -> struts will write out header for static contents such that they are
### not to be cached by web browser (using cache-content, pragma, expires
### headers)
struts.serve.static.browsercache=true
### set this to false if you wish to disable implicit dynamic method invocation
### via the url request. this includes urls like foo!bar.action, as well as params
### like method:bar (but not action:foo).
### an alternative to implicit dynamic method invocation is to use wildcard
### mappings, such as
struts.enable.dynamicmethodinvocation = true
### set this to true if you wish to allow slashes in your action names. if false,
### actions names cannot have slashes, and will be accessible via any directory
### prefix. this is the traditional behavior expected of webwork applications.
### setting to true is useful when you want to use wildcards and store values
### in the url, to be extracted by wildcard patterns, such as
###
### "/foo/save".
struts.enable.slashesinactionnames = false
### use alternative syntax that requires %{} in most places
### to evaluate expressions for string attributes for tags
struts.tag.altsyntax=true
### when set to true, struts will act much more friendly for developers. this
### includes:
### - struts.i18n.reload = true
### - struts.configuration.xml.reload = true
### - raising various debug or ignorable problems to errors
### for example: normally a request to foo.action?someunknownfield=true should
### be ignored (given that any value can come from the web and it
### should not be trusted). however, during development, it may be
### useful to know when these errors are happening and be told of
### them right away.
struts.devmode = false
### when set to true, resource bundles will be reloaded on _every_ request.
### this is good during development, but should never be used in production
struts.i18n.reload=false
### standard ui theme
### change this to reflect which path should be used for jsp control tag templates by default
struts.ui.theme=simple
struts.ui.templatedir=template
#sets the default template type. either ftl, vm, or jsp
struts.ui.templatesuffix=ftl
### configuration reloading
### this will cause the configuration to reload struts.xml when it is changed
struts.configuration.xml.reload=false
### location of velocity.properties file. defaults to velocity.properties
struts.velocity.configfile = velocity.properties
### comma separated list of velocitycontext classnames to chain to the strutsvelocitycontext
struts.velocity.contexts =
### location of the velocity toolbox
struts.velocity.toolboxlocation=
### used to build urls, such as the urltag
struts.url.http.port = 80
struts.url.https.port = 443
### possible values are: none, get or all
struts.url.includeparams = get
### load custom default resource bundles
struts.custom.i18n.resources=com.myshop.resources.applicationresources
### workaround for some app servers that don't handle httpservletrequest.getparametermap()
### often used for weblogic, orion, and oc4j
struts.dispatcher.parametersworkaround = false
### configure the freemarker manager class to be used
### allows user to plug-in customised freemarker manager if necessary
### must extends off org.apache.struts2.views.freemarker.freemarkermanager
#struts.freemarker.manager.classname=org.apache.struts2.views.freemarker.freemarkermanager
### enables caching of freemarker templates
### has the same effect as copying the templates under web_app/templates
struts.freemarker.templatescache=false
### enables caching of models on the beanwrapper
struts.freemarker.beanwrappercache=false
### see the strutsbeanwrapper javadocs for more information
struts.freemarker.wrapper.altmap=true
### configure the xsltresult class to use stylesheet caching.
### set to true for developers and false for production.
struts.xslt.nocache=false
### a list of configuration files automatically loaded by struts
struts.configuration.files=struts-default.xml,struts-plugin.xml,struts.xml
### whether to always select the namespace to be everything before the last slash or not
struts.mapper.alwaysselectfullnamespace=false
============================================struts.xml=========
==================================com.tcs.org.demostic.pub.until.proxoollistener====
package com.tcs.org.demostic.pub.until;
import org.apache.commons.logging.log;
import org.apache.commons.logging.logfactory;
import org.logicalcobwebs.proxool.proxoolexception;
import org.logicalcobwebs.proxool.proxoolfacade;
import org.logicalcobwebs.proxool.configuration.jaxpconfigurator;
import org.logicalcobwebs.proxool.configuration.propertyconfigurator;
import javax.servlet.servletcontextevent;
import java.io.file;
import java.util.properties;
/**
* proxool初始化
*/
public class proxoollistener implements
javax.servlet.servletcontextlistener {
private static final log log = logfactory
.getlog(proxoollistener.class);
private static final string xml_file_property = "proxoolconfiglocation";
private boolean autoshutdown = true;
public void contextinitialized(servletcontextevent servletconfig) {
string appdir = servletconfig.getservletcontext().getrealpath("/");
properties properties = new properties();
string value = servletconfig.getservletcontext().getinitparameter(
xml_file_property);
log.debug("proxoolconfiglocation:" value);
try {
file file = new file(value);
if (file.isabsolute()) {
jaxpconfigurator.configure(value, false);
} else {
log.debug(appdir file.separator value);
jaxpconfigurator.configure(appdir file.separator value,
false);
}
} catch (proxoolexception e) {
log.error("problem configuring " value, e);
}
if (properties.size() > 0) {
try {
propertyconfigurator.configure(properties);
} catch (proxoolexception e) {
log.error("problem configuring using init properties", e);
}
}
}
public void contextdestroyed(servletcontextevent s) {
if (autoshutdown) {
proxoolfacade.shutdown(0);
}
}
}
====================================annotation生成表==============
package com.tcs.org.demostic.pub.until;
import org.hibernate.cfg.annotationconfiguration;
import org.hibernate.cfg.configuration;
import org.hibernate.tool.hbm2ddl.schemaexport;
/*
*功能:生成表
*先建mysql数据库(或)
*oracle实例 (demo)
*doc/oracle--mysql create.readme
*
*/
@suppresswarnings("deprecation")
public class createtable {
public static void main(string[] args) {
configuration cfg = new annotationconfiguration().configure();
schemaexport export = new schemaexport(cfg);
export.create(true, true);
// schemaupdate update =new schemaupdate(cfg);
// update.execute(true, true);
}
}
==================================baseaction======
baseaction.java
package com.tcs.org.demostic.pub.base.action;
import java.io.ioexception;
import java.io.printwriter;
import javax.servlet.http.httpservletresponse;
import net.sf.json.jsonobject;
import org.apache.struts2.servletactioncontext;
import org.springframework.context.annotation.scope;
import org.springframework.stereotype.controller;
import com.opensymphony.xwork2.actionsupport;
/**
*
* @author jar.lin $
* @notes created on 2010-01-25 $
* revision of last commit:$revision: 01 $
* author of last commit:$author: $
* date of last commit:$date: 2010-01-25 16:47:12 0800
*
*/
@suppresswarnings("serial")
@controller
@scope("prototype")
public class baseaction extends actionsupport {
private int page;
private string msg;
public string getmsg() {
return msg;
}
public void setmsg(string msg) {
this.msg = msg;
}
public int getpage() {
return page;
}
public void setpage(int page) {
this.page = page;
}
}
=========================pageindex.java===================
package com.tcs.org.demostic.pub.base.bean;
/**
* 页索引,主要是起始页和终止页 $
*
* @author jar.lin $
*
* @notes created on 2010-01-25 $
* revision of last commit:$revision: 01 $
* author of last commit:$author: $
* date of last commit:$date: 2010-01-25 16:47:12 0800 (周一, 25 一月 2010)$
*
*/
public class pageindex {
/** 开始索引 **/
private int startindex;
/** 结束索引 **/
private int endindex;
public pageindex(int startindex, int endindex) {
this.startindex = startindex;
this.endindex = endindex;
}
public int getstartindex() {
return startindex;
}
public void setstartindex(int startindex) {
this.startindex = startindex;
}
public int getendindex() {
return endindex;
}
public void setendindex(int endindex) {
this.endindex = endindex;
}
/**
* 起始页和终止页
*
* @param viewpagecount
* 显示多少页
* @param currentpage
* 当前页
* @param totalpage
* 总页数
* @return pageindex 起始页和终止页
*/
public static pageindex getpageindex(int viewpagecount, int currentpage,
int totalpage) {
int startpage = currentpage
- (viewpagecount % 2 == 0 ? viewpagecount / 2 - 1
: viewpagecount / 2);
int endpage = currentpage viewpagecount / 2;
if (startpage < 1) {
startpage = 1;
if (totalpage >= viewpagecount)
endpage = viewpagecount;
else
endpage = totalpage;
}
if (endpage > totalpage) {
endpage = totalpage;
if ((endpage - viewpagecount) > 0)
startpage = endpage - viewpagecount 1;
else
startpage = 1;
}
return new pageindex(startpage, endpage);
}
}
==============================pageview.java===================
package com.tcs.org.demostic.pub.base.bean;
import java.util.list;
/**
* * 分页数据包装,包括分页信息和list数据 $
* @author jar.lin $
* @notes created on 2010-01-25 $
* revision of last commit:$revision: 01 $
* author of last commit:$author: $
* date of last commit:$date: 2010-01-25 16:47:12 0800 (周一, 25 一月 2010)$
*
*/
public class pageview
/** 分页数据 **/
private list
/** 页码开始索引和结束索引 **/
private pageindex pageindex;
/** 总页数 **/
private int totalpage = 1;
/** 每页显示记录数 **/
private int maxresult = 10;
/** 当前页 **/
private int currentpage = 1;
/** 总记录数 **/
private int totalrecord;
/** 每次显示多少页,必须保证大于3页,保证左右链接都可以使用 **/
private int viewpagecount = 10;
/** 要获取记录的开始索引 **/
public int getfirstresult() {
return (this.currentpage - 1) * this.maxresult;
}
public int getviewpagecount() {
return viewpagecount;
}
public void setviewpagecount(int viewpagecount) {
this.viewpagecount = viewpagecount;
}
public pageview(int maxresult, int currentpage) {
this.maxresult = maxresult;
this.currentpage = (currentpage <= 0 ? 1 : currentpage);
}
public pageview(int currentpage) {
this.currentpage = (currentpage <= 0 ? 1 : currentpage);
}
public void setqueryresult(queryresult
settotalrecord(qr.gettotalrecord());
setrecords(qr.getresultlist());
}
public int gettotalrecord() {
return totalrecord;
}
public void settotalrecord(int totalrecord) {
this.totalrecord = totalrecord;
settotalpage(this.totalrecord % this.maxresult == 0 ? this.totalrecord
/ this.maxresult : this.totalrecord / this.maxresult 1);
}
public list
return records;
}
public void setrecords(list
this.records = records;
}
public pageindex getpageindex() {
return pageindex;
}
public int gettotalpage() {
return totalpage;
}
public void settotalpage(int totalpage) {
this.totalpage = totalpage;
this.pageindex = pageindex.getpageindex(viewpagecount, currentpage,
totalpage);
}
public int getmaxresult() {
return maxresult;
}
public int getcurrentpage() {
return currentpage;
}
}
======================queryresult.java===============================
package com.tcs.org.demostic.pub.base.bean;
import java.util.list;
/**
**查询结果集,包括数据和总数 $
* @author jar.lin $
* @notes created on 2010-01-25 $
* revision of last commit:$revision: 01 $
* author of last commit:$author: $
* date of last commit:$date: 2010-01-25 16:47:12 0800 (周一, 25 一月 2010)$
*
*/
public class queryresult
/** 查询得出的数据list **/
private list
/** 查询得出的总数 **/
private int totalrecord;
public list
return resultlist;
}
public void setresultlist(list
this.resultlist = resultlist;
}
public int gettotalrecord() {
return totalrecord;
}
public void settotalrecord(int totalrecord) {
this.totalrecord = totalrecord;
}
}
==========================basedaoimpl.java========================
package com.tcs.org.demostic.pub.base.dao.impl;
import java.beans.introspector;
import java.beans.propertydescriptor;
import java.io.serializable;
import java.lang.reflect.method;
import java.sql.sqlexception;
import java.util.linkedhashmap;
import java.util.list;
import javax.annotation.resource;
import javax.persistence.embeddedid;
import javax.persistence.entity;
import org.hibernate.hibernateexception;
import org.hibernate.query;
import org.hibernate.session;
import org.hibernate.sessionfactory;
import org.springframework.orm.hibernate3.hibernatecallback;
import org.springframework.orm.hibernate3.support.hibernatedaosupport;
import com.tcs.org.demostic.pub.base.bean.queryresult;
import com.tcs.org.demostic.pub.base.dao.ibasedao;
import com.tcs.org.demostic.pub.base.util.genericsutils;
/**
* dao层封装使用了泛型,包含常用的curd和分页操作
*
* @author jar.lin $
* @notes created on 2010-01-25 $
* revision of last commit:$revision: 01 $
* author of last commit:$author: $
* date of last commit:$date: 2010-01-25 16:47:12 0800 (周一, 25 一月 2010)$
*
*/
@suppresswarnings("unchecked")
public abstract class basedaoimpl
protected class
protected string entityclassname = getentityname(this.entityclass);
protected string keyfieldname = getkeyfieldname(this.entityclass);
// 为父类hibernatedaosupport注入sessionfactory的值
@resource(name = "sessionfactory")
public void setsupersessionfactory(sessionfactory sessionfactory) {
super.setsessionfactory(sessionfactory);
}
/*
* @see findbyentity(java.lang.object)
*/
public list
return super.gethibernatetemplate().findbyexample(entiey);
}
/*
* order by
*
*/
public list
string entieyorderby = "from" entityclassname " o order by " orderby " " descasc;
return super.gethibernatetemplate().find(entieyorderby);
}
/*
* @see findbyproperty(java.lang.string, java.lang.object)
*/
public list
string querystring = "from " entityclassname " o where o."
propertyname "= ?";
return super.gethibernatetemplate().find(querystring, value);
}
/*
* @see find(java.io.serializable)
*/
public t find(serializable entityid) throws exception {
if (null != entityid)
return (t) super.gethibernatetemplate().get(entityclass, entityid);
return null;
}
/*
* @see getcount()
*/
public int getcount() throws exception {
string hql = "select count( " keyfieldname ") from "
entityclassname;
int count = integer.parseint(super.gethibernatetemplate().find(hql)
.get(0).tostring());
return count;
}
public void save(object entity) throws exception {
super.gethibernatetemplate().save(entity);
}
/*
* @see update(java.lang.object)
*/
public void update(object entity) throws exception {
super.gethibernatetemplate().update(entity);
}
public void saveorupdate(object entity) {
super.gethibernatetemplate().saveorupdate(entity);
}
/*
* @see delete(java.io.serializable[])
*/
public void delete(serializable... entityids) throws exception {
for (object id : entityids) {
super.gethibernatetemplate().delete(find((serializable) id));
}
}
/*
* @see getscrolldata(int, int, java.lang.string,
* java.lang.object[], java.util.linkedhashmap)
*/
public queryresult
final int maxresult,
final string wherejpql,
final object[] queryparams,
final linkedhashmap
final queryresult
super.gethibernatetemplate().execute(new hibernatecallback
public t doinhibernate(session session) throws hibernateexception,
sqlexception {
string hql = "from "
entityclassname
" o "
(wherejpql == null || "".equals(wherejpql.trim()) ? ""
: " where " wherejpql)
buildorderby(orderby);
query query = session.createquery(hql);
setqueryparams(query, queryparams);// where
queryresult.settotalrecord(query.list().size());// first get
// size
if (firstindex != -1 && maxresult != -1)
query.setfirstresult(firstindex).setmaxresults(maxresult);// last
// page
queryresult.setresultlist(query.list());
return null;
}
});
return queryresult;
}
/*
* @see getscrolldata(int, int, java.lang.string,
* java.lang.object[], java.util.linkedhashmap)
*
* select 语句
select[predicate]{*|table.*|[table.]field [,[table.]field2[,...]]} [as alias1 [,alias2[,...]]]
from tableexpression [,...][in externaldatabase]
[]
[where...]
[group by...]
[having...]
[order by...]
[with owneraccess option]
select 语句包括下面几个部分
predicate
*/
/*
* @see getscrolldata(int, int, java.lang.string,
* java.lang.object[])
*/
public queryresult
string wherejpql, object[] queryparams)throws exception {
return getscrolldata(firstindex, maxresult, wherejpql, queryparams,
null);
}
/*
* @see getscrolldata(int, int, java.util.linkedhashmap)
*/
public queryresult
final int maxresult, final linkedhashmap
return getscrolldata(firstindex, maxresult, null, null, orderby);
}
/*
* @see getscrolldata(int, int)
*/
public queryresult
final int maxresult) throws exception {
return getscrolldata(firstindex, maxresult, null, null, null);
}
/*
* @see getscrolldata()
*/
public queryresult
return getscrolldata(-1, -1, null, null, null);
}
/*
* @see save(java.lang.object)
*/
/**
* 获取实体的名称
*
* @param
* @param clazz
* 实体类
* @return
*/
protected static
string entityname = clazz.getsimplename();
entity entity = clazz.getannotation(entity.class);
if (entity.name() != null && !"".equals(entity.name())) {
entityname = entity.name();
}
return entityname;
}
/**
* 获取实体的主键
*
* @param
* @param clazz
* 实体类
* @return 主键名
*/
protected static
try {
propertydescriptor[] propertydescriptors = introspector
.getbeaninfo(clazz).getpropertydescriptors();
for (propertydescriptor propertydesc : propertydescriptors) {
method method = propertydesc.getreadmethod();
if (null != method
&& null != method
.getannotation(javax.persistence.id.class)) {
return propertydesc.getname();
}
}
} catch (exception e) {
e.printstacktrace();
}
return "id";
}
/**
* 设置hql里边的属性值
*
* @param query
* @param queryparams
*/
protected static void setqueryparams(query query, object[] queryparams) {
if (queryparams != null && queryparams.length > 0) {
for (int i = 0; i < queryparams.length; i ) {
query.setparameter(i, queryparams[i]);// 从0开始
}
}
}
/**
* 组装order by语句
*
* @param orderby
* @return
*/
protected static string buildorderby(linkedhashmap
stringbuffer orderbyql = new stringbuffer("");
if (orderby != null && orderby.size() > 0) {
orderbyql.append(" order by ");
for (string key : orderby.keyset()) {
orderbyql.append("o.").append(key).append(" ").append(
orderby.get(key)).append(",");
}
orderbyql.deletecharat(orderbyql.length() - 1);
}
return orderbyql.tostring();
}
protected static
string out = "o";
try {
propertydescriptor[] propertydescriptors = introspector
.getbeaninfo(clazz).getpropertydescriptors();
for (propertydescriptor propertydesc : propertydescriptors) {
method method = propertydesc.getreadmethod();
if (method != null
&& method.isannotationpresent(embeddedid.class)) {
propertydescriptor[] ps = introspector.getbeaninfo(
propertydesc.getpropertytype())
.getpropertydescriptors();
out = "o."
propertydesc.getname()
"."
(!ps[1].getname().equals("class") ? ps[1]
.getname() : ps[0].getname());
break;
}
}
} catch (exception e) {
e.printstacktrace();
}
return out;
}
}
=============================ibasedao.java========================
package com.tcs.org.demostic.pub.base.dao;
import java.io.serializable;
import java.util.linkedhashmap;
import java.util.list;
import com.tcs.org.demostic.pub.base.bean.queryresult;
/**
* dao层封装接口,包含常用的curd和分页操作 $
*
* @author jar.lin $
* @notes created on 2010-01-25 $
* revision of last commit:$revision: 01 $
* author of last commit:$author: $
* date of last commit:$date: 2010-01-25 16:47:12 0800 (周一, 25 一月 2010)$
*
*/
public interface ibasedao
/**
* 根据属性查找对象
*
* @param propertyname
* 属性(对应bean)
* @param value
* 属性
* @return 根据属性查找对象
*/
public list
/**
* 根据实体查找对象
*
* @param entiey
* 实体(t类型)
* @return 根据属性查找对象
*/
public list
/**
* 获取记录总数
*
* @param entityclass
* 实体类
* @return
*/
public int getcount()throws exception;
/**
* 保存实体
*
* @param entity
* 实体id
*/
public void save(object entity)throws exception;
/**
* 更新实体
*
* @param entity
* 实体id
*/
public void update(object entity)throws exception;
/**
* 更新或保存实体
*
* @param entity
* 实体id
*/
public void saveorupdate(object entity)throws exception;
/**
* 删除实体
*
* @param entityclass
* 实体类
* @param entityids
* 实体id数组
*/
public void delete(serializable... entityids)throws exception;
/**
* 获取实体
*
* @param
* @param entityclass
* 实体类
* @param entityid
* 实体id
* @return
*/
public t find(serializable entityid)throws exception;
/**
* 获取分页数据
*
* @param firstindex
* 开始索引
* @param maxresult
* 每页显示记录数
* @param wherejpql
* where语句
* @param queryparams
* 查询参数
* @param orderby
* 排序序列
* @return 分页数据
*/
public queryresult
final int maxresult, final string wherejpql,
final object[] queryparams,
final linkedhashmap
/**
* 获取分页数据
*
* @param firstindex
* 开始索引
* @param maxresult
* 每页显示记录数
* @param wherejpql
* where语句
* @param queryparams
* 查询参数
* @return 分页数据
*/
public queryresult
final int maxresult, final string wherejpql,
final object[] queryparams)throws exception;
/**
* 获取分页数据
*
* @param firstindex
* 开始索引
* @param maxresult
* 每页显示记录数
* @param orderby
* 排序序列
* @return 分页数据
*/
public queryresult
final int maxresult, final linkedhashmap
/**
* 获取分页数据
*
* @param firstindex
* 开始索引
* @param maxresult
* 每页显示记录数
* @return 分页数据
*/
public queryresult
final int maxresult)throws exception;
/**
* 获取所有对象
*
* @return 所有对象
*/
public queryresult
}
==========================genericeutils=============================
package com.tcs.org.demostic.pub.base.util;
import java.lang.reflect.field;
import java.lang.reflect.method;
import java.lang.reflect.parameterizedtype;
import java.lang.reflect.type;
import java.util.arraylist;
import java.util.list;
/**
* 泛型工具类 $
*
* @author jar.lin $
* @notes created on 2010-01-25 $
* revision of last commit:$revision: 01 $
* author of last commit:$author: $
* date of last commit:$date: 2010-01-25 16:47:12 0800 (周一, 25 一月 2010)$
*
*/
public class genericsutils {
/**
* 通过反射,获得指定类的父类的泛型参数的实际类型. 如buyerservicebean extends daosupport
*
* @param clazz
* clazz 需要反射的类,该类必须继承范型父类
* @param index
* 泛型参数所在索引,从0开始.
* @return 范型参数的实际类型, 如果没有实现parameterizedtype接口,即不支持泛型,所以直接返回
* object.class
*/
@suppresswarnings("unchecked")
public static class getsuperclassgenrictype(class clazz, int index) {
type gentype = clazz.getgenericsuperclass();// 得到泛型父类
// 如果没有实现parameterizedtype接口,即不支持泛型,直接返回object.class
if (!(gentype instanceof parameterizedtype)) {
return object.class;
}
// 返回表示此类型实际类型参数的type对象的数组,数组里放的都是对应类型的class, 如buyerservicebean extends
// daosupport
type[] params = ((parameterizedtype) gentype).getactualtypearguments();
if (index >= params.length || index < 0) {
throw new runtimeexception("你输入的索引"
(index < 0 ? "不能小于0" : "超出了参数的总数"));
}
if (!(params[index] instanceof class)) {
return object.class;
}
return (class) params[index];
}
/**
* 通过反射,获得指定类的父类的第一个泛型参数的实际类型. 如buyerservicebean extends daosupport
*
* @param clazz
* clazz 需要反射的类,该类必须继承泛型父类
* @return 泛型参数的实际类型, 如果没有实现parameterizedtype接口,即不支持泛型,所以直接返回
* object.class
*/
@suppresswarnings("unchecked")
public static class getsuperclassgenrictype(class clazz) {
return getsuperclassgenrictype(clazz, 0);
}
/**
* 通过反射,获得方法返回值泛型参数的实际类型. 如: public map
*
* @param method
* method 方法
* @param int index 泛型参数所在索引,从0开始.
* @return 泛型参数的实际类型, 如果没有实现parameterizedtype接口,即不支持泛型,所以直接返回
* object.class
*/
@suppresswarnings("unchecked")
public static class getmethodgenericreturntype(method method, int index) {
type returntype = method.getgenericreturntype();
if (returntype instanceof parameterizedtype) {
parameterizedtype type = (parameterizedtype) returntype;
type[] typearguments = type.getactualtypearguments();
if (index >= typearguments.length || index < 0) {
throw new runtimeexception("你输入的索引"
(index < 0 ? "不能小于0" : "超出了参数的总数"));
}
return (class) typearguments[index];
}
return object.class;
}
/**
* 通过反射,获得方法返回值第一个泛型参数的实际类型. 如: public map
*
* @param method
* method 方法
* @return 泛型参数的实际类型, 如果没有实现parameterizedtype接口,即不支持泛型,所以直接返回
* object.class
*/
@suppresswarnings("unchecked")
public static class getmethodgenericreturntype(method method) {
return getmethodgenericreturntype(method, 0);
}
/**
* 通过反射,获得方法输入参数第index个输入参数的所有泛型参数的实际类型. 如: public void add(map
*
* @param method
* method 方法
* @param int index 第几个输入参数
* @return 输入参数的泛型参数的实际类型集合, 如果没有实现parameterizedtype接口,即不支持泛型,所以直接返回空集合
*/
@suppresswarnings("unchecked")
public static list
int index) {
list
type[] genericparametertypes = method.getgenericparametertypes();
if (index >= genericparametertypes.length || index < 0) {
throw new runtimeexception("你输入的索引"
(index < 0 ? "不能小于0" : "超出了参数的总数"));
}
type genericparametertype = genericparametertypes[index];
if (genericparametertype instanceof parameterizedtype) {
parameterizedtype atype = (parameterizedtype) genericparametertype;
type[] parameterargtypes = atype.getactualtypearguments();
for (type parameterargtype : parameterargtypes) {
class parameterargclass = (class) parameterargtype;
results.add(parameterargclass);
}
return results;
}
return results;
}
/**
* 通过反射,获得方法输入参数第一个输入参数的所有泛型参数的实际类型. 如: public void add(map
* maps, list
*
* @param method
* method 方法
* @return 输入参数的泛型参数的实际类型集合, 如果没有实现parameterizedtype接口,即不支持泛型,所以直接返回空集合
*/
@suppresswarnings("unchecked")
public static list
return getmethodgenericparametertypes(method, 0);
}
/**
* 通过反射,获得field泛型参数的实际类型. 如: public map
*
* @param field
* field 字段
* @param int index 泛型参数所在索引,从0开始.
* @return 泛型参数的实际类型, 如果没有实现parameterizedtype接口,即不支持泛型,所以直接返回
* object.class
*/
@suppresswarnings("unchecked")
public static class getfieldgenerictype(field field, int index) {
type genericfieldtype = field.getgenerictype();
if (genericfieldtype instanceof parameterizedtype) {
parameterizedtype atype = (parameterizedtype) genericfieldtype;
type[] fieldargtypes = atype.getactualtypearguments();
if (index >= fieldargtypes.length || index < 0) {
throw new runtimeexception("你输入的索引"
(index < 0 ? "不能小于0" : "超出了参数的总数"));
}
return (class) fieldargtypes[index];
}
return object.class;
}
/**
* 通过反射,获得field泛型参数的实际类型. 如: public map
*
* @param field
* field 字段
* @param int index 泛型参数所在索引,从0开始.
* @return 泛型参数的实际类型, 如果没有实现parameterizedtype接口,即不支持泛型,所以直接返回
* object.class
*/
@suppresswarnings("unchecked")
public static class getfieldgenerictype(field field) {
return getfieldgenerictype(field, 0);
}
}
=======================================================
相关推荐
struts-2.3.1 spring3.1.1 hibernate3.6.9整合&配置文件 jar包
自己整合了一个可以运行的完整的s2sh框架(struts-2.3.16.1/hibernate-3.6.10/spring-framework-3.2.9),包含了所有的配置文件和所有必需的jar包。以后备用。。。
服务器环境:ubuntu 18.04.1 mysql 5.7.29 python 3.6.9 ** 步骤一:布置环境 mysql安装(sudo apt-get update): 1.1命令安装 (1)sudo apt-get install mysql-server (2)sudo apt-get install mysql-client (3)...
hibernate 3.6.9 官方汉化版教程,包含html、html_single、pdf三种模式。使用adobe reader查看pdf资料时使用缩放为200%时最好,在小就看不清了。
hibernate-core-3.6.9.final
hibernate3.6.9
全名:python-3.6.9rc1.tar.xz
凯沃里 :: api org.kevoree/org.kevoree.api/3.6.9/org.kevoree.api-3.6.9.jar
java jar包,亲测试可用 安全,可以对其进行数字签名,只让能够识别数字签名的用户使用里面的东西。 加快下载速度; 压缩,使文件变小,与zip压缩机制完全相同。 ...能够让jar包里面的文件依赖于统一版本的类文件。...
很专业的适用于can总线的eds电子数据表格制作编辑调试验证工具,兼容eds,dcf,xdd,xdc多种文件格式,且可互相转化。安装后自动生成pdf使用手册,使用很方便。
智慧消防云平台融合了无线烟感监测、...springboot2 mysql 5.7 redis 5.0.0 elasticsearch 6.5.4 rabbitmq 3.6.9 vue3 使用根目录下maven 配置文件 mysql数据库资源创建好后,执行sql文件创建初始化数据库
spire.pdf.jar 截止2020/7/7 最新版本 使用spire实现pdf指定位置插入图片签章, 前一个资源还实现了通过itext对pdf文件进行关键词定位,定位后,通过spire进行指定位置图片签章
【免费版】spire.doc for java 专业的java word 组件,涵盖创建、编辑、打印、转化等功能,可以实现office或者wps的pdf文档处理功能。
python3.6中文文档版html版,比其他人上传的pdf版好用多了。直接用浏览器打开其中的index.html,然后点击合适的目录,就看m6手机网页版登录官网在线查看一样,方便哪里不会查哪里。
hibernate-core-3.6.9.final.jar hibernate-jpa-2.0-api-1.0.1.final.jar httpclient-4.2.3.jar httpcore-4.2.2.jar httpmime-4.2.2.jar itext-4.2.0.jar itext-rtf-2.1.7.jar jackson-annotations-2.0.1.jar ...
1.1 读者范围 .................................................................................................................................1 1.2 内容组织 ..............................................
引言 4 1.1. 编写目的 4 1.2. 项目背景 4 1.3. 适用范围 4 1.4. 术语和缩略语 4 1.5. 参考资料 5 2. 总体设计 5 2.1. 运行环境 5 2.1.1. 硬件环境 5 2.1.2. 软件环境 5 2.2. 开发环境 5 2.2.1. 硬件环境 5 2.2.2. ...
samba-3.6.9rpm包镜像。 其中包含 samba-3.6.9-164.el6.x86_64.rpm samba-client-3.6.9-164.el6.x86_64.rpm samba-common-3.6.9-164.el6.x86_64.rpm
rabbitmq-server-3.6.9-1.el6.noarch.rpm rabbitmq-server-3.6.9-1.el6.noarch.rpm
1.1 历史背景............... 9 1.2 开发原始码软件........ 10 1.3 eclipse 版本介绍...... 10 1.4 跨语言、跨平台........ 11 2. eclipse platform .......... 13 2.1 概观.................. 13 2.2 架构.....