├── Download └── etmvc-1.0.1-bin.rar ├── README.md ├── Source ├── etmvc shuzheng │ ├── et-ar │ │ ├── .classpath │ │ ├── .project │ │ ├── .settings │ │ │ ├── org.eclipse.core.resources.prefs │ │ │ └── org.eclipse.jdt.core.prefs │ │ ├── COPYRIGHT.txt │ │ ├── README.txt │ │ ├── lib │ │ │ ├── asm.jar │ │ │ ├── cglib-2.1.3.jar │ │ │ └── commons-logging.jar │ │ └── src │ │ │ └── com │ │ │ └── et │ │ │ └── ar │ │ │ ├── ActiveRecordBase.java │ │ │ ├── ActiveRecordProxy.java │ │ │ ├── ConfReader.java │ │ │ ├── ConnectionFactoryBean.java │ │ │ ├── ConnectionHolder.java │ │ │ ├── ConvertUtil.java │ │ │ ├── Converter.java │ │ │ ├── DaoSupport.java │ │ │ ├── Json.java │ │ │ ├── OrmInfo.java │ │ │ ├── Transaction.java │ │ │ ├── adapters │ │ │ ├── Adapter.java │ │ │ ├── DB2Adapter.java │ │ │ ├── MySqlAdapter.java │ │ │ ├── OracleAdapter.java │ │ │ ├── SqlServerAdapter.java │ │ │ └── SqliteAdapter.java │ │ │ ├── annotations │ │ │ ├── BelongsTo.java │ │ │ ├── Column.java │ │ │ ├── DependentType.java │ │ │ ├── Email.java │ │ │ ├── GeneratorType.java │ │ │ ├── HasMany.java │ │ │ ├── HasOne.java │ │ │ ├── Id.java │ │ │ ├── Length.java │ │ │ ├── NotEmpty.java │ │ │ ├── Pattern.java │ │ │ ├── Table.java │ │ │ ├── Unique.java │ │ │ └── ValidatorClass.java │ │ │ ├── connections │ │ │ ├── ConnectionProvider.java │ │ │ ├── DataSourceConnectionProvider.java │ │ │ └── DriverManagerConnectionProvider.java │ │ │ ├── exception │ │ │ ├── ActiveRecordException.java │ │ │ ├── DataAccessException.java │ │ │ ├── FieldAccessException.java │ │ │ ├── TransactionException.java │ │ │ └── ValidateException.java │ │ │ ├── orm │ │ │ ├── BelongsToField.java │ │ │ ├── ColumnField.java │ │ │ ├── HasManyField.java │ │ │ └── HasOneField.java │ │ │ └── validators │ │ │ ├── AbstractValidator.java │ │ │ ├── EmailValidator.java │ │ │ ├── LengthValidator.java │ │ │ ├── NotEmptyValidator.java │ │ │ ├── PatternValidator.java │ │ │ ├── UniqueCreateValidator.java │ │ │ └── UniqueUpdateValidator.java │ └── et-mvc │ │ ├── .classpath │ │ ├── .project │ │ ├── .settings │ │ ├── org.eclipse.core.resources.prefs │ │ └── org.eclipse.jdt.core.prefs │ │ ├── COPYRIGHT.txt │ │ ├── README.txt │ │ ├── lib │ │ ├── commons-fileupload.jar │ │ ├── commons-io.jar │ │ ├── commons-logging.jar │ │ ├── freemarker.jar │ │ ├── paranamer-1.3.jar │ │ ├── servlet-api.jar │ │ └── spring.jar │ │ └── src │ │ └── com │ │ └── et │ │ └── mvc │ │ ├── BinaryView.java │ │ ├── Controller.java │ │ ├── Dispatcher.java │ │ ├── DispatcherFilter.java │ │ ├── Flash.java │ │ ├── FreeMarkerView.java │ │ ├── JsonView.java │ │ ├── JspView.java │ │ ├── MultipartFile.java │ │ ├── MultipartRequest.java │ │ ├── NormalRequest.java │ │ ├── PlugIn.java │ │ ├── PlugInContext.java │ │ ├── RequestContext.java │ │ ├── SpringDispatcherFilter.java │ │ ├── TextView.java │ │ ├── View.java │ │ ├── ViewContext.java │ │ ├── ViewRenderer.java │ │ ├── ViewRendererClass.java │ │ ├── binding │ │ ├── Bind.java │ │ ├── BindingContext.java │ │ ├── DataBinder.java │ │ ├── DataBinders.java │ │ └── binders │ │ │ ├── BigDecimalBinder.java │ │ │ ├── BigIntegerBinder.java │ │ │ ├── BooleanArrayBinder.java │ │ │ ├── BooleanBinder.java │ │ │ ├── DoubleArrayBinder.java │ │ │ ├── DoubleBinder.java │ │ │ ├── FloatArrayBinder.java │ │ │ ├── FloatBinder.java │ │ │ ├── IntegerArrayBinder.java │ │ │ ├── IntegerBinder.java │ │ │ ├── LongArrayBinder.java │ │ │ ├── LongBinder.java │ │ │ ├── MapBinder.java │ │ │ ├── MultipartFileBinder.java │ │ │ ├── ObjectBinder.java │ │ │ ├── ShortArrayBinder.java │ │ │ ├── ShortBinder.java │ │ │ ├── SqlDateBinder.java │ │ │ ├── SqlTimeBinder.java │ │ │ ├── SqlTimestampBinder.java │ │ │ ├── StringArrayBinder.java │ │ │ └── StringBinder.java │ │ ├── filter │ │ ├── AbstractAroundHandler.java │ │ ├── AfterFilter.java │ │ ├── AfterFilters.java │ │ ├── AroundFilter.java │ │ ├── AroundFilters.java │ │ ├── AroundHandler.java │ │ ├── BeforeFilter.java │ │ ├── BeforeFilters.java │ │ ├── Filter.java │ │ └── FilterUtils.java │ │ ├── renderer │ │ ├── AbstractViewRenderer.java │ │ ├── BinaryViewRenderer.java │ │ ├── FreeMarkerViewRenderer.java │ │ ├── JsonViewRenderer.java │ │ ├── JspViewRenderer.java │ │ ├── StringViewRenderer.java │ │ ├── TextViewRenderer.java │ │ └── VoidViewRenderer.java │ │ ├── routing │ │ ├── DefaultRouteHandler.java │ │ ├── Route.java │ │ ├── RouteHandler.java │ │ ├── RouteResult.java │ │ └── RouteTable.java │ │ └── util │ │ ├── Json.java │ │ └── Page.java ├── etmvc stworthy │ ├── et-ar │ │ ├── .classpath │ │ ├── .project │ │ ├── .settings │ │ │ ├── org.eclipse.core.resources.prefs │ │ │ └── org.eclipse.jdt.core.prefs │ │ ├── COPYRIGHT.txt │ │ ├── README.txt │ │ ├── lib │ │ │ ├── asm.jar │ │ │ ├── cglib-2.1.3.jar │ │ │ └── commons-logging.jar │ │ └── src │ │ │ └── com │ │ │ └── et │ │ │ └── ar │ │ │ ├── ActiveRecordBase.java │ │ │ ├── ActiveRecordProxy.java │ │ │ ├── ConfReader.java │ │ │ ├── ConnectionFactoryBean.java │ │ │ ├── ConnectionHolder.java │ │ │ ├── ConvertUtil.java │ │ │ ├── Converter.java │ │ │ ├── DaoSupport.java │ │ │ ├── Json.java │ │ │ ├── OrmInfo.java │ │ │ ├── Transaction.java │ │ │ ├── adapters │ │ │ ├── Adapter.java │ │ │ ├── DB2Adapter.java │ │ │ ├── MySqlAdapter.java │ │ │ ├── OracleAdapter.java │ │ │ ├── SqlServerAdapter.java │ │ │ └── SqliteAdapter.java │ │ │ ├── annotations │ │ │ ├── BelongsTo.java │ │ │ ├── Column.java │ │ │ ├── DependentType.java │ │ │ ├── Email.java │ │ │ ├── GeneratorType.java │ │ │ ├── HasMany.java │ │ │ ├── HasOne.java │ │ │ ├── Id.java │ │ │ ├── Length.java │ │ │ ├── NotEmpty.java │ │ │ ├── Pattern.java │ │ │ ├── Table.java │ │ │ ├── Unique.java │ │ │ └── ValidatorClass.java │ │ │ ├── connections │ │ │ ├── ConnectionProvider.java │ │ │ ├── DataSourceConnectionProvider.java │ │ │ └── DriverManagerConnectionProvider.java │ │ │ ├── exception │ │ │ ├── ActiveRecordException.java │ │ │ ├── DataAccessException.java │ │ │ ├── FieldAccessException.java │ │ │ ├── TransactionException.java │ │ │ └── ValidateException.java │ │ │ ├── orm │ │ │ ├── BelongsToField.java │ │ │ ├── ColumnField.java │ │ │ ├── HasManyField.java │ │ │ └── HasOneField.java │ │ │ └── validators │ │ │ ├── AbstractValidator.java │ │ │ ├── EmailValidator.java │ │ │ ├── LengthValidator.java │ │ │ ├── NotEmptyValidator.java │ │ │ ├── PatternValidator.java │ │ │ ├── UniqueCreateValidator.java │ │ │ └── UniqueUpdateValidator.java │ └── et-mvc │ │ ├── .classpath │ │ ├── .project │ │ ├── .settings │ │ ├── org.eclipse.core.resources.prefs │ │ └── org.eclipse.jdt.core.prefs │ │ ├── COPYRIGHT.txt │ │ ├── README.txt │ │ ├── lib │ │ ├── commons-fileupload.jar │ │ ├── commons-io.jar │ │ ├── commons-logging.jar │ │ ├── freemarker.jar │ │ ├── paranamer-1.3.jar │ │ ├── servlet-api.jar │ │ └── spring.jar │ │ └── src │ │ └── com │ │ └── et │ │ └── mvc │ │ ├── BinaryView.java │ │ ├── Controller.java │ │ ├── Dispatcher.java │ │ ├── DispatcherFilter.java │ │ ├── Flash.java │ │ ├── FreeMarkerView.java │ │ ├── JsonView.java │ │ ├── JspView.java │ │ ├── MultipartFile.java │ │ ├── MultipartRequest.java │ │ ├── NormalRequest.java │ │ ├── PlugIn.java │ │ ├── PlugInContext.java │ │ ├── RequestContext.java │ │ ├── SpringDispatcherFilter.java │ │ ├── TextView.java │ │ ├── View.java │ │ ├── ViewContext.java │ │ ├── ViewRenderer.java │ │ ├── ViewRendererClass.java │ │ ├── binding │ │ ├── Bind.java │ │ ├── BindingContext.java │ │ ├── DataBinder.java │ │ ├── DataBinders.java │ │ └── binders │ │ │ ├── BigDecimalBinder.java │ │ │ ├── BigIntegerBinder.java │ │ │ ├── BooleanArrayBinder.java │ │ │ ├── BooleanBinder.java │ │ │ ├── DoubleArrayBinder.java │ │ │ ├── DoubleBinder.java │ │ │ ├── FloatArrayBinder.java │ │ │ ├── FloatBinder.java │ │ │ ├── IntegerArrayBinder.java │ │ │ ├── IntegerBinder.java │ │ │ ├── LongArrayBinder.java │ │ │ ├── LongBinder.java │ │ │ ├── MapBinder.java │ │ │ ├── MultipartFileBinder.java │ │ │ ├── ObjectBinder.java │ │ │ ├── ShortArrayBinder.java │ │ │ ├── ShortBinder.java │ │ │ ├── SqlDateBinder.java │ │ │ ├── SqlTimeBinder.java │ │ │ ├── SqlTimestampBinder.java │ │ │ ├── StringArrayBinder.java │ │ │ └── StringBinder.java │ │ ├── filter │ │ ├── AbstractAroundHandler.java │ │ ├── AfterFilter.java │ │ ├── AfterFilters.java │ │ ├── AroundFilter.java │ │ ├── AroundFilters.java │ │ ├── AroundHandler.java │ │ ├── BeforeFilter.java │ │ ├── BeforeFilters.java │ │ ├── Filter.java │ │ └── FilterUtils.java │ │ ├── renderer │ │ ├── AbstractViewRenderer.java │ │ ├── BinaryViewRenderer.java │ │ ├── FreeMarkerViewRenderer.java │ │ ├── JsonViewRenderer.java │ │ ├── JspViewRenderer.java │ │ ├── StringViewRenderer.java │ │ ├── TextViewRenderer.java │ │ └── VoidViewRenderer.java │ │ ├── routing │ │ ├── DefaultRouteHandler.java │ │ ├── Route.java │ │ ├── RouteHandler.java │ │ ├── RouteResult.java │ │ └── RouteTable.java │ │ └── util │ │ ├── Json.java │ │ └── Page.java └── README.md └── Wiki ├── README.md ├── about.md ├── action.md ├── activerecord_callback.md ├── activerecord_datatype.md ├── activerecord_spring.md ├── aroundfilter.md ├── aroundfilter_exception.md ├── binders.md ├── configuration.md ├── controller.md ├── etmvc_spring.md ├── extendview.md ├── filters.md ├── helloworld.md ├── i18n.md ├── multi_database.md ├── ormbase.md ├── pagination.md ├── plugin.md ├── relation.md ├── route.md ├── transaction.md ├── upload_download.md ├── user_admin_example.md └── view.md /Download/etmvc-1.0.1-bin.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuzheng/etmvc/9eff387121679b67a281ee114f051cb0e470befb/Download/etmvc-1.0.1-bin.rar -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | et-ar 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | #Mon Jul 06 10:04:40 CST 2009 2 | eclipse.preferences.version=1 3 | encoding/=UTF-8 4 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Mon Jul 06 10:04:42 CST 2009 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.5 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.source=1.5 13 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/README.txt: -------------------------------------------------------------------------------- 1 | 致etmvc框架用户: 2 | 3 | 非常感谢您选择etmvc,相信她会为您的开发工作带来便利。 4 | 为了您更好地使用etmvc,请您参阅在线文档http://www.etmvc.cn/tutorial/index。 5 | 欢迎访问我们的网站:http://www.etmvc.cn。 6 | 欢迎提宝贵意见和建议。 7 | 8 | Copyright 2009 junxian she 9 | junxian she 10 | http://www.etmvc.cn 11 | 12 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/lib/asm.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuzheng/etmvc/9eff387121679b67a281ee114f051cb0e470befb/Source/ etmvc shuzheng/et-ar/lib/asm.jar -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/lib/cglib-2.1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuzheng/etmvc/9eff387121679b67a281ee114f051cb0e470befb/Source/ etmvc shuzheng/et-ar/lib/cglib-2.1.3.jar -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/lib/commons-logging.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuzheng/etmvc/9eff387121679b67a281ee114f051cb0e470befb/Source/ etmvc shuzheng/et-ar/lib/commons-logging.jar -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/ConnectionFactoryBean.java: -------------------------------------------------------------------------------- 1 | package com.et.ar; 2 | 3 | import com.et.ar.adapters.Adapter; 4 | import com.et.ar.connections.DataSourceConnectionProvider; 5 | import javax.sql.DataSource; 6 | 7 | public class ConnectionFactoryBean { 8 | private String domainBaseClass; 9 | private String adapterClass; 10 | private DataSource dataSource; 11 | 12 | public String getDomainBaseClass() { 13 | return domainBaseClass; 14 | } 15 | 16 | public void setDomainBaseClass(String domainBaseClass) { 17 | this.domainBaseClass = domainBaseClass; 18 | init(); 19 | } 20 | 21 | public DataSource getDataSource() { 22 | return dataSource; 23 | } 24 | 25 | public void setDataSource(DataSource dataSource) { 26 | this.dataSource = dataSource; 27 | init(); 28 | } 29 | 30 | public String getAdapterClass() { 31 | return adapterClass; 32 | } 33 | 34 | public void setAdapterClass(String adapterClass) { 35 | this.adapterClass = adapterClass; 36 | init(); 37 | } 38 | 39 | private void init(){ 40 | if (domainBaseClass != null && dataSource != null){ 41 | DataSourceConnectionProvider cp = new DataSourceConnectionProvider(dataSource); 42 | ActiveRecordBase.putConnectionProvider(domainBaseClass, cp); 43 | // ActiveRecordBase.connections.put(domainBaseClass, cp); 44 | } 45 | if (domainBaseClass != null && adapterClass != null){ 46 | try{ 47 | Adapter adapter = (Adapter)Class.forName(adapterClass).newInstance(); 48 | ActiveRecordBase.putConnectionAdapter(domainBaseClass, adapter); 49 | // ActiveRecordBase.adapters.put(domainBaseClass, (Adapter)Class.forName(adapterClass).newInstance()); 50 | } 51 | catch(Exception e){ 52 | 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/ConnectionHolder.java: -------------------------------------------------------------------------------- 1 | package com.et.ar; 2 | 3 | import com.et.ar.connections.ConnectionProvider; 4 | import com.et.ar.exception.DataAccessException; 5 | import java.sql.Connection; 6 | import java.sql.SQLException; 7 | 8 | /** 9 | * 管理当前操作的数据库连接,使用连接的优先顺序如下: 10 | * 1、如果处于事务中,则使用事务的连接; 11 | * 2、如果连接有缓存,则使用缓存中的连接; 12 | * 3、以上都没有,则创建从连接池中取得新的连接。 13 | * @author stworthy 14 | */ 15 | public class ConnectionHolder { 16 | private Transaction transaction = null; 17 | private ConnectionProvider connectionProvider = null; 18 | private Connection con = null; 19 | 20 | public ConnectionHolder(Class c) throws DataAccessException { 21 | transaction = ActiveRecordBase.getCurrentTransaction(c); 22 | 23 | try{ 24 | if (transaction == null){ 25 | connectionProvider = ActiveRecordBase.getConnectionProvider(c); 26 | con = connectionProvider.getConnection(); 27 | } 28 | else{ 29 | con = transaction.getConnection(); 30 | } 31 | } 32 | catch(SQLException e){ 33 | throw new DataAccessException(e); 34 | } 35 | } 36 | 37 | public Connection getConnection() { 38 | return con; 39 | } 40 | 41 | public void close() throws DataAccessException{ 42 | try{ 43 | if (transaction == null){ 44 | connectionProvider.closeConnection(con); 45 | } 46 | } 47 | catch(SQLException e){ 48 | throw new DataAccessException(e); 49 | } 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/Converter.java: -------------------------------------------------------------------------------- 1 | package com.et.ar; 2 | 3 | /** 4 | * 数据转换接口 5 | * @author stworthy 6 | */ 7 | public interface Converter { 8 | /** 9 | * 进行转换操作 10 | * @param obj 原对象 11 | * @return 转换后对象 12 | */ 13 | public Object convert(Object obj); 14 | } 15 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/Transaction.java: -------------------------------------------------------------------------------- 1 | package com.et.ar; 2 | 3 | import com.et.ar.exception.TransactionException; 4 | import java.sql.Connection; 5 | import java.sql.SQLException; 6 | 7 | /** 8 | * 事务描述类 9 | * @author stworthy 10 | */ 11 | public class Transaction { 12 | private int level = 0; 13 | private Connection conn = null; 14 | 15 | public Transaction(Connection conn) throws TransactionException { 16 | this.conn = conn; 17 | try{ 18 | this.conn.setAutoCommit(false); 19 | } 20 | catch(SQLException e){ 21 | throw new TransactionException(e); 22 | } 23 | } 24 | 25 | public Connection getConnection(){ 26 | return conn; 27 | } 28 | 29 | public void beginTransaction() throws TransactionException{ 30 | level += 1; 31 | } 32 | 33 | public void commit() throws TransactionException{ 34 | try{ 35 | level -= 1; 36 | if (level == 0){ 37 | conn.commit(); 38 | conn.close(); 39 | } 40 | } 41 | catch(SQLException e){ 42 | throw new TransactionException(e); 43 | } 44 | } 45 | 46 | public void rollback() throws TransactionException{ 47 | try{ 48 | level -= 1; 49 | if (level == 0){ 50 | conn.rollback(); 51 | conn.close(); 52 | } 53 | } 54 | catch(SQLException e){ 55 | throw new TransactionException(e); 56 | } 57 | } 58 | 59 | public boolean isFinished(){ 60 | return level == 0; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/adapters/Adapter.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.adapters; 2 | 3 | public abstract class Adapter { 4 | public abstract String getAdapterName(); 5 | public abstract String getLimitString(String sql, int limit, int offset); 6 | public abstract boolean supportsLimitOffset(); 7 | public abstract String getIdentitySelectString(); 8 | public abstract String getSequenceNextValString(String sequenceName); 9 | } 10 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/adapters/DB2Adapter.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.adapters; 2 | 3 | public class DB2Adapter extends Adapter { 4 | 5 | public String getAdapterName() { 6 | return "db2"; 7 | } 8 | 9 | public String getLimitString(String sql, int limit, int offset) { 10 | return sql + " fetch first " + Integer.toString(offset + limit) 11 | + " rows only"; 12 | } 13 | 14 | public boolean supportsLimitOffset() { 15 | return false; 16 | } 17 | 18 | public String getIdentitySelectString() { 19 | return "VALUES IDENTITY_VAL_LOCAL()"; 20 | } 21 | 22 | public String getSequenceNextValString(String sequenceName) { 23 | return null; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/adapters/MySqlAdapter.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.adapters; 2 | 3 | public class MySqlAdapter extends Adapter{ 4 | public String getAdapterName(){ 5 | return "mysql"; 6 | } 7 | 8 | public String getLimitString(String sql, int limit, int offset){ 9 | if (offset == 0){ 10 | return sql + " limit " + Integer.toString(limit); 11 | } 12 | else{ 13 | return sql + " limit " + Integer.toString(offset) + "," + Integer.toString(limit); 14 | } 15 | } 16 | 17 | public boolean supportsLimitOffset(){ 18 | return true; 19 | } 20 | 21 | public String getIdentitySelectString(){ 22 | return "select last_insert_id()"; 23 | } 24 | 25 | public String getSequenceNextValString(String sequenceName){ 26 | return null; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/adapters/OracleAdapter.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.adapters; 2 | 3 | public class OracleAdapter extends Adapter{ 4 | public String getAdapterName(){ 5 | return "oracle"; 6 | } 7 | 8 | public String getLimitString(String sql, int limit, int offset){ 9 | StringBuffer pagingSelect = new StringBuffer(sql.length()+100); 10 | if (offset == 0){ 11 | pagingSelect.append("select * from ( "); 12 | pagingSelect.append(sql); 13 | pagingSelect.append(" ) where rownum <= " + Integer.toString(limit)); 14 | } 15 | else{ 16 | pagingSelect.append("select * from ( select row_.*, rownum rownum_ from ( "); 17 | pagingSelect.append(sql); 18 | pagingSelect.append(" ) row_ ) where rownum_ <= "+Integer.toString(limit+offset)+" and rownum_ > "+Integer.toString(offset)); 19 | } 20 | return pagingSelect.toString(); 21 | } 22 | 23 | public boolean supportsLimitOffset(){ 24 | return true; 25 | } 26 | 27 | public String getIdentitySelectString(){ 28 | return null; 29 | } 30 | 31 | public String getSequenceNextValString(String sequenceName){ 32 | return "select " + sequenceName + ".nextval from dual"; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/adapters/SqlServerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.adapters; 2 | 3 | public class SqlServerAdapter extends Adapter{ 4 | public String getAdapterName(){ 5 | return "sqlserver"; 6 | } 7 | 8 | public String getLimitString(String sql, int limit, int offset){ 9 | if (sql.toLowerCase().startsWith("select distinct")){ 10 | return "select distinct top " + Integer.toString(limit+offset) + sql.substring("select distinct".length()); 11 | } 12 | else{ 13 | return "select top " + Integer.toString(limit+offset) + sql.substring("select".length()); 14 | } 15 | } 16 | 17 | public boolean supportsLimitOffset(){ 18 | return false; 19 | } 20 | 21 | public String getIdentitySelectString(){ 22 | return "SELECT @@IDENTITY"; 23 | // return "select scope_identity()"; 24 | } 25 | 26 | public String getSequenceNextValString(String sequenceName){ 27 | return null; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/adapters/SqliteAdapter.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.adapters; 2 | 3 | public class SqliteAdapter extends Adapter{ 4 | public String getAdapterName(){ 5 | return "sqlite"; 6 | } 7 | 8 | public String getLimitString(String sql, int limit, int offset){ 9 | if (offset == 0){ 10 | return sql + " limit " + Integer.toString(limit); 11 | } 12 | else{ 13 | return sql + " limit " + Integer.toString(offset) + "," + Integer.toString(limit); 14 | } 15 | } 16 | 17 | public boolean supportsLimitOffset(){ 18 | return true; 19 | } 20 | 21 | public String getIdentitySelectString(){ 22 | return "select last_insert_rowid()"; 23 | } 24 | 25 | public String getSequenceNextValString(String sequenceName){ 26 | return null; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/annotations/BelongsTo.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.annotations; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | @Target({ElementType.FIELD,ElementType.METHOD}) 10 | @Retention(RetentionPolicy.RUNTIME) 11 | @Documented 12 | public @interface BelongsTo { 13 | String foreignKey() default ""; 14 | } 15 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/annotations/Column.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.annotations; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | 10 | @Target({ElementType.FIELD,ElementType.METHOD}) 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Documented 13 | public @interface Column { 14 | } 15 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/annotations/DependentType.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.annotations; 2 | 3 | public enum DependentType { 4 | DESTROY, 5 | DELETE, 6 | NULLIFY 7 | } 8 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/annotations/Email.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.annotations; 2 | 3 | import com.et.ar.validators.EmailValidator; 4 | import java.lang.annotation.Documented; 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | @ValidatorClass(EmailValidator.class) 11 | @Target({ElementType.FIELD,ElementType.METHOD}) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Documented 14 | public @interface Email { 15 | String message() default "非法电子邮件格式"; 16 | } 17 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/annotations/GeneratorType.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.annotations; 2 | 3 | public enum GeneratorType { 4 | SEQUENCE, 5 | IDENTITY, 6 | AUTO, 7 | NONE 8 | } 9 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/annotations/HasMany.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.annotations; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | @Target({ElementType.FIELD,ElementType.METHOD}) 10 | @Retention(RetentionPolicy.RUNTIME) 11 | @Documented 12 | public @interface HasMany { 13 | String foreignKey() default ""; 14 | DependentType dependent() default DependentType.NULLIFY; 15 | String order() default ""; 16 | } 17 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/annotations/HasOne.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.annotations; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | @Target({ElementType.FIELD,ElementType.METHOD}) 10 | @Retention(RetentionPolicy.RUNTIME) 11 | @Documented 12 | public @interface HasOne { 13 | String foreignKey() default ""; 14 | DependentType dependent() default DependentType.NULLIFY; 15 | String order() default ""; 16 | } 17 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/annotations/Id.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.annotations; 2 | 3 | import java.lang.annotation.*; 4 | 5 | @Target({ElementType.FIELD,ElementType.METHOD}) 6 | @Retention(RetentionPolicy.RUNTIME) 7 | @Documented 8 | public @interface Id { 9 | GeneratorType generate() default GeneratorType.AUTO; 10 | } 11 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/annotations/Length.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.annotations; 2 | 3 | import com.et.ar.validators.LengthValidator; 4 | import java.lang.annotation.*; 5 | 6 | @ValidatorClass(LengthValidator.class) 7 | @Target({ElementType.FIELD,ElementType.METHOD}) 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Documented 10 | public @interface Length{ 11 | int min() default 0; 12 | int max(); 13 | String message(); 14 | } 15 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/annotations/NotEmpty.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.annotations; 2 | 3 | import com.et.ar.validators.NotEmptyValidator; 4 | import java.lang.annotation.Documented; 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | @ValidatorClass(NotEmptyValidator.class) 11 | @Target({ElementType.FIELD,ElementType.METHOD}) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Documented 14 | public @interface NotEmpty { 15 | String message() default "字段内容不能为空"; 16 | } 17 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/annotations/Pattern.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.annotations; 2 | 3 | import com.et.ar.validators.PatternValidator; 4 | import java.lang.annotation.*; 5 | 6 | @ValidatorClass(PatternValidator.class) 7 | @Target({ElementType.FIELD,ElementType.METHOD}) 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Documented 10 | public @interface Pattern { 11 | String regex(); 12 | String message() default "模式匹配错误"; 13 | } 14 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/annotations/Table.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.annotations; 2 | 3 | import java.lang.annotation.*; 4 | 5 | @Target({ElementType.TYPE}) 6 | @Retention(RetentionPolicy.RUNTIME) 7 | @Documented 8 | public @interface Table { 9 | String name(); 10 | } 11 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/annotations/Unique.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.annotations; 2 | 3 | import java.lang.annotation.*; 4 | 5 | @Target({ElementType.FIELD,ElementType.METHOD}) 6 | @Retention(RetentionPolicy.RUNTIME) 7 | @Documented 8 | public @interface Unique { 9 | String message(); 10 | } 11 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/annotations/ValidatorClass.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.annotations; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | @Target({ElementType.ANNOTATION_TYPE}) 10 | @Retention(RetentionPolicy.RUNTIME) 11 | @Documented 12 | public @interface ValidatorClass { 13 | Class value(); 14 | } 15 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/connections/ConnectionProvider.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.connections; 2 | 3 | import java.sql.*; 4 | 5 | public interface ConnectionProvider { 6 | public Connection getConnection() throws SQLException; 7 | 8 | public void closeConnection(Connection conn) throws SQLException; 9 | 10 | public void close() throws SQLException; 11 | } 12 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/connections/DataSourceConnectionProvider.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.connections; 2 | 3 | import java.sql.Connection; 4 | import java.sql.SQLException; 5 | import javax.sql.DataSource; 6 | 7 | public class DataSourceConnectionProvider implements ConnectionProvider{ 8 | private DataSource ds; 9 | 10 | public DataSourceConnectionProvider(DataSource ds){ 11 | this.ds = ds; 12 | } 13 | 14 | public Connection getConnection() throws SQLException{ 15 | return ds.getConnection(); 16 | } 17 | 18 | public void closeConnection(Connection con) throws SQLException{ 19 | con.close(); 20 | } 21 | 22 | public void close() throws SQLException{ 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/exception/ActiveRecordException.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.exception; 2 | 3 | /** 4 | * 活动记录操作异常基类 5 | * @author stworthy 6 | * 7 | */ 8 | public class ActiveRecordException extends Exception{ 9 | /** 10 | * 11 | */ 12 | private static final long serialVersionUID = 1L; 13 | 14 | public ActiveRecordException(String s){ 15 | super(s); 16 | } 17 | 18 | public ActiveRecordException(String s, Throwable root){ 19 | super(s, root); 20 | } 21 | 22 | public ActiveRecordException(Throwable root){ 23 | super(root); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/exception/DataAccessException.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.exception; 2 | 3 | import java.sql.SQLException; 4 | 5 | /** 6 | * 数据访问异常类 7 | * @author stworthy 8 | * 9 | */ 10 | public class DataAccessException extends ActiveRecordException{ 11 | /** 12 | * 13 | */ 14 | private static final long serialVersionUID = 1L; 15 | 16 | public DataAccessException(String s, SQLException root){ 17 | super(s, root); 18 | } 19 | 20 | public DataAccessException(SQLException root){ 21 | super(root); 22 | } 23 | // 24 | // public DataAccessException(Exception root){ 25 | // super(root); 26 | // } 27 | } 28 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/exception/FieldAccessException.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.exception; 2 | 3 | /** 4 | * 对象字段访问异常类 5 | * @author stworthy 6 | */ 7 | public class FieldAccessException extends ActiveRecordException{ 8 | /** 9 | * 10 | */ 11 | private static final long serialVersionUID = 1L; 12 | 13 | public FieldAccessException(String s){ 14 | super(s); 15 | } 16 | 17 | public FieldAccessException(String s, Throwable root){ 18 | super(s, root); 19 | } 20 | 21 | public FieldAccessException(Throwable root){ 22 | super(root); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/exception/TransactionException.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.exception; 2 | 3 | /** 4 | * 事务操作异常类 5 | * @author stworthy 6 | */ 7 | public class TransactionException extends ActiveRecordException{ 8 | /** 9 | * 10 | */ 11 | private static final long serialVersionUID = 1L; 12 | 13 | public TransactionException(String s){ 14 | super(s); 15 | } 16 | 17 | public TransactionException(String s, Throwable root){ 18 | super(s, root); 19 | } 20 | 21 | public TransactionException(Throwable root){ 22 | super(root); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/exception/ValidateException.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.exception; 2 | 3 | /** 4 | * 数据验证异常类 5 | * @author stworthy 6 | */ 7 | public class ValidateException extends ActiveRecordException{ 8 | /** 9 | * 10 | */ 11 | private static final long serialVersionUID = 1L; 12 | 13 | public ValidateException(String s){ 14 | super(s); 15 | } 16 | 17 | public ValidateException(String s, Throwable root){ 18 | super(s, root); 19 | } 20 | 21 | public ValidateException(Throwable root){ 22 | super(root); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/orm/BelongsToField.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.orm; 2 | 3 | import com.et.ar.annotations.BelongsTo; 4 | 5 | public class BelongsToField { 6 | private String name; 7 | private BelongsTo annotation; 8 | private Class targetType; 9 | private String foreignKey; 10 | 11 | public String getName() { 12 | return name; 13 | } 14 | 15 | public void setName(String name) { 16 | this.name = name; 17 | } 18 | 19 | public BelongsTo getAnnotation() { 20 | return annotation; 21 | } 22 | 23 | public void setAnnotation(BelongsTo annotation) { 24 | this.annotation = annotation; 25 | } 26 | 27 | public Class getTargetType() { 28 | return targetType; 29 | } 30 | 31 | public void setTargetType(Class targetType) { 32 | this.targetType = targetType; 33 | } 34 | 35 | public String getForeignKey() { 36 | return foreignKey; 37 | } 38 | 39 | public void setForeignKey(String foreignKey) { 40 | this.foreignKey = foreignKey; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/orm/ColumnField.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.orm; 2 | 3 | public class ColumnField { 4 | private String name; 5 | private Class type; 6 | 7 | public String getName() { 8 | return name; 9 | } 10 | 11 | public void setName(String name) { 12 | this.name = name; 13 | } 14 | 15 | public Class getType() { 16 | return type; 17 | } 18 | 19 | public void setType(Class type) { 20 | this.type = type; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/orm/HasManyField.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.orm; 2 | 3 | import com.et.ar.annotations.HasMany; 4 | 5 | public class HasManyField { 6 | private String name; 7 | private HasMany annotation; 8 | private Class targetType; 9 | private String foreignKey; 10 | 11 | public String getName() { 12 | return name; 13 | } 14 | 15 | public void setName(String name) { 16 | this.name = name; 17 | } 18 | 19 | public HasMany getAnnotation() { 20 | return annotation; 21 | } 22 | 23 | public void setAnnotation(HasMany annotation) { 24 | this.annotation = annotation; 25 | } 26 | 27 | public Class getTargetType() { 28 | return targetType; 29 | } 30 | 31 | public void setTargetType(Class targetType) { 32 | this.targetType = targetType; 33 | } 34 | 35 | public String getForeignKey() { 36 | return foreignKey; 37 | } 38 | 39 | public void setForeignKey(String foreignKey) { 40 | this.foreignKey = foreignKey; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/orm/HasOneField.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.orm; 2 | 3 | import com.et.ar.annotations.HasOne; 4 | 5 | public class HasOneField { 6 | private String name; 7 | private HasOne annotation; 8 | private Class targetType; 9 | private String foreignKey; 10 | 11 | public String getName() { 12 | return name; 13 | } 14 | 15 | public void setName(String name) { 16 | this.name = name; 17 | } 18 | 19 | public HasOne getAnnotation() { 20 | return annotation; 21 | } 22 | 23 | public void setAnnotation(HasOne annotation) { 24 | this.annotation = annotation; 25 | } 26 | 27 | public Class getTargetType() { 28 | return targetType; 29 | } 30 | 31 | public void setTargetType(Class targetType) { 32 | this.targetType = targetType; 33 | } 34 | 35 | public String getForeignKey() { 36 | return foreignKey; 37 | } 38 | 39 | public void setForeignKey(String foreignKey) { 40 | this.foreignKey = foreignKey; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/validators/EmailValidator.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.validators; 2 | 3 | import com.et.ar.annotations.Email; 4 | 5 | /** 6 | * 电子邮件验证类 7 | * @author stworthy 8 | */ 9 | public class EmailValidator extends AbstractValidator{ 10 | public boolean validate(Object value) { 11 | String parten = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}" + 12 | "\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\" + 13 | ".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"; 14 | String s = (String)value; 15 | if (s == null){ 16 | s = ""; 17 | } 18 | if (s.matches(parten) == false){ 19 | return false; 20 | } 21 | return true; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/validators/LengthValidator.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.validators; 2 | 3 | import com.et.ar.annotations.Length; 4 | 5 | /** 6 | * 长度验证类 7 | * @author stworthy 8 | */ 9 | public class LengthValidator extends AbstractValidator{ 10 | public boolean validate(Object value) { 11 | String s = (String)value; 12 | if (s == null){ 13 | s = ""; 14 | } 15 | if (s.length() < parameters.min() || s.length() > parameters.max()){ 16 | return false; 17 | } 18 | else{ 19 | return true; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/validators/NotEmptyValidator.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.validators; 2 | 3 | import com.et.ar.annotations.NotEmpty; 4 | 5 | /** 6 | * 数据非空验证类 7 | * @author stworthy 8 | */ 9 | public class NotEmptyValidator extends AbstractValidator{ 10 | public boolean validate(Object value) { 11 | if (value == null){ 12 | return false; 13 | } 14 | if (value instanceof String){ 15 | String s = (String)value; 16 | if (s.length() == 0){ 17 | return false; 18 | } 19 | } 20 | return true; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/validators/PatternValidator.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.validators; 2 | 3 | import com.et.ar.annotations.Pattern; 4 | 5 | 6 | /** 7 | * 模式匹配验证类 8 | * @author stworthy 9 | */ 10 | public class PatternValidator extends AbstractValidator{ 11 | public boolean validate(Object value){ 12 | String s = (String)value; 13 | if (s == null){ 14 | s = ""; 15 | } 16 | if (!s.matches(parameters.regex())){ 17 | return false; 18 | } 19 | else{ 20 | return true; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/validators/UniqueCreateValidator.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.validators; 2 | 3 | import com.et.ar.ActiveRecordBase; 4 | import com.et.ar.exception.ValidateException; 5 | import com.et.ar.annotations.Unique; 6 | 7 | /** 8 | * 数据创建唯一性验证类 9 | * @author stworthy 10 | */ 11 | public class UniqueCreateValidator extends AbstractValidator{ 12 | private Class c; 13 | private String tableName; 14 | private String fieldName; 15 | 16 | public UniqueCreateValidator(Class c, String tableName, String fieldName, Unique parameters){ 17 | super.init(parameters); 18 | this.c = c; 19 | this.tableName = tableName; 20 | this.fieldName = fieldName; 21 | } 22 | 23 | public boolean validate(Object value) throws ValidateException{ 24 | try{ 25 | String sql = "select count(*) from "+tableName+" where "+fieldName+"=?"; 26 | Object[] args = new Object[]{value}; 27 | Object count = ActiveRecordBase.executeScalar(c, sql, args); 28 | if (Integer.parseInt(count.toString()) > 0){ 29 | return false; 30 | } 31 | else{ 32 | return true; 33 | } 34 | } 35 | catch(Exception e){ 36 | throw new ValidateException(e); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-ar/src/com/et/ar/validators/UniqueUpdateValidator.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.validators; 2 | 3 | import com.et.ar.ActiveRecordBase; 4 | import com.et.ar.exception.ValidateException; 5 | import com.et.ar.annotations.Unique; 6 | 7 | /** 8 | * 数据更新时唯一性验证类 9 | * @author stworthy 10 | */ 11 | public class UniqueUpdateValidator extends AbstractValidator{ 12 | private Class c; 13 | private String tableName; 14 | private String fieldName; 15 | private String fieldId; 16 | private Object idValue; 17 | 18 | public UniqueUpdateValidator(Class c, String tableName, String fieldName, String fieldId, Object idValue, Unique parameters){ 19 | super.init(parameters); 20 | this.c = c; 21 | this.tableName = tableName; 22 | this.fieldName = fieldName; 23 | this.fieldId = fieldId; 24 | this.idValue = idValue; 25 | } 26 | 27 | public boolean validate(Object value) throws ValidateException{ 28 | try{ 29 | String sql = "select count(*) from "+tableName+" where "+fieldName+"=? and "+fieldId+"<>?"; 30 | Object[] args = new Object[]{value,idValue}; 31 | Object count = ActiveRecordBase.executeScalar(c, sql, args); 32 | if (Integer.parseInt(count.toString()) > 0){ 33 | return false; 34 | } 35 | else{ 36 | return true; 37 | } 38 | } 39 | catch(Exception e){ 40 | throw new ValidateException(e); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | et-mvc 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | #Mon Jul 06 08:58:43 CST 2009 2 | eclipse.preferences.version=1 3 | encoding/=UTF-8 4 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Mon Jul 06 08:56:33 CST 2009 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.5 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.source=1.5 13 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/README.txt: -------------------------------------------------------------------------------- 1 | 致etmvc框架用户: 2 | 3 | 非常感谢您选择etmvc,相信她会为您的开发工作带来便利。 4 | 为了您更好地使用etmvc,请您参阅在线文档http://www.etmvc.cn/tutorial/index。 5 | 欢迎访问我们的网站:http://www.etmvc.cn。 6 | 欢迎提宝贵意见和建议。 7 | 8 | Copyright 2009 junxian she 9 | junxian she 10 | http://www.etmvc.cn 11 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/lib/commons-fileupload.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuzheng/etmvc/9eff387121679b67a281ee114f051cb0e470befb/Source/ etmvc shuzheng/et-mvc/lib/commons-fileupload.jar -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/lib/commons-io.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuzheng/etmvc/9eff387121679b67a281ee114f051cb0e470befb/Source/ etmvc shuzheng/et-mvc/lib/commons-io.jar -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/lib/commons-logging.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuzheng/etmvc/9eff387121679b67a281ee114f051cb0e470befb/Source/ etmvc shuzheng/et-mvc/lib/commons-logging.jar -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/lib/freemarker.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuzheng/etmvc/9eff387121679b67a281ee114f051cb0e470befb/Source/ etmvc shuzheng/et-mvc/lib/freemarker.jar -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/lib/paranamer-1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuzheng/etmvc/9eff387121679b67a281ee114f051cb0e470befb/Source/ etmvc shuzheng/et-mvc/lib/paranamer-1.3.jar -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/lib/servlet-api.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuzheng/etmvc/9eff387121679b67a281ee114f051cb0e470befb/Source/ etmvc shuzheng/et-mvc/lib/servlet-api.jar -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/lib/spring.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuzheng/etmvc/9eff387121679b67a281ee114f051cb0e470befb/Source/ etmvc shuzheng/et-mvc/lib/spring.jar -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/Flash.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * 闪存类,用于在二次action操作中传递数据,传递后自动丢弃 8 | * @author stworthy 9 | */ 10 | public class Flash { 11 | public final static String FLASH_KEY = "flash_key"; 12 | 13 | private Map attr = new HashMap(); 14 | private Map keepAttr = new HashMap(); 15 | 16 | public void setAttribute(String key, Object value){ 17 | attr.put(key, value); 18 | } 19 | 20 | public Map getAttributes(){ 21 | return attr; 22 | } 23 | 24 | public Object getAttribute(String attributeName){ 25 | return attr.get(attributeName); 26 | } 27 | 28 | public void keep(){ 29 | keepAttr = attr; 30 | } 31 | 32 | public void keep(String key){ 33 | keepAttr.put(key, attr.get(key)); 34 | } 35 | 36 | protected void sweep(){ 37 | attr = keepAttr; 38 | keepAttr = new HashMap(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/FreeMarkerView.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc; 2 | 3 | import com.et.mvc.renderer.FreeMarkerViewRenderer; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | /** 8 | * 使用FreeMarker模板的视图类
9 | * 范例: 10 | *
11 |  * FreeMarkerView view = new FreeMarkerView();
12 |  * view.setAttribute("info", "...");
13 |  * return view;
14 |  * 
15 | * 或者: 16 | *
17 |  * request.setAttribute("info", "...");
18 |  * return new FreeMarkerView();
19 |  * 
20 | * @author stworthy 21 | */ 22 | @ViewRendererClass(FreeMarkerViewRenderer.class) 23 | public class FreeMarkerView extends View{ 24 | private String path; 25 | private Map attributes = new HashMap(); 26 | 27 | public FreeMarkerView(){ 28 | this.path = null; 29 | } 30 | 31 | public FreeMarkerView(String path){ 32 | this.path = path; 33 | } 34 | 35 | public FreeMarkerView(String path, String key, Object value){ 36 | this.path = path; 37 | this.setAttribute(key, value); 38 | } 39 | 40 | public FreeMarkerView(String key, Object value){ 41 | this.path = null; 42 | this.setAttribute(key, value); 43 | } 44 | 45 | public Map getAttributes() { 46 | return attributes; 47 | } 48 | 49 | public void setAttribute(String key, Object value){ 50 | attributes.put(key, value); 51 | } 52 | 53 | public String getPath() { 54 | return path; 55 | } 56 | 57 | public void setPath(String path) { 58 | this.path = path; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/JspView.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc; 2 | 3 | import com.et.mvc.renderer.JspViewRenderer; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | /** 8 | * 使用JSP的视图类 9 | *
10 |  * request.setAttribute("info","...");
11 |  * return new JspView("/user/show.jsp");
12 |  * 
13 | * 或者 14 | *
15 |  * JspView view = new JspView("/user/show.jsp");
16 |  * view.setAttribute("info","...");
17 |  * return view;
18 |  * 
19 | * @author stworthy 20 | */ 21 | @ViewRendererClass(JspViewRenderer.class) 22 | public class JspView extends View{ 23 | private String path; 24 | private Map attributes = new HashMap(); 25 | 26 | public JspView(){ 27 | this.path = null; 28 | } 29 | 30 | public JspView(String path){ 31 | this.path = path; 32 | } 33 | 34 | public JspView(String path, String key, Object value){ 35 | this.path = path; 36 | this.setAttribute(key, value); 37 | } 38 | 39 | public JspView(String key, Object value){ 40 | this.path = null; 41 | this.setAttribute(key, value); 42 | } 43 | 44 | public String getPath() { 45 | return path; 46 | } 47 | 48 | public void setPath(String path) { 49 | this.path = path; 50 | } 51 | 52 | public void setAttribute(String key, Object value){ 53 | attributes.put(key, value); 54 | } 55 | 56 | public Map getAttributes(){ 57 | return attributes; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/MultipartFile.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.io.File; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import org.apache.commons.fileupload.FileItem; 8 | 9 | /** 10 | * 文件上传支持类 11 | * @author stworthy 12 | */ 13 | public class MultipartFile { 14 | private FileItem fileItem; 15 | private long size; 16 | 17 | public MultipartFile(FileItem fileItem){ 18 | this.fileItem = fileItem; 19 | this.size = this.fileItem.getSize(); 20 | } 21 | 22 | public String getName(){ 23 | return fileItem.getFieldName(); 24 | } 25 | 26 | public String getOriginalFilename(){ 27 | String filename = this.fileItem.getName(); 28 | if (filename == null){ 29 | return ""; 30 | } 31 | int pos = filename.lastIndexOf("/"); 32 | if (pos == -1){ 33 | pos = filename.lastIndexOf("\\"); 34 | } 35 | if (pos != -1){ 36 | return filename.substring(pos+1); 37 | } 38 | else{ 39 | return filename; 40 | } 41 | } 42 | 43 | public String getContentType(){ 44 | return this.fileItem.getContentType(); 45 | } 46 | 47 | public boolean isEmpty(){ 48 | return size==0; 49 | } 50 | 51 | public long getSize(){ 52 | return size; 53 | } 54 | 55 | public byte[] getBytes(){ 56 | byte[] bytes = this.fileItem.get(); 57 | return bytes == null ? new byte[0] : bytes; 58 | } 59 | 60 | public InputStream getInputStream() throws IOException{ 61 | InputStream inputStream = this.fileItem.getInputStream(); 62 | return inputStream != null ? inputStream : new ByteArrayInputStream(new byte[0]); 63 | } 64 | 65 | public void transferTo(File dest) throws Exception{ 66 | this.fileItem.write(dest); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/PlugIn.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc; 2 | 3 | /** 4 | * 插件接口 5 | * @author stworthy 6 | */ 7 | public interface PlugIn { 8 | /** 9 | * 插件初始化时执行的方法 10 | * @param context 插件上下文对象 11 | */ 12 | public void init(PlugInContext context); 13 | 14 | /** 15 | * 插件销毁时执行的方法 16 | */ 17 | public void destroy(); 18 | } 19 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/PlugInContext.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc; 2 | 3 | import java.util.Map; 4 | import javax.servlet.ServletContext; 5 | 6 | /** 7 | * 插件上下文类 8 | * @author stworthy 9 | */ 10 | public class PlugInContext { 11 | private ServletContext servletContext; 12 | private Map configParams; 13 | 14 | public ServletContext getServletContext() { 15 | return servletContext; 16 | } 17 | 18 | public void setServletContext(ServletContext servletContext) { 19 | this.servletContext = servletContext; 20 | } 21 | 22 | public Map getConfigParams() { 23 | return configParams; 24 | } 25 | 26 | public void setConfigParams(Map configParams) { 27 | this.configParams = configParams; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/RequestContext.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc; 2 | 3 | import java.util.List; 4 | import javax.servlet.http.HttpServletRequest; 5 | 6 | /** 7 | * 请求的上下文 8 | * @author stworthy 9 | */ 10 | public class RequestContext { 11 | private String controllerBasePackage; 12 | private List controllerPaths; 13 | private HttpServletRequest request; 14 | 15 | public String getControllerBasePackage() { 16 | return controllerBasePackage; 17 | } 18 | 19 | public void setControllerBasePackage(String controllerBasePackage) { 20 | this.controllerBasePackage = controllerBasePackage; 21 | } 22 | 23 | public List getControllerPaths() { 24 | return controllerPaths; 25 | } 26 | 27 | public void setControllerPaths(List controllerPaths) { 28 | this.controllerPaths = controllerPaths; 29 | } 30 | 31 | public HttpServletRequest getRequest() { 32 | return request; 33 | } 34 | 35 | public void setRequest(HttpServletRequest request) { 36 | this.request = request; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/SpringDispatcherFilter.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc; 2 | 3 | import javax.servlet.FilterConfig; 4 | import javax.servlet.ServletContext; 5 | import org.springframework.web.context.WebApplicationContext; 6 | import org.springframework.web.context.support.WebApplicationContextUtils; 7 | 8 | /** 9 | * 同spring集成的分发器 10 | * @author stworthy 11 | */ 12 | public class SpringDispatcherFilter extends DispatcherFilter{ 13 | private WebApplicationContext webApplicationContext; 14 | 15 | @Override 16 | public void init(FilterConfig config){ 17 | super.init(config); 18 | this.setWebApplicationContext(initWebApplicationContext(config.getServletContext())); 19 | } 20 | 21 | protected WebApplicationContext initWebApplicationContext(ServletContext servletContext){ 22 | return WebApplicationContextUtils.getWebApplicationContext(servletContext); 23 | } 24 | 25 | @Override 26 | public Object getController(String controllerClassName) throws Exception{ 27 | if (this.webApplicationContext.containsBean(controllerClassName)){ 28 | return this.webApplicationContext.getBean(controllerClassName); 29 | } 30 | else{ 31 | return super.getController(controllerClassName); 32 | } 33 | } 34 | 35 | public WebApplicationContext getWebApplicationContext() { 36 | return webApplicationContext; 37 | } 38 | 39 | public void setWebApplicationContext(WebApplicationContext webApplicationContext) { 40 | this.webApplicationContext = webApplicationContext; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/TextView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package com.et.mvc; 7 | 8 | import com.et.mvc.renderer.TextViewRenderer; 9 | 10 | /** 11 | * 文本视图,用于向浏览器返回一段文本 12 | * @author stworthy 13 | */ 14 | @ViewRendererClass(TextViewRenderer.class) 15 | public class TextView extends View{ 16 | private String text; 17 | 18 | public TextView(){ 19 | text = ""; 20 | } 21 | 22 | public TextView(String text){ 23 | this.text = text; 24 | } 25 | 26 | public TextView(String text, String contentType){ 27 | this.text = text; 28 | setContentType(contentType); 29 | } 30 | 31 | public String getText() { 32 | return text; 33 | } 34 | 35 | public void setText(String text) { 36 | this.text = text; 37 | } 38 | 39 | @Override 40 | public String toString(){ 41 | return text; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/View.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc; 2 | 3 | /** 4 | * 视图抽象类,建议所有的自定义视图类继承该类,但不是必须的 5 | * @author stworthy 6 | */ 7 | public abstract class View { 8 | private String contentType; 9 | private Class rendererClass = null; 10 | 11 | public String getContentType() { 12 | return contentType; 13 | } 14 | 15 | public void setContentType(String contentType) { 16 | this.contentType = contentType; 17 | } 18 | 19 | public void setRendererClass(Class rendererClass) { 20 | this.rendererClass = rendererClass; 21 | } 22 | 23 | public Class getRendererClass() { 24 | return rendererClass; 25 | } 26 | 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/ViewContext.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc; 2 | 3 | import javax.servlet.ServletContext; 4 | import javax.servlet.http.HttpServletRequest; 5 | import javax.servlet.http.HttpServletResponse; 6 | 7 | /** 8 | * 视图上下文 9 | * @author stworthy 10 | */ 11 | public class ViewContext { 12 | private String viewBasePath; 13 | private String controllerPath; 14 | private String actionName; 15 | private HttpServletRequest request; 16 | private HttpServletResponse response; 17 | private ServletContext servletContext; 18 | 19 | public String getViewBasePath() { 20 | return viewBasePath; 21 | } 22 | 23 | public void setViewBasePath(String viewBasePath) { 24 | this.viewBasePath = viewBasePath; 25 | } 26 | 27 | public HttpServletRequest getRequest() { 28 | return request; 29 | } 30 | 31 | public void setRequest(HttpServletRequest request) { 32 | this.request = request; 33 | } 34 | 35 | public HttpServletResponse getResponse() { 36 | return response; 37 | } 38 | 39 | public void setResponse(HttpServletResponse response) { 40 | this.response = response; 41 | } 42 | 43 | public ServletContext getServletContext() { 44 | return servletContext; 45 | } 46 | 47 | public void setServletContext(ServletContext servletContext) { 48 | this.servletContext = servletContext; 49 | } 50 | 51 | public String getActionName() { 52 | return actionName; 53 | } 54 | 55 | public void setActionName(String actionName) { 56 | this.actionName = actionName; 57 | } 58 | 59 | public String getControllerPath() { 60 | return controllerPath; 61 | } 62 | 63 | public void setControllerPath(String controllerPath) { 64 | this.controllerPath = controllerPath; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/ViewRenderer.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc; 2 | 3 | /** 4 | * 视图渲染接口 5 | * @author stworthy 6 | */ 7 | public interface ViewRenderer { 8 | /** 9 | * 渲染动作 10 | * @param viewObject 视图对象 11 | * @param viewContext 视图上下文 12 | * @throws Exception 13 | */ 14 | public void render(T viewObject, ViewContext viewContext) throws Exception; 15 | } 16 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/ViewRendererClass.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /** 10 | * 指定视图渲染类的注解 11 | * @author stworthy 12 | */ 13 | @Target({ElementType.TYPE}) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Documented 16 | public @interface ViewRendererClass { 17 | Class value(); 18 | } 19 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/binding/Bind.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.binding; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /** 10 | * 绑定请求参数注解,用于指示请求参数的前缀,如:
11 | *
12 |  * public void save(@Bind(prefix="user")User user) throws Exception{
13 |  * }
14 |  * 
15 | * HTTP传递过来的参数必须是user.code,user.name才能绑定到user对象 16 | * @author stworthy 17 | */ 18 | @Target({ElementType.PARAMETER}) 19 | @Retention(RetentionPolicy.RUNTIME) 20 | @Documented 21 | public @interface Bind { 22 | String prefix() default ""; 23 | } 24 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/binding/BindingContext.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.binding; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | 5 | /** 6 | * 绑定上下文 7 | * @author stworthy 8 | */ 9 | public class BindingContext { 10 | private String parameterName; 11 | private Class parameterType; 12 | private HttpServletRequest request; 13 | private String prefix; 14 | 15 | public String getParameterName() { 16 | return parameterName; 17 | } 18 | 19 | public void setParameterName(String parameterName) { 20 | this.parameterName = parameterName; 21 | } 22 | 23 | public Class getParameterType() { 24 | return parameterType; 25 | } 26 | 27 | public void setParameterType(Class parameterType) { 28 | this.parameterType = parameterType; 29 | } 30 | 31 | public HttpServletRequest getRequest() { 32 | return request; 33 | } 34 | 35 | public void setRequest(HttpServletRequest request) { 36 | this.request = request; 37 | } 38 | 39 | public String getPrefix() { 40 | return prefix; 41 | } 42 | 43 | public void setPrefix(String prefix) { 44 | this.prefix = prefix; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/binding/DataBinder.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.binding; 2 | 3 | /** 4 | * 数据绑定接口 5 | * @author Administrator 6 | */ 7 | public interface DataBinder { 8 | /** 9 | * 绑定操作 10 | * @param ctx 绑定上下文 11 | * @return 转换后的对象 12 | * @throws Exception 13 | */ 14 | public Object bind(BindingContext ctx) throws Exception; 15 | } 16 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/binding/binders/BigDecimalBinder.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.binding.binders; 2 | 3 | import com.et.mvc.binding.BindingContext; 4 | import com.et.mvc.binding.DataBinder; 5 | import com.et.mvc.binding.DataBinders; 6 | 7 | public class BigDecimalBinder implements DataBinder{ 8 | public Object bind(BindingContext ctx) throws Exception{ 9 | String parameterName = ctx.getParameterName(); 10 | if (!ctx.getPrefix().equals("")){ 11 | parameterName = ctx.getPrefix() + "." + parameterName; 12 | } 13 | String value = ctx.getRequest().getParameter(parameterName); 14 | if (value == null){ 15 | return null; 16 | } 17 | else{ 18 | if (DataBinders.isAllowEmpty() && value.equals("")) { 19 | return null; 20 | } 21 | return new java.math.BigDecimal(value); 22 | } 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/binding/binders/BigIntegerBinder.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.binding.binders; 2 | 3 | import com.et.mvc.binding.BindingContext; 4 | import com.et.mvc.binding.DataBinder; 5 | import com.et.mvc.binding.DataBinders; 6 | 7 | public class BigIntegerBinder implements DataBinder{ 8 | public Object bind(BindingContext ctx) throws Exception{ 9 | String parameterName = ctx.getParameterName(); 10 | if (!ctx.getPrefix().equals("")){ 11 | parameterName = ctx.getPrefix() + "." + parameterName; 12 | } 13 | 14 | String value = ctx.getRequest().getParameter(parameterName); 15 | if (value == null){ 16 | return null; 17 | } 18 | else{ 19 | if (DataBinders.isAllowEmpty() && value.equals("")) { 20 | return null; 21 | } 22 | return new java.math.BigInteger(value); 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/binding/binders/BooleanArrayBinder.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.binding.binders; 2 | 3 | import com.et.mvc.binding.BindingContext; 4 | import com.et.mvc.binding.DataBinder; 5 | import com.et.mvc.binding.DataBinders; 6 | 7 | public class BooleanArrayBinder implements DataBinder{ 8 | 9 | public Object bind(BindingContext ctx) throws Exception { 10 | String parameterName = ctx.getParameterName(); 11 | if (!ctx.getPrefix().equals("")) { 12 | parameterName = ctx.getPrefix() + "." + parameterName; 13 | } 14 | 15 | String[] values = (String[])ctx.getRequest().getParameterMap().get(parameterName); 16 | if (values == null){ 17 | return null; 18 | } else if (ctx.getParameterType().equals(boolean[].class)){ 19 | boolean[] aa = new boolean[values.length]; 20 | for(int i=0; i execute(); 18 | String[] except() default {}; 19 | String[] only() default {}; 20 | } 21 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/filter/AroundFilters.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.filter; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /** 10 | * 多环绕过滤器注解 11 | * @author stworthy 12 | */ 13 | @Target({ElementType.TYPE}) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Documented 16 | public @interface AroundFilters { 17 | AroundFilter[] value() default {}; 18 | } 19 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/filter/AroundHandler.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.filter; 2 | 3 | import com.et.mvc.Controller; 4 | 5 | /** 6 | * 环绕过滤器接口 7 | * @author stworthy 8 | */ 9 | public interface AroundHandler { 10 | /** 11 | * 控制器执行前 12 | * @param controller 控制器 13 | * @return 返回true继续执行,返回false中断执行 14 | * @throws Exception 15 | */ 16 | public boolean before(Controller controller) throws Exception; 17 | 18 | /** 19 | * 控制器执行后 20 | * @param controller 控制器 21 | * @return 返回true继续执行,返回false中断执行 22 | * @throws Exception 23 | */ 24 | public boolean after(Controller controller) throws Exception; 25 | } 26 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/filter/BeforeFilter.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.filter; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /** 10 | * 单前置过滤器注解 11 | * @author stworthy 12 | */ 13 | @Target({ElementType.TYPE}) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Documented 16 | public @interface BeforeFilter { 17 | String execute(); 18 | String[] except() default {}; 19 | String[] only() default {}; 20 | } 21 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/filter/BeforeFilters.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.filter; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /** 10 | * 多前置过滤器注解 11 | * @author stworthy 12 | */ 13 | @Target({ElementType.TYPE}) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Documented 16 | public @interface BeforeFilters { 17 | BeforeFilter[] value() default {}; 18 | } 19 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/renderer/AbstractViewRenderer.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.renderer; 2 | 3 | import com.et.mvc.ViewContext; 4 | import com.et.mvc.ViewRenderer; 5 | 6 | public abstract class AbstractViewRenderer implements ViewRenderer{ 7 | public void render(T viewObject, ViewContext viewContext) throws Exception{ 8 | if (viewContext.getResponse().isCommitted() == true){ 9 | return; 10 | } 11 | renderView(viewObject, viewContext); 12 | } 13 | 14 | protected abstract void renderView(T viewObject, ViewContext viewContext) throws Exception; 15 | } 16 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/renderer/BinaryViewRenderer.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.renderer; 2 | 3 | import com.et.mvc.BinaryView; 4 | import com.et.mvc.ViewContext; 5 | import java.io.OutputStream; 6 | import javax.servlet.http.HttpServletResponse; 7 | 8 | public class BinaryViewRenderer extends AbstractViewRenderer{ 9 | public void renderView(BinaryView view, ViewContext viewContext) throws Exception{ 10 | if (view == null){ 11 | return; 12 | } 13 | 14 | HttpServletResponse response = viewContext.getResponse(); 15 | response.setContentType(view.getContentType()); 16 | response.setContentLength(view.getData().length); 17 | if (view.getFileName() == null){ 18 | response.setHeader("Content-Disposition", view.getContentDisposition()); 19 | } 20 | else{ 21 | String filename = new String(view.getFileName().getBytes("GBK"), "ISO8859_1"); 22 | response.setHeader("Content-Disposition", view.getContentDisposition()+";filename="+filename); 23 | } 24 | OutputStream out = response.getOutputStream(); 25 | out.write(view.getData()); 26 | out.close(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/renderer/JsonViewRenderer.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.renderer; 2 | 3 | import com.et.mvc.JsonView; 4 | import com.et.mvc.ViewContext; 5 | import java.io.PrintWriter; 6 | import javax.servlet.http.HttpServletResponse; 7 | 8 | public class JsonViewRenderer extends AbstractViewRenderer{ 9 | public void renderView(JsonView view, ViewContext viewContext) throws Exception{ 10 | if (view == null){ 11 | return; 12 | } 13 | 14 | HttpServletResponse response = viewContext.getResponse(); 15 | if (view.getContentType() != null){ 16 | response.setContentType(view.getContentType()); 17 | } 18 | else{ 19 | response.setContentType("application/json;charset=utf-8"); 20 | } 21 | PrintWriter out = response.getWriter(); 22 | out.print(view.toString()); 23 | out.close(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/renderer/StringViewRenderer.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.renderer; 2 | 3 | import com.et.mvc.ViewContext; 4 | import java.io.PrintWriter; 5 | 6 | public class StringViewRenderer extends AbstractViewRenderer{ 7 | public void renderView(String view, ViewContext viewContext) throws Exception{ 8 | if (view == null){ 9 | return; 10 | } 11 | PrintWriter out = viewContext.getResponse().getWriter(); 12 | out.print(view); 13 | out.close(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/renderer/TextViewRenderer.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.renderer; 2 | 3 | import com.et.mvc.TextView; 4 | import com.et.mvc.ViewContext; 5 | import java.io.PrintWriter; 6 | import javax.servlet.http.HttpServletResponse; 7 | 8 | public class TextViewRenderer extends AbstractViewRenderer{ 9 | public void renderView(TextView view, ViewContext viewContext) throws Exception{ 10 | if (view == null){ 11 | return; 12 | } 13 | 14 | HttpServletResponse response = viewContext.getResponse(); 15 | if (view.getContentType() != null){ 16 | response.setContentType(view.getContentType()); 17 | } 18 | PrintWriter out = response.getWriter(); 19 | out.print(view.toString()); 20 | out.close(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/renderer/VoidViewRenderer.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.renderer; 2 | 3 | import com.et.mvc.ViewContext; 4 | import javax.servlet.RequestDispatcher; 5 | 6 | public class VoidViewRenderer extends AbstractViewRenderer{ 7 | public void renderView(Void viewObject, ViewContext viewContext) throws Exception{ 8 | String path = viewContext.getViewBasePath() + viewContext.getControllerPath().toLowerCase() + "/" + viewContext.getActionName() + ".jsp"; 9 | RequestDispatcher rd = viewContext.getRequest().getRequestDispatcher(path); 10 | rd.forward(viewContext.getRequest(), viewContext.getResponse()); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/routing/Route.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.routing; 2 | 3 | /** 4 | * 路由定义,由默认路由处理器处理 5 | * @author stworthy 6 | */ 7 | public class Route { 8 | private String url; 9 | private String controller; 10 | private String action; 11 | private Class handlerClass; 12 | 13 | public Route(String url, Class handlerClass){ 14 | this.url = url; 15 | this.handlerClass = handlerClass; 16 | } 17 | 18 | public Route(String url, String controller, Class handlerClass){ 19 | this.url = url; 20 | this.controller = controller; 21 | this.handlerClass = handlerClass; 22 | } 23 | 24 | public Route(String url, String controller, String action, Class handlerClass){ 25 | this.url = url; 26 | this.controller = controller; 27 | this.action = action; 28 | this.handlerClass = handlerClass; 29 | } 30 | 31 | public String getUrl() { 32 | return url; 33 | } 34 | 35 | public void setUrl(String url) { 36 | this.url = url; 37 | } 38 | 39 | public Class getHandlerClass() { 40 | return handlerClass; 41 | } 42 | 43 | public void setHandlerClass(Class handlerClass) { 44 | this.handlerClass = handlerClass; 45 | } 46 | 47 | public String getController() { 48 | return controller; 49 | } 50 | 51 | public void setController(String controller) { 52 | this.controller = controller; 53 | } 54 | 55 | public String getAction() { 56 | return action; 57 | } 58 | 59 | public void setAction(String action) { 60 | this.action = action; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/routing/RouteHandler.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.routing; 2 | 3 | import com.et.mvc.RequestContext; 4 | 5 | /** 6 | * 路由处理接口 7 | * @author stworthy 8 | */ 9 | public interface RouteHandler { 10 | /** 11 | * 获取路由选择结果 12 | * @param requestContext 请求上下文 13 | * @param route 路由定义 14 | * @return 路由选择结果 15 | */ 16 | public RouteResult getResult(RequestContext requestContext, Route route); 17 | } 18 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/routing/RouteResult.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.routing; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * 路由选择结果 8 | * @author stworthy 9 | */ 10 | public class RouteResult { 11 | private String subPackageName; 12 | private String controllerPath; 13 | private String controllerName; 14 | private String actionName; 15 | private Map params = new HashMap(); 16 | 17 | public String getSubPackageName() { 18 | return subPackageName; 19 | } 20 | 21 | public void setSubPackageName(String subPackageName) { 22 | this.subPackageName = subPackageName; 23 | } 24 | 25 | public String getControllerName() { 26 | return controllerName; 27 | } 28 | 29 | public void setControllerName(String controllerName) { 30 | this.controllerName = controllerName; 31 | } 32 | 33 | public String getActionName() { 34 | return actionName; 35 | } 36 | 37 | public void setActionName(String actionName) { 38 | this.actionName = actionName; 39 | } 40 | 41 | public String getControllerPath() { 42 | return controllerPath; 43 | } 44 | 45 | public void setControllerPath(String controllerPath) { 46 | this.controllerPath = controllerPath; 47 | } 48 | 49 | public Map getParams() { 50 | return params; 51 | } 52 | 53 | public void setParams(Map params) { 54 | this.params = params; 55 | } 56 | 57 | 58 | } 59 | -------------------------------------------------------------------------------- /Source/ etmvc shuzheng/et-mvc/src/com/et/mvc/routing/RouteTable.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.routing; 2 | 3 | import com.et.mvc.RequestContext; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | /** 8 | * 路由表管理类 9 | * @author stworthy 10 | */ 11 | public class RouteTable { 12 | private static List routes = new ArrayList(); 13 | 14 | static{ 15 | Route defaultRoute = new Route("$controller/$action/$id", DefaultRouteHandler.class); 16 | routes.add(defaultRoute); 17 | } 18 | 19 | public static RouteResult selectRoute(RequestContext requestContext) throws Exception{ 20 | for(Route route: routes){ 21 | RouteHandler handler = (RouteHandler)route.getHandlerClass().newInstance(); 22 | RouteResult result = handler.getResult(requestContext, route); 23 | if (result != null){ 24 | return result; 25 | } 26 | } 27 | return null; 28 | } 29 | 30 | public static List getRoutes() { 31 | return routes; 32 | } 33 | 34 | public static void addRoute(Route route){ 35 | routes.add(route); 36 | } 37 | 38 | public static void addRoute(int pos, Route route){ 39 | routes.add(pos, route); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | et-ar 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | #Mon Jul 06 10:04:40 CST 2009 2 | eclipse.preferences.version=1 3 | encoding/=UTF-8 4 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Mon Jul 06 10:04:42 CST 2009 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.5 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.source=1.5 13 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/README.txt: -------------------------------------------------------------------------------- 1 | 致etmvc框架用户: 2 | 3 | 非常感谢您选择etmvc,相信她会为您的开发工作带来便利。 4 | 为了您更好地使用etmvc,请您参阅在线文档http://www.etmvc.cn/tutorial/index。 5 | 欢迎访问我们的网站:http://www.etmvc.cn。 6 | 欢迎提宝贵意见和建议。 7 | 8 | Copyright 2009 junxian she 9 | junxian she 10 | http://www.etmvc.cn 11 | 12 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/lib/asm.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuzheng/etmvc/9eff387121679b67a281ee114f051cb0e470befb/Source/ etmvc stworthy/et-ar/lib/asm.jar -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/lib/cglib-2.1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuzheng/etmvc/9eff387121679b67a281ee114f051cb0e470befb/Source/ etmvc stworthy/et-ar/lib/cglib-2.1.3.jar -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/lib/commons-logging.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuzheng/etmvc/9eff387121679b67a281ee114f051cb0e470befb/Source/ etmvc stworthy/et-ar/lib/commons-logging.jar -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/ConnectionFactoryBean.java: -------------------------------------------------------------------------------- 1 | package com.et.ar; 2 | 3 | import com.et.ar.adapters.Adapter; 4 | import com.et.ar.connections.DataSourceConnectionProvider; 5 | import javax.sql.DataSource; 6 | 7 | public class ConnectionFactoryBean { 8 | private String domainBaseClass; 9 | private String adapterClass; 10 | private DataSource dataSource; 11 | 12 | public String getDomainBaseClass() { 13 | return domainBaseClass; 14 | } 15 | 16 | public void setDomainBaseClass(String domainBaseClass) { 17 | this.domainBaseClass = domainBaseClass; 18 | init(); 19 | } 20 | 21 | public DataSource getDataSource() { 22 | return dataSource; 23 | } 24 | 25 | public void setDataSource(DataSource dataSource) { 26 | this.dataSource = dataSource; 27 | init(); 28 | } 29 | 30 | public String getAdapterClass() { 31 | return adapterClass; 32 | } 33 | 34 | public void setAdapterClass(String adapterClass) { 35 | this.adapterClass = adapterClass; 36 | init(); 37 | } 38 | 39 | private void init(){ 40 | if (domainBaseClass != null && dataSource != null){ 41 | DataSourceConnectionProvider cp = new DataSourceConnectionProvider(dataSource); 42 | ActiveRecordBase.putConnectionProvider(domainBaseClass, cp); 43 | // ActiveRecordBase.connections.put(domainBaseClass, cp); 44 | } 45 | if (domainBaseClass != null && adapterClass != null){ 46 | try{ 47 | Adapter adapter = (Adapter)Class.forName(adapterClass).newInstance(); 48 | ActiveRecordBase.putConnectionAdapter(domainBaseClass, adapter); 49 | // ActiveRecordBase.adapters.put(domainBaseClass, (Adapter)Class.forName(adapterClass).newInstance()); 50 | } 51 | catch(Exception e){ 52 | 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/ConnectionHolder.java: -------------------------------------------------------------------------------- 1 | package com.et.ar; 2 | 3 | import com.et.ar.connections.ConnectionProvider; 4 | import com.et.ar.exception.DataAccessException; 5 | import java.sql.Connection; 6 | import java.sql.SQLException; 7 | 8 | /** 9 | * 管理当前操作的数据库连接,使用连接的优先顺序如下: 10 | * 1、如果处于事务中,则使用事务的连接; 11 | * 2、如果连接有缓存,则使用缓存中的连接; 12 | * 3、以上都没有,则创建从连接池中取得新的连接。 13 | * @author stworthy 14 | */ 15 | public class ConnectionHolder { 16 | private Transaction transaction = null; 17 | private ConnectionProvider connectionProvider = null; 18 | private Connection con = null; 19 | 20 | public ConnectionHolder(Class c) throws DataAccessException { 21 | transaction = ActiveRecordBase.getCurrentTransaction(c); 22 | 23 | try{ 24 | if (transaction == null){ 25 | connectionProvider = ActiveRecordBase.getConnectionProvider(c); 26 | con = connectionProvider.getConnection(); 27 | } 28 | else{ 29 | con = transaction.getConnection(); 30 | } 31 | } 32 | catch(SQLException e){ 33 | throw new DataAccessException(e); 34 | } 35 | } 36 | 37 | public Connection getConnection() { 38 | return con; 39 | } 40 | 41 | public void close() throws DataAccessException{ 42 | try{ 43 | if (transaction == null){ 44 | connectionProvider.closeConnection(con); 45 | } 46 | } 47 | catch(SQLException e){ 48 | throw new DataAccessException(e); 49 | } 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/Converter.java: -------------------------------------------------------------------------------- 1 | package com.et.ar; 2 | 3 | /** 4 | * 数据转换接口 5 | * @author stworthy 6 | */ 7 | public interface Converter { 8 | /** 9 | * 进行转换操作 10 | * @param obj 原对象 11 | * @return 转换后对象 12 | */ 13 | public Object convert(Object obj); 14 | } 15 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/Transaction.java: -------------------------------------------------------------------------------- 1 | package com.et.ar; 2 | 3 | import com.et.ar.exception.TransactionException; 4 | import java.sql.Connection; 5 | import java.sql.SQLException; 6 | 7 | /** 8 | * 事务描述类 9 | * @author stworthy 10 | */ 11 | public class Transaction { 12 | private int level = 0; 13 | private Connection conn = null; 14 | 15 | public Transaction(Connection conn) throws TransactionException { 16 | this.conn = conn; 17 | try{ 18 | this.conn.setAutoCommit(false); 19 | } 20 | catch(SQLException e){ 21 | throw new TransactionException(e); 22 | } 23 | } 24 | 25 | public Connection getConnection(){ 26 | return conn; 27 | } 28 | 29 | public void beginTransaction() throws TransactionException{ 30 | level += 1; 31 | } 32 | 33 | public void commit() throws TransactionException{ 34 | try{ 35 | level -= 1; 36 | if (level == 0){ 37 | conn.commit(); 38 | conn.close(); 39 | } 40 | } 41 | catch(SQLException e){ 42 | throw new TransactionException(e); 43 | } 44 | } 45 | 46 | public void rollback() throws TransactionException{ 47 | try{ 48 | level -= 1; 49 | if (level == 0){ 50 | conn.rollback(); 51 | conn.close(); 52 | } 53 | } 54 | catch(SQLException e){ 55 | throw new TransactionException(e); 56 | } 57 | } 58 | 59 | public boolean isFinished(){ 60 | return level == 0; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/adapters/Adapter.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.adapters; 2 | 3 | public abstract class Adapter { 4 | public abstract String getAdapterName(); 5 | public abstract String getLimitString(String sql, int limit, int offset); 6 | public abstract boolean supportsLimitOffset(); 7 | public abstract String getIdentitySelectString(); 8 | public abstract String getSequenceNextValString(String sequenceName); 9 | } 10 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/adapters/DB2Adapter.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.adapters; 2 | 3 | public class DB2Adapter extends Adapter { 4 | 5 | public String getAdapterName() { 6 | return "db2"; 7 | } 8 | 9 | public String getLimitString(String sql, int limit, int offset) { 10 | return sql + " fetch first " + Integer.toString(offset + limit) 11 | + " rows only"; 12 | } 13 | 14 | public boolean supportsLimitOffset() { 15 | return false; 16 | } 17 | 18 | public String getIdentitySelectString() { 19 | return "VALUES IDENTITY_VAL_LOCAL()"; 20 | } 21 | 22 | public String getSequenceNextValString(String sequenceName) { 23 | return null; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/adapters/MySqlAdapter.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.adapters; 2 | 3 | public class MySqlAdapter extends Adapter{ 4 | public String getAdapterName(){ 5 | return "mysql"; 6 | } 7 | 8 | public String getLimitString(String sql, int limit, int offset){ 9 | if (offset == 0){ 10 | return sql + " limit " + Integer.toString(limit); 11 | } 12 | else{ 13 | return sql + " limit " + Integer.toString(offset) + "," + Integer.toString(limit); 14 | } 15 | } 16 | 17 | public boolean supportsLimitOffset(){ 18 | return true; 19 | } 20 | 21 | public String getIdentitySelectString(){ 22 | return "select last_insert_id()"; 23 | } 24 | 25 | public String getSequenceNextValString(String sequenceName){ 26 | return null; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/adapters/OracleAdapter.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.adapters; 2 | 3 | public class OracleAdapter extends Adapter{ 4 | public String getAdapterName(){ 5 | return "oracle"; 6 | } 7 | 8 | public String getLimitString(String sql, int limit, int offset){ 9 | StringBuffer pagingSelect = new StringBuffer(sql.length()+100); 10 | if (offset == 0){ 11 | pagingSelect.append("select * from ( "); 12 | pagingSelect.append(sql); 13 | pagingSelect.append(" ) where rownum <= " + Integer.toString(limit)); 14 | } 15 | else{ 16 | pagingSelect.append("select * from ( select row_.*, rownum rownum_ from ( "); 17 | pagingSelect.append(sql); 18 | pagingSelect.append(" ) row_ ) where rownum_ <= "+Integer.toString(limit+offset)+" and rownum_ > "+Integer.toString(offset)); 19 | } 20 | return pagingSelect.toString(); 21 | } 22 | 23 | public boolean supportsLimitOffset(){ 24 | return true; 25 | } 26 | 27 | public String getIdentitySelectString(){ 28 | return null; 29 | } 30 | 31 | public String getSequenceNextValString(String sequenceName){ 32 | return "select " + sequenceName + ".nextval from dual"; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/adapters/SqlServerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.adapters; 2 | 3 | public class SqlServerAdapter extends Adapter{ 4 | public String getAdapterName(){ 5 | return "sqlserver"; 6 | } 7 | 8 | public String getLimitString(String sql, int limit, int offset){ 9 | if (sql.toLowerCase().startsWith("select distinct")){ 10 | return "select distinct top " + Integer.toString(limit+offset) + sql.substring("select distinct".length()); 11 | } 12 | else{ 13 | return "select top " + Integer.toString(limit+offset) + sql.substring("select".length()); 14 | } 15 | } 16 | 17 | public boolean supportsLimitOffset(){ 18 | return false; 19 | } 20 | 21 | public String getIdentitySelectString(){ 22 | return "SELECT @@IDENTITY"; 23 | // return "select scope_identity()"; 24 | } 25 | 26 | public String getSequenceNextValString(String sequenceName){ 27 | return null; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/adapters/SqliteAdapter.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.adapters; 2 | 3 | public class SqliteAdapter extends Adapter{ 4 | public String getAdapterName(){ 5 | return "sqlite"; 6 | } 7 | 8 | public String getLimitString(String sql, int limit, int offset){ 9 | if (offset == 0){ 10 | return sql + " limit " + Integer.toString(limit); 11 | } 12 | else{ 13 | return sql + " limit " + Integer.toString(offset) + "," + Integer.toString(limit); 14 | } 15 | } 16 | 17 | public boolean supportsLimitOffset(){ 18 | return true; 19 | } 20 | 21 | public String getIdentitySelectString(){ 22 | return "select last_insert_rowid()"; 23 | } 24 | 25 | public String getSequenceNextValString(String sequenceName){ 26 | return null; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/annotations/BelongsTo.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.annotations; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | @Target({ElementType.FIELD,ElementType.METHOD}) 10 | @Retention(RetentionPolicy.RUNTIME) 11 | @Documented 12 | public @interface BelongsTo { 13 | String foreignKey() default ""; 14 | } 15 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/annotations/Column.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.annotations; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | 10 | @Target({ElementType.FIELD,ElementType.METHOD}) 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Documented 13 | public @interface Column { 14 | } 15 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/annotations/DependentType.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.annotations; 2 | 3 | public enum DependentType { 4 | DESTROY, 5 | DELETE, 6 | NULLIFY 7 | } 8 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/annotations/Email.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.annotations; 2 | 3 | import com.et.ar.validators.EmailValidator; 4 | import java.lang.annotation.Documented; 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | @ValidatorClass(EmailValidator.class) 11 | @Target({ElementType.FIELD,ElementType.METHOD}) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Documented 14 | public @interface Email { 15 | String message() default "非法电子邮件格式"; 16 | } 17 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/annotations/GeneratorType.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.annotations; 2 | 3 | public enum GeneratorType { 4 | SEQUENCE, 5 | IDENTITY, 6 | AUTO, 7 | NONE 8 | } 9 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/annotations/HasMany.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.annotations; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | @Target({ElementType.FIELD,ElementType.METHOD}) 10 | @Retention(RetentionPolicy.RUNTIME) 11 | @Documented 12 | public @interface HasMany { 13 | String foreignKey() default ""; 14 | DependentType dependent() default DependentType.NULLIFY; 15 | String order() default ""; 16 | } 17 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/annotations/HasOne.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.annotations; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | @Target({ElementType.FIELD,ElementType.METHOD}) 10 | @Retention(RetentionPolicy.RUNTIME) 11 | @Documented 12 | public @interface HasOne { 13 | String foreignKey() default ""; 14 | DependentType dependent() default DependentType.NULLIFY; 15 | String order() default ""; 16 | } 17 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/annotations/Id.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.annotations; 2 | 3 | import java.lang.annotation.*; 4 | 5 | @Target({ElementType.FIELD,ElementType.METHOD}) 6 | @Retention(RetentionPolicy.RUNTIME) 7 | @Documented 8 | public @interface Id { 9 | GeneratorType generate() default GeneratorType.AUTO; 10 | } 11 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/annotations/Length.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.annotations; 2 | 3 | import com.et.ar.validators.LengthValidator; 4 | import java.lang.annotation.*; 5 | 6 | @ValidatorClass(LengthValidator.class) 7 | @Target({ElementType.FIELD,ElementType.METHOD}) 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Documented 10 | public @interface Length{ 11 | int min() default 0; 12 | int max(); 13 | String message(); 14 | } 15 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/annotations/NotEmpty.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.annotations; 2 | 3 | import com.et.ar.validators.NotEmptyValidator; 4 | import java.lang.annotation.Documented; 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | @ValidatorClass(NotEmptyValidator.class) 11 | @Target({ElementType.FIELD,ElementType.METHOD}) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Documented 14 | public @interface NotEmpty { 15 | String message() default "字段内容不能为空"; 16 | } 17 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/annotations/Pattern.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.annotations; 2 | 3 | import com.et.ar.validators.PatternValidator; 4 | import java.lang.annotation.*; 5 | 6 | @ValidatorClass(PatternValidator.class) 7 | @Target({ElementType.FIELD,ElementType.METHOD}) 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Documented 10 | public @interface Pattern { 11 | String regex(); 12 | String message() default "模式匹配错误"; 13 | } 14 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/annotations/Table.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.annotations; 2 | 3 | import java.lang.annotation.*; 4 | 5 | @Target({ElementType.TYPE}) 6 | @Retention(RetentionPolicy.RUNTIME) 7 | @Documented 8 | public @interface Table { 9 | String name(); 10 | } 11 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/annotations/Unique.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.annotations; 2 | 3 | import java.lang.annotation.*; 4 | 5 | @Target({ElementType.FIELD,ElementType.METHOD}) 6 | @Retention(RetentionPolicy.RUNTIME) 7 | @Documented 8 | public @interface Unique { 9 | String message(); 10 | } 11 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/annotations/ValidatorClass.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.annotations; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | @Target({ElementType.ANNOTATION_TYPE}) 10 | @Retention(RetentionPolicy.RUNTIME) 11 | @Documented 12 | public @interface ValidatorClass { 13 | Class value(); 14 | } 15 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/connections/ConnectionProvider.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.connections; 2 | 3 | import java.sql.*; 4 | 5 | public interface ConnectionProvider { 6 | public Connection getConnection() throws SQLException; 7 | 8 | public void closeConnection(Connection conn) throws SQLException; 9 | 10 | public void close() throws SQLException; 11 | } 12 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/connections/DataSourceConnectionProvider.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.connections; 2 | 3 | import java.sql.Connection; 4 | import java.sql.SQLException; 5 | import javax.sql.DataSource; 6 | 7 | public class DataSourceConnectionProvider implements ConnectionProvider{ 8 | private DataSource ds; 9 | 10 | public DataSourceConnectionProvider(DataSource ds){ 11 | this.ds = ds; 12 | } 13 | 14 | public Connection getConnection() throws SQLException{ 15 | return ds.getConnection(); 16 | } 17 | 18 | public void closeConnection(Connection con) throws SQLException{ 19 | con.close(); 20 | } 21 | 22 | public void close() throws SQLException{ 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/exception/ActiveRecordException.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.exception; 2 | 3 | /** 4 | * 活动记录操作异常基类 5 | * @author stworthy 6 | * 7 | */ 8 | public class ActiveRecordException extends Exception{ 9 | /** 10 | * 11 | */ 12 | private static final long serialVersionUID = 1L; 13 | 14 | public ActiveRecordException(String s){ 15 | super(s); 16 | } 17 | 18 | public ActiveRecordException(String s, Throwable root){ 19 | super(s, root); 20 | } 21 | 22 | public ActiveRecordException(Throwable root){ 23 | super(root); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/exception/DataAccessException.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.exception; 2 | 3 | import java.sql.SQLException; 4 | 5 | /** 6 | * 数据访问异常类 7 | * @author stworthy 8 | * 9 | */ 10 | public class DataAccessException extends ActiveRecordException{ 11 | /** 12 | * 13 | */ 14 | private static final long serialVersionUID = 1L; 15 | 16 | public DataAccessException(String s, SQLException root){ 17 | super(s, root); 18 | } 19 | 20 | public DataAccessException(SQLException root){ 21 | super(root); 22 | } 23 | // 24 | // public DataAccessException(Exception root){ 25 | // super(root); 26 | // } 27 | } 28 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/exception/FieldAccessException.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.exception; 2 | 3 | /** 4 | * 对象字段访问异常类 5 | * @author stworthy 6 | */ 7 | public class FieldAccessException extends ActiveRecordException{ 8 | /** 9 | * 10 | */ 11 | private static final long serialVersionUID = 1L; 12 | 13 | public FieldAccessException(String s){ 14 | super(s); 15 | } 16 | 17 | public FieldAccessException(String s, Throwable root){ 18 | super(s, root); 19 | } 20 | 21 | public FieldAccessException(Throwable root){ 22 | super(root); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/exception/TransactionException.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.exception; 2 | 3 | /** 4 | * 事务操作异常类 5 | * @author stworthy 6 | */ 7 | public class TransactionException extends ActiveRecordException{ 8 | /** 9 | * 10 | */ 11 | private static final long serialVersionUID = 1L; 12 | 13 | public TransactionException(String s){ 14 | super(s); 15 | } 16 | 17 | public TransactionException(String s, Throwable root){ 18 | super(s, root); 19 | } 20 | 21 | public TransactionException(Throwable root){ 22 | super(root); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/exception/ValidateException.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.exception; 2 | 3 | /** 4 | * 数据验证异常类 5 | * @author stworthy 6 | */ 7 | public class ValidateException extends ActiveRecordException{ 8 | /** 9 | * 10 | */ 11 | private static final long serialVersionUID = 1L; 12 | 13 | public ValidateException(String s){ 14 | super(s); 15 | } 16 | 17 | public ValidateException(String s, Throwable root){ 18 | super(s, root); 19 | } 20 | 21 | public ValidateException(Throwable root){ 22 | super(root); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/orm/BelongsToField.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.orm; 2 | 3 | import com.et.ar.annotations.BelongsTo; 4 | 5 | public class BelongsToField { 6 | private String name; 7 | private BelongsTo annotation; 8 | private Class targetType; 9 | private String foreignKey; 10 | 11 | public String getName() { 12 | return name; 13 | } 14 | 15 | public void setName(String name) { 16 | this.name = name; 17 | } 18 | 19 | public BelongsTo getAnnotation() { 20 | return annotation; 21 | } 22 | 23 | public void setAnnotation(BelongsTo annotation) { 24 | this.annotation = annotation; 25 | } 26 | 27 | public Class getTargetType() { 28 | return targetType; 29 | } 30 | 31 | public void setTargetType(Class targetType) { 32 | this.targetType = targetType; 33 | } 34 | 35 | public String getForeignKey() { 36 | return foreignKey; 37 | } 38 | 39 | public void setForeignKey(String foreignKey) { 40 | this.foreignKey = foreignKey; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/orm/ColumnField.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.orm; 2 | 3 | public class ColumnField { 4 | private String name; 5 | private Class type; 6 | 7 | public String getName() { 8 | return name; 9 | } 10 | 11 | public void setName(String name) { 12 | this.name = name; 13 | } 14 | 15 | public Class getType() { 16 | return type; 17 | } 18 | 19 | public void setType(Class type) { 20 | this.type = type; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/orm/HasManyField.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.orm; 2 | 3 | import com.et.ar.annotations.HasMany; 4 | 5 | public class HasManyField { 6 | private String name; 7 | private HasMany annotation; 8 | private Class targetType; 9 | private String foreignKey; 10 | 11 | public String getName() { 12 | return name; 13 | } 14 | 15 | public void setName(String name) { 16 | this.name = name; 17 | } 18 | 19 | public HasMany getAnnotation() { 20 | return annotation; 21 | } 22 | 23 | public void setAnnotation(HasMany annotation) { 24 | this.annotation = annotation; 25 | } 26 | 27 | public Class getTargetType() { 28 | return targetType; 29 | } 30 | 31 | public void setTargetType(Class targetType) { 32 | this.targetType = targetType; 33 | } 34 | 35 | public String getForeignKey() { 36 | return foreignKey; 37 | } 38 | 39 | public void setForeignKey(String foreignKey) { 40 | this.foreignKey = foreignKey; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/orm/HasOneField.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.orm; 2 | 3 | import com.et.ar.annotations.HasOne; 4 | 5 | public class HasOneField { 6 | private String name; 7 | private HasOne annotation; 8 | private Class targetType; 9 | private String foreignKey; 10 | 11 | public String getName() { 12 | return name; 13 | } 14 | 15 | public void setName(String name) { 16 | this.name = name; 17 | } 18 | 19 | public HasOne getAnnotation() { 20 | return annotation; 21 | } 22 | 23 | public void setAnnotation(HasOne annotation) { 24 | this.annotation = annotation; 25 | } 26 | 27 | public Class getTargetType() { 28 | return targetType; 29 | } 30 | 31 | public void setTargetType(Class targetType) { 32 | this.targetType = targetType; 33 | } 34 | 35 | public String getForeignKey() { 36 | return foreignKey; 37 | } 38 | 39 | public void setForeignKey(String foreignKey) { 40 | this.foreignKey = foreignKey; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/validators/EmailValidator.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.validators; 2 | 3 | import com.et.ar.annotations.Email; 4 | 5 | /** 6 | * 电子邮件验证类 7 | * @author stworthy 8 | */ 9 | public class EmailValidator extends AbstractValidator{ 10 | public boolean validate(Object value) { 11 | String parten = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}" + 12 | "\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\" + 13 | ".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"; 14 | String s = (String)value; 15 | if (s == null){ 16 | s = ""; 17 | } 18 | if (s.matches(parten) == false){ 19 | return false; 20 | } 21 | return true; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/validators/LengthValidator.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.validators; 2 | 3 | import com.et.ar.annotations.Length; 4 | 5 | /** 6 | * 长度验证类 7 | * @author stworthy 8 | */ 9 | public class LengthValidator extends AbstractValidator{ 10 | public boolean validate(Object value) { 11 | String s = (String)value; 12 | if (s == null){ 13 | s = ""; 14 | } 15 | if (s.length() < parameters.min() || s.length() > parameters.max()){ 16 | return false; 17 | } 18 | else{ 19 | return true; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/validators/NotEmptyValidator.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.validators; 2 | 3 | import com.et.ar.annotations.NotEmpty; 4 | 5 | /** 6 | * 数据非空验证类 7 | * @author stworthy 8 | */ 9 | public class NotEmptyValidator extends AbstractValidator{ 10 | public boolean validate(Object value) { 11 | if (value == null){ 12 | return false; 13 | } 14 | if (value instanceof String){ 15 | String s = (String)value; 16 | if (s.length() == 0){ 17 | return false; 18 | } 19 | } 20 | return true; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/validators/PatternValidator.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.validators; 2 | 3 | import com.et.ar.annotations.Pattern; 4 | 5 | 6 | /** 7 | * 模式匹配验证类 8 | * @author stworthy 9 | */ 10 | public class PatternValidator extends AbstractValidator{ 11 | public boolean validate(Object value){ 12 | String s = (String)value; 13 | if (s == null){ 14 | s = ""; 15 | } 16 | if (!s.matches(parameters.regex())){ 17 | return false; 18 | } 19 | else{ 20 | return true; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/validators/UniqueCreateValidator.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.validators; 2 | 3 | import com.et.ar.ActiveRecordBase; 4 | import com.et.ar.exception.ValidateException; 5 | import com.et.ar.annotations.Unique; 6 | 7 | /** 8 | * 数据创建唯一性验证类 9 | * @author stworthy 10 | */ 11 | public class UniqueCreateValidator extends AbstractValidator{ 12 | private Class c; 13 | private String tableName; 14 | private String fieldName; 15 | 16 | public UniqueCreateValidator(Class c, String tableName, String fieldName, Unique parameters){ 17 | super.init(parameters); 18 | this.c = c; 19 | this.tableName = tableName; 20 | this.fieldName = fieldName; 21 | } 22 | 23 | public boolean validate(Object value) throws ValidateException{ 24 | try{ 25 | String sql = "select count(*) from "+tableName+" where "+fieldName+"=?"; 26 | Object[] args = new Object[]{value}; 27 | Object count = ActiveRecordBase.executeScalar(c, sql, args); 28 | if (Integer.parseInt(count.toString()) > 0){ 29 | return false; 30 | } 31 | else{ 32 | return true; 33 | } 34 | } 35 | catch(Exception e){ 36 | throw new ValidateException(e); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-ar/src/com/et/ar/validators/UniqueUpdateValidator.java: -------------------------------------------------------------------------------- 1 | package com.et.ar.validators; 2 | 3 | import com.et.ar.ActiveRecordBase; 4 | import com.et.ar.exception.ValidateException; 5 | import com.et.ar.annotations.Unique; 6 | 7 | /** 8 | * 数据更新时唯一性验证类 9 | * @author stworthy 10 | */ 11 | public class UniqueUpdateValidator extends AbstractValidator{ 12 | private Class c; 13 | private String tableName; 14 | private String fieldName; 15 | private String fieldId; 16 | private Object idValue; 17 | 18 | public UniqueUpdateValidator(Class c, String tableName, String fieldName, String fieldId, Object idValue, Unique parameters){ 19 | super.init(parameters); 20 | this.c = c; 21 | this.tableName = tableName; 22 | this.fieldName = fieldName; 23 | this.fieldId = fieldId; 24 | this.idValue = idValue; 25 | } 26 | 27 | public boolean validate(Object value) throws ValidateException{ 28 | try{ 29 | String sql = "select count(*) from "+tableName+" where "+fieldName+"=? and "+fieldId+"<>?"; 30 | Object[] args = new Object[]{value,idValue}; 31 | Object count = ActiveRecordBase.executeScalar(c, sql, args); 32 | if (Integer.parseInt(count.toString()) > 0){ 33 | return false; 34 | } 35 | else{ 36 | return true; 37 | } 38 | } 39 | catch(Exception e){ 40 | throw new ValidateException(e); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | et-mvc 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | #Mon Jul 06 08:58:43 CST 2009 2 | eclipse.preferences.version=1 3 | encoding/=UTF-8 4 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Mon Jul 06 08:56:33 CST 2009 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.5 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.source=1.5 13 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/README.txt: -------------------------------------------------------------------------------- 1 | 致etmvc框架用户: 2 | 3 | 非常感谢您选择etmvc,相信她会为您的开发工作带来便利。 4 | 为了您更好地使用etmvc,请您参阅在线文档http://www.etmvc.cn/tutorial/index。 5 | 欢迎访问我们的网站:http://www.etmvc.cn。 6 | 欢迎提宝贵意见和建议。 7 | 8 | Copyright 2009 junxian she 9 | junxian she 10 | http://www.etmvc.cn 11 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/lib/commons-fileupload.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuzheng/etmvc/9eff387121679b67a281ee114f051cb0e470befb/Source/ etmvc stworthy/et-mvc/lib/commons-fileupload.jar -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/lib/commons-io.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuzheng/etmvc/9eff387121679b67a281ee114f051cb0e470befb/Source/ etmvc stworthy/et-mvc/lib/commons-io.jar -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/lib/commons-logging.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuzheng/etmvc/9eff387121679b67a281ee114f051cb0e470befb/Source/ etmvc stworthy/et-mvc/lib/commons-logging.jar -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/lib/freemarker.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuzheng/etmvc/9eff387121679b67a281ee114f051cb0e470befb/Source/ etmvc stworthy/et-mvc/lib/freemarker.jar -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/lib/paranamer-1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuzheng/etmvc/9eff387121679b67a281ee114f051cb0e470befb/Source/ etmvc stworthy/et-mvc/lib/paranamer-1.3.jar -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/lib/servlet-api.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuzheng/etmvc/9eff387121679b67a281ee114f051cb0e470befb/Source/ etmvc stworthy/et-mvc/lib/servlet-api.jar -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/lib/spring.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuzheng/etmvc/9eff387121679b67a281ee114f051cb0e470befb/Source/ etmvc stworthy/et-mvc/lib/spring.jar -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/Flash.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * 闪存类,用于在二次action操作中传递数据,传递后自动丢弃 8 | * @author stworthy 9 | */ 10 | public class Flash { 11 | public final static String FLASH_KEY = "flash_key"; 12 | 13 | private Map attr = new HashMap(); 14 | private Map keepAttr = new HashMap(); 15 | 16 | public void setAttribute(String key, Object value){ 17 | attr.put(key, value); 18 | } 19 | 20 | public Map getAttributes(){ 21 | return attr; 22 | } 23 | 24 | public Object getAttribute(String attributeName){ 25 | return attr.get(attributeName); 26 | } 27 | 28 | public void keep(){ 29 | keepAttr = attr; 30 | } 31 | 32 | public void keep(String key){ 33 | keepAttr.put(key, attr.get(key)); 34 | } 35 | 36 | protected void sweep(){ 37 | attr = keepAttr; 38 | keepAttr = new HashMap(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/FreeMarkerView.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc; 2 | 3 | import com.et.mvc.renderer.FreeMarkerViewRenderer; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | /** 8 | * 使用FreeMarker模板的视图类
9 | * 范例: 10 | *
11 |  * FreeMarkerView view = new FreeMarkerView();
12 |  * view.setAttribute("info", "...");
13 |  * return view;
14 |  * 
15 | * 或者: 16 | *
17 |  * request.setAttribute("info", "...");
18 |  * return new FreeMarkerView();
19 |  * 
20 | * @author stworthy 21 | */ 22 | @ViewRendererClass(FreeMarkerViewRenderer.class) 23 | public class FreeMarkerView extends View{ 24 | private String path; 25 | private Map attributes = new HashMap(); 26 | 27 | public FreeMarkerView(){ 28 | this.path = null; 29 | } 30 | 31 | public FreeMarkerView(String path){ 32 | this.path = path; 33 | } 34 | 35 | public FreeMarkerView(String path, String key, Object value){ 36 | this.path = path; 37 | this.setAttribute(key, value); 38 | } 39 | 40 | public FreeMarkerView(String key, Object value){ 41 | this.path = null; 42 | this.setAttribute(key, value); 43 | } 44 | 45 | public Map getAttributes() { 46 | return attributes; 47 | } 48 | 49 | public void setAttribute(String key, Object value){ 50 | attributes.put(key, value); 51 | } 52 | 53 | public String getPath() { 54 | return path; 55 | } 56 | 57 | public void setPath(String path) { 58 | this.path = path; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/JspView.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc; 2 | 3 | import com.et.mvc.renderer.JspViewRenderer; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | /** 8 | * 使用JSP的视图类 9 | *
10 |  * request.setAttribute("info","...");
11 |  * return new JspView("/user/show.jsp");
12 |  * 
13 | * 或者 14 | *
15 |  * JspView view = new JspView("/user/show.jsp");
16 |  * view.setAttribute("info","...");
17 |  * return view;
18 |  * 
19 | * @author stworthy 20 | */ 21 | @ViewRendererClass(JspViewRenderer.class) 22 | public class JspView extends View{ 23 | private String path; 24 | private Map attributes = new HashMap(); 25 | 26 | public JspView(){ 27 | this.path = null; 28 | } 29 | 30 | public JspView(String path){ 31 | this.path = path; 32 | } 33 | 34 | public JspView(String path, String key, Object value){ 35 | this.path = path; 36 | this.setAttribute(key, value); 37 | } 38 | 39 | public JspView(String key, Object value){ 40 | this.path = null; 41 | this.setAttribute(key, value); 42 | } 43 | 44 | public String getPath() { 45 | return path; 46 | } 47 | 48 | public void setPath(String path) { 49 | this.path = path; 50 | } 51 | 52 | public void setAttribute(String key, Object value){ 53 | attributes.put(key, value); 54 | } 55 | 56 | public Map getAttributes(){ 57 | return attributes; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/PlugIn.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc; 2 | 3 | /** 4 | * 插件接口 5 | * @author stworthy 6 | */ 7 | public interface PlugIn { 8 | /** 9 | * 插件初始化时执行的方法 10 | * @param context 插件上下文对象 11 | */ 12 | public void init(PlugInContext context); 13 | 14 | /** 15 | * 插件销毁时执行的方法 16 | */ 17 | public void destroy(); 18 | } 19 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/PlugInContext.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc; 2 | 3 | import java.util.Map; 4 | import javax.servlet.ServletContext; 5 | 6 | /** 7 | * 插件上下文类 8 | * @author stworthy 9 | */ 10 | public class PlugInContext { 11 | private ServletContext servletContext; 12 | private Map configParams; 13 | 14 | public ServletContext getServletContext() { 15 | return servletContext; 16 | } 17 | 18 | public void setServletContext(ServletContext servletContext) { 19 | this.servletContext = servletContext; 20 | } 21 | 22 | public Map getConfigParams() { 23 | return configParams; 24 | } 25 | 26 | public void setConfigParams(Map configParams) { 27 | this.configParams = configParams; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/RequestContext.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc; 2 | 3 | import java.util.List; 4 | import javax.servlet.http.HttpServletRequest; 5 | 6 | /** 7 | * 请求的上下文 8 | * @author stworthy 9 | */ 10 | public class RequestContext { 11 | private String controllerBasePackage; 12 | private List controllerPaths; 13 | private HttpServletRequest request; 14 | 15 | public String getControllerBasePackage() { 16 | return controllerBasePackage; 17 | } 18 | 19 | public void setControllerBasePackage(String controllerBasePackage) { 20 | this.controllerBasePackage = controllerBasePackage; 21 | } 22 | 23 | public List getControllerPaths() { 24 | return controllerPaths; 25 | } 26 | 27 | public void setControllerPaths(List controllerPaths) { 28 | this.controllerPaths = controllerPaths; 29 | } 30 | 31 | public HttpServletRequest getRequest() { 32 | return request; 33 | } 34 | 35 | public void setRequest(HttpServletRequest request) { 36 | this.request = request; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/SpringDispatcherFilter.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc; 2 | 3 | import javax.servlet.FilterConfig; 4 | import javax.servlet.ServletContext; 5 | import org.springframework.web.context.WebApplicationContext; 6 | import org.springframework.web.context.support.WebApplicationContextUtils; 7 | 8 | /** 9 | * 同spring集成的分发器 10 | * @author stworthy 11 | */ 12 | public class SpringDispatcherFilter extends DispatcherFilter{ 13 | private WebApplicationContext webApplicationContext; 14 | 15 | @Override 16 | public void init(FilterConfig config){ 17 | super.init(config); 18 | this.setWebApplicationContext(initWebApplicationContext(config.getServletContext())); 19 | } 20 | 21 | protected WebApplicationContext initWebApplicationContext(ServletContext servletContext){ 22 | return WebApplicationContextUtils.getWebApplicationContext(servletContext); 23 | } 24 | 25 | @Override 26 | public Object getController(String controllerClassName) throws Exception{ 27 | if (this.webApplicationContext.containsBean(controllerClassName)){ 28 | return this.webApplicationContext.getBean(controllerClassName); 29 | } 30 | else{ 31 | return super.getController(controllerClassName); 32 | } 33 | } 34 | 35 | public WebApplicationContext getWebApplicationContext() { 36 | return webApplicationContext; 37 | } 38 | 39 | public void setWebApplicationContext(WebApplicationContext webApplicationContext) { 40 | this.webApplicationContext = webApplicationContext; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/TextView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package com.et.mvc; 7 | 8 | import com.et.mvc.renderer.TextViewRenderer; 9 | 10 | /** 11 | * 文本视图,用于向浏览器返回一段文本 12 | * @author stworthy 13 | */ 14 | @ViewRendererClass(TextViewRenderer.class) 15 | public class TextView extends View{ 16 | private String text; 17 | 18 | public TextView(){ 19 | text = ""; 20 | } 21 | 22 | public TextView(String text){ 23 | this.text = text; 24 | } 25 | 26 | public TextView(String text, String contentType){ 27 | this.text = text; 28 | setContentType(contentType); 29 | } 30 | 31 | public String getText() { 32 | return text; 33 | } 34 | 35 | public void setText(String text) { 36 | this.text = text; 37 | } 38 | 39 | @Override 40 | public String toString(){ 41 | return text; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/View.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc; 2 | 3 | /** 4 | * 视图抽象类,建议所有的自定义视图类继承该类,但不是必须的 5 | * @author stworthy 6 | */ 7 | public abstract class View { 8 | private String contentType; 9 | private Class rendererClass = null; 10 | 11 | public String getContentType() { 12 | return contentType; 13 | } 14 | 15 | public void setContentType(String contentType) { 16 | this.contentType = contentType; 17 | } 18 | 19 | public void setRendererClass(Class rendererClass) { 20 | this.rendererClass = rendererClass; 21 | } 22 | 23 | public Class getRendererClass() { 24 | return rendererClass; 25 | } 26 | 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/ViewContext.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc; 2 | 3 | import javax.servlet.ServletContext; 4 | import javax.servlet.http.HttpServletRequest; 5 | import javax.servlet.http.HttpServletResponse; 6 | 7 | /** 8 | * 视图上下文 9 | * @author stworthy 10 | */ 11 | public class ViewContext { 12 | private String viewBasePath; 13 | private String controllerPath; 14 | private String actionName; 15 | private HttpServletRequest request; 16 | private HttpServletResponse response; 17 | private ServletContext servletContext; 18 | 19 | public String getViewBasePath() { 20 | return viewBasePath; 21 | } 22 | 23 | public void setViewBasePath(String viewBasePath) { 24 | this.viewBasePath = viewBasePath; 25 | } 26 | 27 | public HttpServletRequest getRequest() { 28 | return request; 29 | } 30 | 31 | public void setRequest(HttpServletRequest request) { 32 | this.request = request; 33 | } 34 | 35 | public HttpServletResponse getResponse() { 36 | return response; 37 | } 38 | 39 | public void setResponse(HttpServletResponse response) { 40 | this.response = response; 41 | } 42 | 43 | public ServletContext getServletContext() { 44 | return servletContext; 45 | } 46 | 47 | public void setServletContext(ServletContext servletContext) { 48 | this.servletContext = servletContext; 49 | } 50 | 51 | public String getActionName() { 52 | return actionName; 53 | } 54 | 55 | public void setActionName(String actionName) { 56 | this.actionName = actionName; 57 | } 58 | 59 | public String getControllerPath() { 60 | return controllerPath; 61 | } 62 | 63 | public void setControllerPath(String controllerPath) { 64 | this.controllerPath = controllerPath; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/ViewRenderer.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc; 2 | 3 | /** 4 | * 视图渲染接口 5 | * @author stworthy 6 | */ 7 | public interface ViewRenderer { 8 | /** 9 | * 渲染动作 10 | * @param viewObject 视图对象 11 | * @param viewContext 视图上下文 12 | * @throws Exception 13 | */ 14 | public void render(T viewObject, ViewContext viewContext) throws Exception; 15 | } 16 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/ViewRendererClass.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /** 10 | * 指定视图渲染类的注解 11 | * @author stworthy 12 | */ 13 | @Target({ElementType.TYPE}) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Documented 16 | public @interface ViewRendererClass { 17 | Class value(); 18 | } 19 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/binding/Bind.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.binding; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /** 10 | * 绑定请求参数注解,用于指示请求参数的前缀,如:
11 | *
12 |  * public void save(@Bind(prefix="user")User user) throws Exception{
13 |  * }
14 |  * 
15 | * HTTP传递过来的参数必须是user.code,user.name才能绑定到user对象 16 | * @author stworthy 17 | */ 18 | @Target({ElementType.PARAMETER}) 19 | @Retention(RetentionPolicy.RUNTIME) 20 | @Documented 21 | public @interface Bind { 22 | String prefix() default ""; 23 | } 24 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/binding/BindingContext.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.binding; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | 5 | /** 6 | * 绑定上下文 7 | * @author stworthy 8 | */ 9 | public class BindingContext { 10 | private String parameterName; 11 | private Class parameterType; 12 | private HttpServletRequest request; 13 | private String prefix; 14 | 15 | public String getParameterName() { 16 | return parameterName; 17 | } 18 | 19 | public void setParameterName(String parameterName) { 20 | this.parameterName = parameterName; 21 | } 22 | 23 | public Class getParameterType() { 24 | return parameterType; 25 | } 26 | 27 | public void setParameterType(Class parameterType) { 28 | this.parameterType = parameterType; 29 | } 30 | 31 | public HttpServletRequest getRequest() { 32 | return request; 33 | } 34 | 35 | public void setRequest(HttpServletRequest request) { 36 | this.request = request; 37 | } 38 | 39 | public String getPrefix() { 40 | return prefix; 41 | } 42 | 43 | public void setPrefix(String prefix) { 44 | this.prefix = prefix; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/binding/DataBinder.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.binding; 2 | 3 | /** 4 | * 数据绑定接口 5 | * @author Administrator 6 | */ 7 | public interface DataBinder { 8 | /** 9 | * 绑定操作 10 | * @param ctx 绑定上下文 11 | * @return 转换后的对象 12 | * @throws Exception 13 | */ 14 | public Object bind(BindingContext ctx) throws Exception; 15 | } 16 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/binding/binders/BigDecimalBinder.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.binding.binders; 2 | 3 | import com.et.mvc.binding.BindingContext; 4 | import com.et.mvc.binding.DataBinder; 5 | import com.et.mvc.binding.DataBinders; 6 | 7 | public class BigDecimalBinder implements DataBinder{ 8 | public Object bind(BindingContext ctx) throws Exception{ 9 | String parameterName = ctx.getParameterName(); 10 | if (!ctx.getPrefix().equals("")){ 11 | parameterName = ctx.getPrefix() + "." + parameterName; 12 | } 13 | String value = ctx.getRequest().getParameter(parameterName); 14 | if (value == null){ 15 | return null; 16 | } 17 | else{ 18 | if (DataBinders.isAllowEmpty() && value.equals("")) { 19 | return null; 20 | } 21 | return new java.math.BigDecimal(value); 22 | } 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/binding/binders/BigIntegerBinder.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.binding.binders; 2 | 3 | import com.et.mvc.binding.BindingContext; 4 | import com.et.mvc.binding.DataBinder; 5 | import com.et.mvc.binding.DataBinders; 6 | 7 | public class BigIntegerBinder implements DataBinder{ 8 | public Object bind(BindingContext ctx) throws Exception{ 9 | String parameterName = ctx.getParameterName(); 10 | if (!ctx.getPrefix().equals("")){ 11 | parameterName = ctx.getPrefix() + "." + parameterName; 12 | } 13 | 14 | String value = ctx.getRequest().getParameter(parameterName); 15 | if (value == null){ 16 | return null; 17 | } 18 | else{ 19 | if (DataBinders.isAllowEmpty() && value.equals("")) { 20 | return null; 21 | } 22 | return new java.math.BigInteger(value); 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/binding/binders/BooleanArrayBinder.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.binding.binders; 2 | 3 | import com.et.mvc.binding.BindingContext; 4 | import com.et.mvc.binding.DataBinder; 5 | import com.et.mvc.binding.DataBinders; 6 | 7 | public class BooleanArrayBinder implements DataBinder{ 8 | 9 | public Object bind(BindingContext ctx) throws Exception { 10 | String parameterName = ctx.getParameterName(); 11 | if (!ctx.getPrefix().equals("")) { 12 | parameterName = ctx.getPrefix() + "." + parameterName; 13 | } 14 | 15 | String[] values = (String[])ctx.getRequest().getParameterMap().get(parameterName); 16 | if (values == null){ 17 | return null; 18 | } else if (ctx.getParameterType().equals(boolean[].class)){ 19 | boolean[] aa = new boolean[values.length]; 20 | for(int i=0; i execute(); 18 | String[] except() default {}; 19 | String[] only() default {}; 20 | } 21 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/filter/AroundFilters.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.filter; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /** 10 | * 多环绕过滤器注解 11 | * @author stworthy 12 | */ 13 | @Target({ElementType.TYPE}) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Documented 16 | public @interface AroundFilters { 17 | AroundFilter[] value() default {}; 18 | } 19 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/filter/AroundHandler.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.filter; 2 | 3 | import com.et.mvc.Controller; 4 | 5 | /** 6 | * 环绕过滤器接口 7 | * @author stworthy 8 | */ 9 | public interface AroundHandler { 10 | /** 11 | * 控制器执行前 12 | * @param controller 控制器 13 | * @return 返回true继续执行,返回false中断执行 14 | * @throws Exception 15 | */ 16 | public boolean before(Controller controller) throws Exception; 17 | 18 | /** 19 | * 控制器执行后 20 | * @param controller 控制器 21 | * @return 返回true继续执行,返回false中断执行 22 | * @throws Exception 23 | */ 24 | public boolean after(Controller controller) throws Exception; 25 | } 26 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/filter/BeforeFilter.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.filter; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /** 10 | * 单前置过滤器注解 11 | * @author stworthy 12 | */ 13 | @Target({ElementType.TYPE}) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Documented 16 | public @interface BeforeFilter { 17 | String execute(); 18 | String[] except() default {}; 19 | String[] only() default {}; 20 | } 21 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/filter/BeforeFilters.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.filter; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /** 10 | * 多前置过滤器注解 11 | * @author stworthy 12 | */ 13 | @Target({ElementType.TYPE}) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Documented 16 | public @interface BeforeFilters { 17 | BeforeFilter[] value() default {}; 18 | } 19 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/renderer/AbstractViewRenderer.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.renderer; 2 | 3 | import com.et.mvc.ViewContext; 4 | import com.et.mvc.ViewRenderer; 5 | 6 | public abstract class AbstractViewRenderer implements ViewRenderer{ 7 | public void render(T viewObject, ViewContext viewContext) throws Exception{ 8 | if (viewContext.getResponse().isCommitted() == true){ 9 | return; 10 | } 11 | renderView(viewObject, viewContext); 12 | } 13 | 14 | protected abstract void renderView(T viewObject, ViewContext viewContext) throws Exception; 15 | } 16 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/renderer/BinaryViewRenderer.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.renderer; 2 | 3 | import com.et.mvc.BinaryView; 4 | import com.et.mvc.ViewContext; 5 | import java.io.OutputStream; 6 | import javax.servlet.http.HttpServletResponse; 7 | 8 | public class BinaryViewRenderer extends AbstractViewRenderer{ 9 | public void renderView(BinaryView view, ViewContext viewContext) throws Exception{ 10 | if (view == null){ 11 | return; 12 | } 13 | 14 | HttpServletResponse response = viewContext.getResponse(); 15 | response.setContentType(view.getContentType()); 16 | response.setContentLength(view.getData().length); 17 | if (view.getFileName() == null){ 18 | response.setHeader("Content-Disposition", view.getContentDisposition()); 19 | } 20 | else{ 21 | String filename = new String(view.getFileName().getBytes("GBK"), "ISO8859_1"); 22 | response.setHeader("Content-Disposition", view.getContentDisposition()+";filename="+filename); 23 | } 24 | OutputStream out = response.getOutputStream(); 25 | out.write(view.getData()); 26 | out.close(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/renderer/JsonViewRenderer.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.renderer; 2 | 3 | import com.et.mvc.JsonView; 4 | import com.et.mvc.ViewContext; 5 | import java.io.PrintWriter; 6 | import javax.servlet.http.HttpServletResponse; 7 | 8 | public class JsonViewRenderer extends AbstractViewRenderer{ 9 | public void renderView(JsonView view, ViewContext viewContext) throws Exception{ 10 | if (view == null){ 11 | return; 12 | } 13 | 14 | HttpServletResponse response = viewContext.getResponse(); 15 | if (view.getContentType() != null){ 16 | response.setContentType(view.getContentType()); 17 | } 18 | else{ 19 | response.setContentType("application/json;charset=utf-8"); 20 | } 21 | PrintWriter out = response.getWriter(); 22 | out.print(view.toString()); 23 | out.close(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/renderer/StringViewRenderer.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.renderer; 2 | 3 | import com.et.mvc.ViewContext; 4 | import java.io.PrintWriter; 5 | 6 | public class StringViewRenderer extends AbstractViewRenderer{ 7 | public void renderView(String view, ViewContext viewContext) throws Exception{ 8 | if (view == null){ 9 | return; 10 | } 11 | PrintWriter out = viewContext.getResponse().getWriter(); 12 | out.print(view); 13 | out.close(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/renderer/TextViewRenderer.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.renderer; 2 | 3 | import com.et.mvc.TextView; 4 | import com.et.mvc.ViewContext; 5 | import java.io.PrintWriter; 6 | import javax.servlet.http.HttpServletResponse; 7 | 8 | public class TextViewRenderer extends AbstractViewRenderer{ 9 | public void renderView(TextView view, ViewContext viewContext) throws Exception{ 10 | if (view == null){ 11 | return; 12 | } 13 | 14 | HttpServletResponse response = viewContext.getResponse(); 15 | if (view.getContentType() != null){ 16 | response.setContentType(view.getContentType()); 17 | } 18 | PrintWriter out = response.getWriter(); 19 | out.print(view.toString()); 20 | out.close(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/renderer/VoidViewRenderer.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.renderer; 2 | 3 | import com.et.mvc.ViewContext; 4 | import javax.servlet.RequestDispatcher; 5 | 6 | public class VoidViewRenderer extends AbstractViewRenderer{ 7 | public void renderView(Void viewObject, ViewContext viewContext) throws Exception{ 8 | String path = viewContext.getViewBasePath() + viewContext.getControllerPath().toLowerCase() + "/" + viewContext.getActionName() + ".jsp"; 9 | RequestDispatcher rd = viewContext.getRequest().getRequestDispatcher(path); 10 | rd.forward(viewContext.getRequest(), viewContext.getResponse()); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/routing/Route.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.routing; 2 | 3 | /** 4 | * 路由定义,由默认路由处理器处理 5 | * @author stworthy 6 | */ 7 | public class Route { 8 | private String url; 9 | private String controller; 10 | private String action; 11 | private Class handlerClass; 12 | 13 | public Route(String url, Class handlerClass){ 14 | this.url = url; 15 | this.handlerClass = handlerClass; 16 | } 17 | 18 | public Route(String url, String controller, Class handlerClass){ 19 | this.url = url; 20 | this.controller = controller; 21 | this.handlerClass = handlerClass; 22 | } 23 | 24 | public Route(String url, String controller, String action, Class handlerClass){ 25 | this.url = url; 26 | this.controller = controller; 27 | this.action = action; 28 | this.handlerClass = handlerClass; 29 | } 30 | 31 | public String getUrl() { 32 | return url; 33 | } 34 | 35 | public void setUrl(String url) { 36 | this.url = url; 37 | } 38 | 39 | public Class getHandlerClass() { 40 | return handlerClass; 41 | } 42 | 43 | public void setHandlerClass(Class handlerClass) { 44 | this.handlerClass = handlerClass; 45 | } 46 | 47 | public String getController() { 48 | return controller; 49 | } 50 | 51 | public void setController(String controller) { 52 | this.controller = controller; 53 | } 54 | 55 | public String getAction() { 56 | return action; 57 | } 58 | 59 | public void setAction(String action) { 60 | this.action = action; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/routing/RouteHandler.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.routing; 2 | 3 | import com.et.mvc.RequestContext; 4 | 5 | /** 6 | * 路由处理接口 7 | * @author stworthy 8 | */ 9 | public interface RouteHandler { 10 | /** 11 | * 获取路由选择结果 12 | * @param requestContext 请求上下文 13 | * @param route 路由定义 14 | * @return 路由选择结果 15 | */ 16 | public RouteResult getResult(RequestContext requestContext, Route route); 17 | } 18 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/routing/RouteResult.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.routing; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * 路由选择结果 8 | * @author stworthy 9 | */ 10 | public class RouteResult { 11 | private String subPackageName; 12 | private String controllerPath; 13 | private String controllerName; 14 | private String actionName; 15 | private Map params = new HashMap(); 16 | 17 | public String getSubPackageName() { 18 | return subPackageName; 19 | } 20 | 21 | public void setSubPackageName(String subPackageName) { 22 | this.subPackageName = subPackageName; 23 | } 24 | 25 | public String getControllerName() { 26 | return controllerName; 27 | } 28 | 29 | public void setControllerName(String controllerName) { 30 | this.controllerName = controllerName; 31 | } 32 | 33 | public String getActionName() { 34 | return actionName; 35 | } 36 | 37 | public void setActionName(String actionName) { 38 | this.actionName = actionName; 39 | } 40 | 41 | public String getControllerPath() { 42 | return controllerPath; 43 | } 44 | 45 | public void setControllerPath(String controllerPath) { 46 | this.controllerPath = controllerPath; 47 | } 48 | 49 | public Map getParams() { 50 | return params; 51 | } 52 | 53 | public void setParams(Map params) { 54 | this.params = params; 55 | } 56 | 57 | 58 | } 59 | -------------------------------------------------------------------------------- /Source/ etmvc stworthy/et-mvc/src/com/et/mvc/routing/RouteTable.java: -------------------------------------------------------------------------------- 1 | package com.et.mvc.routing; 2 | 3 | import com.et.mvc.RequestContext; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | /** 8 | * 路由表管理类 9 | * @author stworthy 10 | */ 11 | public class RouteTable { 12 | private static List routes = new ArrayList(); 13 | 14 | static{ 15 | Route defaultRoute = new Route("$controller/$action/$id", DefaultRouteHandler.class); 16 | routes.add(defaultRoute); 17 | } 18 | 19 | public static RouteResult selectRoute(RequestContext requestContext) throws Exception{ 20 | for(Route route: routes){ 21 | RouteHandler handler = (RouteHandler)route.getHandlerClass().newInstance(); 22 | RouteResult result = handler.getResult(requestContext, route); 23 | if (result != null){ 24 | return result; 25 | } 26 | } 27 | return null; 28 | } 29 | 30 | public static List getRoutes() { 31 | return routes; 32 | } 33 | 34 | public static void addRoute(Route route){ 35 | routes.add(route); 36 | } 37 | 38 | public static void addRoute(int pos, Route route){ 39 | routes.add(pos, route); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Source/README.md: -------------------------------------------------------------------------------- 1 | 2 | ## 说明 3 | 4 | **etmvc stworthy:** 作者`stworthy`最后更新的源码 5 | 6 | **etmvc shuzheng:** 更新版本 7 | -------------------------------------------------------------------------------- /Wiki/action.md: -------------------------------------------------------------------------------- 1 | ##Action方法和控制器环境 2 | 3 | 当请求到达时,etmvc将创建控制器对象,控制器对象会查找与“被请求的action”同名的public实例方法。如此看来,控制器的Action方法是允许被继承的。如果你希望某些方法不被作为action调用,可以将其声明为protected或者private。比如有如下的控制器: 4 | 5 | ```java 6 | public class BlogController extends ApplicationController{ 7 | public String show(){ 8 | return "show method"; 9 | } 10 | 11 | protected String create(){ 12 | return "create method"; 13 | } 14 | } 15 | ``` 16 | 17 | 当访问/blog/show时将输入框“show method” ,而访问/blog/create时将有“The requested resource (/test1/blog/create) is not available”的信息。 18 | 19 | Action方法允许使用控制器环境提供的一些对象: 20 | 21 | * request 22 | * response 23 | * session 24 | * servletContext 25 | * controllerPath 26 | * controllerName 27 | * actionPath 28 | * flash 29 | * exception 30 | 他们的作用应该不言自明,其中flash对象的使用方法我们将分出一个主题专门作介绍。 31 | -------------------------------------------------------------------------------- /Wiki/activerecord_callback.md: -------------------------------------------------------------------------------- 1 | ## ActiveRecord中的回调方法 2 | 3 | etmvc中ActiveRecord模型对象拥有很多的操作方法,其中有一类称为回调方法,在ActiveRecord模型对象的生命周期内,回调给予你更多的、更灵活控制能力。回调方法就象一个钩子,它允许在模型对象操作数据的前后执行一段逻辑,这实际就是ActiveRecord模型对象的AOP编程。 4 | 5 | ActiveRecord模型对象支持的回调方法有: 6 | 7 | |回调方法 |执行时机 | 8 | |:----|:----| 9 | |beforeCreate| 对象创建前执行 | 10 | |afterCreate |对象创建后执行 | 11 | |beforeUpdate |对象更新前执行 | 12 | |afterUpdate| 对象更新后执行 | 13 | |beforeSave |对象保存前执行 | 14 | |afterSave |对象保存后执行 | 15 | |beforeDestroy| 对象删除前执行 | 16 | |afterDestroy |对象删除后执行 | 17 | 18 | 回调方法签名:public void callbackMethodName() throws ActiveRecordException 19 | 20 | 我们举个回调方法应用的典型例子,在用户资料管理中,用户的信息除基本的信息外,还包括照片,而照片以文件的形式被保存在某个地方。为保证数据的完整性,在用户资料删除时必须同时删除其关联的照片文件。 21 | 22 | 我们来看一下用户的模型类定义: 23 | 24 | ```java 25 | @Table(name="users") 26 | public class User extends ActiveRecordBase{ 27 | @Id private Integer id; 28 | @Column private String name; 29 | @Column private String phone; 30 | @Column private String filename; 31 | 32 | public void afterDestroy() throws ActiveRecordException{ 33 | String path = getImagePath(); 34 | File file = new File(path); 35 | if (file.exists() && file.isFile()){ 36 | file.delete(); 37 | } 38 | } 39 | 40 | public String getImagePath(){ 41 | return "d:/temp/" + id + "_" + filename; //获取照片文件存放路径 42 | } 43 | 44 | //get,set... 45 | } 46 | ``` 47 | 48 | 我们重载了afterDestroy,告诉ActiveRecord框架,在记录删除后将相关的照片文件删除。现在来看调用代码: 49 | 50 | ```java 51 | User user = User.find(User.class, 1); 52 | user.destroy(); 53 | ``` 54 | 55 | 我们无须在调用时编写删除照片文件的代码,仅仅将User对象删除就好,User对象会做相应的回调,执行相关的逻辑。 56 | 57 | 另外,在ActiveRecord模型对象执行回调方法时是有事务保证的,所以一旦照片文件删除失败,整个对象将执行回滚操作。如此,对于模型对象的调用者来说,这将变得更清晰。 58 | -------------------------------------------------------------------------------- /Wiki/activerecord_datatype.md: -------------------------------------------------------------------------------- 1 | ## ActiveRecord中的数据类型映射 2 | 3 | etmvc中的ActiveRecord将数据表中的字段映射成模型类的字段,相应的将数据表中的字段类型映射成模型类的字段类型。 4 | 5 | 在多数情况下,ActiveRecord能够自动处理从JDBC类型到Java Object类型的映射,此种映射如下表所示: 6 | 7 | |JDBC 类型 | Java Object 类型 | 8 | |:-------|:----------------| 9 | |CHAR | String | 10 | |VARCHAR | String | 11 | |LONGVARCHAR | String | 12 | |NUMERIC | java.math.BigDecimal| 13 | |DECIMAL | java.math.BigDecimal| 14 | |BIT | Boolean | 15 | |TINYINT | Integer | 16 | |SMALLINT | Integer | 17 | |INTEGER | Integer | 18 | |BIGINT | Long | 19 | |REAL | Float | 20 | |FLOAT | Double | 21 | |DOUBLE | Double | 22 | |BINARY | byte[.md](.md) | 23 | |VARBINARY | byte[.md](.md) | 24 | |LONGVARBINARY | byte[.md](.md) | 25 | |DATE | java.sql.Date | 26 | |TIME | java.sql.Time | 27 | |TIMESTAMP | java.sql.Timestamp| 28 | 29 | 在类型的映射上可能存在一些需要转换的,比如在MSSQL数据库中定义了一个datetime的字段类型,而在模型类中定义了java.sql.Date类型。按照上表中的映射关系,将无法直接从datetime映射成java.sql.Date,所以需要作些转换。 30 | 31 | 我们需要为上面的这种转换编写一个转换器,转换器必须实现com.et.ar.Converter接口: 32 | 33 | ```java 34 | public class DateConverter implements Converter { 35 | @Override 36 | public Object convert(Object value) { 37 | if (value == null) { 38 | return null; 39 | } 40 | String s = value.toString().substring(0, 10); //取yyyy-mm-dd 41 | return java.sql.Date.valueOf(s); 42 | } 43 | } 44 | ``` 45 | 46 | 这个转换器将对象value转换成java.sql.Date类型的对象,在上面的转换实现中,我们仅是简单地取前十个字符串,然后调用valueOf进行转换。 47 | 48 | 最后将这个转换器进行注册登记: 49 | 50 | ```java 51 | static{ 52 | ConvertUtil.register(new DateConverter(), java.sql.Date.class); 53 | } 54 | ``` 55 | 56 | 好了,ActiveRecord在处理到需要映射成java.sql.Date类型的字段时会调用我们自定义的转换器进行处理。 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /Wiki/activerecord_spring.md: -------------------------------------------------------------------------------- 1 | ## ActiveRecord中集成spring 2 | 3 | etmvc中ActiveRecord(下称AR)在使用上可以独立使用,其数据库的连接信息通过activerecord.properties进行配置。 4 | AR提供一个简单的连接池实现,如果需要使用更高效的连接池,则可以利用spring来进行配置。AR集成spring分二步进行: 5 | 6 | 1、配置spring的连接池 7 | 8 | ```xml 9 | 10 | 11 | 12 | 13 | 14 | 15 | ``` 16 | 17 | 2、配置AR的连接工厂 18 | ```xml 19 | 20 | 21 | 22 | 23 | 24 | ``` 25 | 26 | 这样就完成了切换数据源的操作,下面再给出一个使用多数据库的配置实例 27 | 28 | ```xml 29 | 35 | 41 | 42 | 46 | 50 | ``` 51 | -------------------------------------------------------------------------------- /Wiki/aroundfilter.md: -------------------------------------------------------------------------------- 1 | ## etmvc中使用环绕过滤器 2 | 3 | etmvc中支持前置过滤器,后置过滤器和环绕过滤器,前面介绍过前置过滤器了,请参阅《etmvc的过滤器基础》。 4 | 5 | 环绕过滤器是功能最强的一类过滤器,允许拦截action方法的执行前和执行后,这实际上就是一种AOP。所以通过环绕过滤器,我们可以在action方法执行前和执行后处理一些逻辑,甚至中断action的执行,可以用它做日志处理、异常处理等。 6 | 7 | etmvc中创建一个环绕过滤器同前置过滤器有些不同,前置过滤器只要简单在控制器中编写一个方法就行了,环绕过滤器必须是单独的一个类,这个类要求实现AroundHandler接口,或者继承AbstractAroundHandler。我们先来看个简单的环绕过滤器例子: 8 | 9 | ```java 10 | public class TestAroundFilter implements AroundHandler{ 11 | 12 | @Override 13 | public boolean before(Controller controller) throws Exception { 14 | System.out.println("begin invoke:" + controller.getActionName()); 15 | return true; 16 | } 17 | 18 | @Override 19 | public boolean after(Controller controller) throws Exception { 20 | System.out.println("after invoke:" + controller.getActionName()); 21 | return true; 22 | } 23 | 24 | } 25 | ``` 26 | 27 | 其中before和after分别是在action方法执行之前和之后执行,如果返回true则继续后续代码执行,如果返回false则中断后续代码执行,所以如果before返回false将中止action方法的执行。 28 | 29 | 如此,利用环绕过滤器,我们完全能够控制action方法之前和之后的逻辑,只要在before和after中编写处理逻辑的代码就行了。如若要记录日志,只要在before中记录action开始执行的时间,在after中记录action执行完成的时间,就能够清楚执行那个action,什么时间开始执行,什么时间结束执行,执行了多长时间等。 30 | 31 | 好了,我们来看看这个环绕过滤器怎样安装到控制器上,看下面的示例: 32 | 33 | ```java 34 | @AroundFilter(execute=TestAroundFilter.class) 35 | public class HelloController extends ApplicationController{ 36 | public String say() throws Exception{ 37 | return "hello,world"; 38 | } 39 | } 40 | ``` 41 | 42 | 用@AroundFilter注解就能将环绕过滤器安到控制器上,注意到这里的execute是类,而前置过滤器和后置过滤器是方法名称。如果需要安多个环绕过滤器,用@AroundFilters就好了。 43 | 44 | 在上面例子中,我们执行http://localhost:8080/xxx/hello/say时,将在TOMCAT控制台输出: 45 | 46 | begin invoke:say 47 | 48 | after invoke:say 49 | 50 | 51 | -------------------------------------------------------------------------------- /Wiki/aroundfilter_exception.md: -------------------------------------------------------------------------------- 1 | ## etmvc中使用环绕过滤器处理异常 2 | 3 | etmvc框架中可以使用环绕过滤来处理异常,在WEB应用程序中如果需要处理全局的异常,比如我们可能需要拦截全局的异常然后集中处理,这时可以使用环绕过滤器。 4 | 5 | 下面给出一个参考的处理方法: 6 | 7 | 定义异常过滤器: 8 | 9 | ```java 10 | public class ExceptionFilter implements AroundHandler{ 11 | 12 | @Override 13 | public boolean after(Controller controller) throws Exception { 14 | Exception ex = controller.getException(); 15 | if (ex != null){ 16 | controller.getSession().setAttribute("error", ex); 17 | controller.getResponse().sendRedirect("/myweb/application/error"); 18 | return false; 19 | } 20 | return true; 21 | } 22 | 23 | @Override 24 | public boolean before(Controller controller) throws Exception { 25 | return true; 26 | } 27 | 28 | } 29 | ``` 30 | 31 | 异常过滤器中检测到有异常发生,则重定向到全局的错误页面,为了方便,我们将错误页面显示的方法写在了ApplicationController类中,当然也可以专门写个处理异常的控制器: 32 | 33 | ```java 34 | @AroundFilter(execute=ExceptionFilter.class) 35 | public class ApplicationController extends Controller{ 36 | public void error() throws Exception{ 37 | Exception ex = (Exception)session.getAttribute("error"); 38 | session.setAttribute("error", null); 39 | ex.printStackTrace(); 40 | request.setAttribute("error", ex); 41 | } 42 | } 43 | ``` 44 | 45 | 最后需要一个页面(/views/applicaion/error.jsp)来显示异常信息: 46 | 47 | ```jsp 48 | <%@ page language="java" contentType="text/html; charset=UTF-8" 49 | pageEncoding="UTF-8"%> 50 | 51 | 52 | 53 | 54 | Insert title here 55 | 56 | 57 |

error message

58 |

${error }

59 | 60 | 61 | ``` 62 | 63 | 在下面的myweb例子中执行http://localhost:8080/myweb/test/test1时成功执行,显示一个字符串,执行http://localhost:8080/myweb/test/test2时出现异常,重定向至错误页面。 64 | -------------------------------------------------------------------------------- /Wiki/configuration.md: -------------------------------------------------------------------------------- 1 | ## 关于etmvc的配置 2 | 3 | etmvc遵循“约定优于配置”的原则,通过文件的命名及存放位置来代替显式的配置,避免编写烦杂的XML配置文件。 4 | 5 | etmvc的配置只有一处,即在web.xml中配置一个filter,如下所示: 6 | 7 | ```xml 8 | 9 | etmvc 10 | com.et.mvc.DispatcherFilter 11 | 12 | controllerBasePackage 13 | controllers 14 | 15 | 16 | viewBasePath 17 | /views 18 | 19 | 20 | plugin 21 | plugin.OcrServer 22 | 23 | 24 | 25 | etmvc 26 | /* 27 | 28 | ``` 29 | 30 | 其中,filter的初始参数有三个:controllerBasePackage, viewBasePath, plugin,说明如下: 31 | 32 | 1 controllerBasePackage是控制器的基包名称,如controllers,所有的控制器类必须在controllers包中,或者在controllers的子包中。控制器类必须以Controller结尾,必须继承Controller,比如有如下的控制器类: 33 | ```java 34 | package controllers; 35 | 36 | public class ArticleController extends ApplicationController{ 37 | public View showImage(int id) throws Exception{ 38 | //... 39 | } 40 | 41 | public View download(int id) throws Exception{ 42 | //... 43 | } 44 | 45 | public void create(){ 46 | 47 | } 48 | 49 | } 50 | ``` 51 | 控制器包名是controllers,控制器类名是ArticleController,有showImage等Action方法。 52 | 53 | 2 viewBasePath是存放视图模板的位置,如下所示: 54 | 视图模板的目录结构有一定的规则,在[viewBasePath]目录下是控制器名称(小写),再往下是对应每个Action方法的视图文件。如ArticleController控制器中的方法create对应到/article/create.jsp视图文件,即执行控制器的create方法后,etmvc根据执行的结果找到对应的视图进行渲染。 55 | 56 | 3 plugin是插件的配置,一般情况下无须用到,所以不用配置该项,关于插件的使用留到后面的章节再作介绍。 57 | -------------------------------------------------------------------------------- /Wiki/extendview.md: -------------------------------------------------------------------------------- 1 | ## 扩展etmvc的视图 2 | 3 | etmvc内置了多种常用的视图,每种视图都有对应的renderer对象,视图对象中通过加上@ViewRendererClass注解将renderer对象关联起来。比如JspView有相应的JspViewRenderer,JsonView有对应的JsonViewRenderer。 4 | 5 | 如果要使用自定义视图,则可以扩展视图,扩展视图是很简单的事情,我们需要做二件事情:一是定义视图对象,二是定义renderer对象。 6 | 7 | 假如我们要来定义一个JavaScriptView视图,用于向页面输出并执行一段JavaScript代码。首先定义视图对象,视图对象建议继承View对象: 8 | 9 | ```java 10 | @ViewRendererClass(JavaScriptViewRenderer.class) 11 | public class JavaScriptView extends View{ 12 | private String js; 13 | 14 | public JavaScriptView(String js){ 15 | this.js = js; 16 | } 17 | 18 | public String getJs() { 19 | return js; 20 | } 21 | 22 | public void setJs(String js) { 23 | this.js = js; 24 | } 25 | } 26 | ``` 27 | 28 | 我们看到,视图对象仅是一个定义了需要的数据载体,其渲染输出是通过renderer对象完成的。下面看来一下renderer对象的定义: 29 | ```java 30 | public class JavaScriptViewRenderer extends AbstractViewRenderer{ 31 | public void renderView(JavaScriptView view, ViewContext context) throws Exception{ 32 | PrintWriter out = context.getResponse().getWriter(); 33 | out.print(""); 34 | out.close(); 35 | } 36 | } 37 | ``` 38 | 39 | renderer对象扩展了AbstractViewRenderer ,视图的渲染就是通过renderView方法实现的。 40 | 41 | 好了,自定义的JavaScriptView扩展完成了,我们来看看怎样使用: 42 | 43 | ```java 44 | public class TestController extends ApplicationController{ 45 | public View jstest(){ 46 | JavaScriptView view = new JavaScriptView("alert('abc');"); 47 | return view; 48 | } 49 | } 50 | ``` 51 | 52 | 我们在控制器中定义一个Action方法,只要将该方法的返回类型设为JavaScriptView就行了。 53 | -------------------------------------------------------------------------------- /Wiki/helloworld.md: -------------------------------------------------------------------------------- 1 | ## Hello,World经典示例 2 | 3 | 我们利用etmvc来建立一个Hello,World的WEB应用程序。 4 | 5 | 一、首先,建立新的WEB项目,引入et-mvc.jar和paranamer-1.3.jar,配置web.xml,加入一个过滤器,如下所示: 6 | 7 | ```xml 8 | 9 | etmvc 10 | com.et.mvc.DispatcherFilter 11 | 12 | controllerBasePackage 13 | controllers 14 | 15 | 16 | viewBasePath 17 | /views 18 | 19 | 20 | 21 | etmvc 22 | /* 23 | 24 | ``` 25 | 我们看到,过滤器com.et.mvc.DispatcherFilter目前只有二个参数,controllerBasePackage指的是控制器的包名,viewBasePath指的是视图模板的存放目录。 26 | 27 | 二、接下来,我们开始编写控制器HelloController,一般我们会编写控制器基类ApplicationController,我们的HelloController会继承它。注意到,控制器的包名是controllers,这就是前面配置中的controllerBasePackage配置值。 28 | ```java 29 | package controllers; 30 | 31 | import com.et.mvc.Controller; 32 | 33 | public class ApplicationController extends Controller{ 34 | 35 | } 36 | ``` 37 | ```java 38 | package controllers; 39 | 40 | import com.et.mvc.TextView; 41 | 42 | public class HelloController extends ApplicationController{ 43 | public TextView say(){ 44 | return new TextView("hello,world"); 45 | } 46 | } 47 | ``` 48 | 49 | 三、至些,我们的Hello,World程序编写完毕,部署后在浏览器地址栏输入http://localhost:8080/helloworld/hello/say,将会输出hello,world字样。 50 | -------------------------------------------------------------------------------- /Wiki/multi_database.md: -------------------------------------------------------------------------------- 1 | ## ActiveRecord中同时访问多个数据库 2 | 3 | 我们先来看一下ActiveRecord(下简称AR)的基本配置: 4 | 5 | ```java 6 | domain_base_class=com.et.ar.ActiveRecordBase 7 | 8 | com.et.ar.ActiveRecordBase.driver_class=com.mysql.jdbc.Driver 9 | com.et.ar.ActiveRecordBase.url=jdbc:mysql://localhost/mydb 10 | com.et.ar.ActiveRecordBase.username=root 11 | com.et.ar.ActiveRecordBase.password=soft123456 12 | com.et.ar.ActiveRecordBase.pool_size=2 13 | ``` 14 | 15 | 其中的配置项domain\_base\_class是我们域模型对象的基类,我们在定义模型类时必须让其继承ActiveRecordBase,AR将根据此找到对应的数据库连接。 16 | 17 | 如果我们想同时使用多个数据库,这时我们可以先定义二个基类: 18 | 19 | ```java 20 | public class Base1 extends ActiveRecordBase{ 21 | } 22 | public class Base2 extends ActiveRecordBase{ 23 | } 24 | ``` 25 | 26 | 然后进行配置: 27 | 28 | ```java 29 | domain_base_class=models.Base1 models.Base2 30 | 31 | models.Base1.driver_class=com.mysql.jdbc.Driver 32 | models.Base1.url=jdbc:mysql://localhost/mydb1 33 | models.Base1.username=root 34 | models.Base1.password=soft123456 35 | models.Base1.pool_size=2 36 | 37 | models.Base2.driver_class=com.mysql.jdbc.Driver 38 | models.Base2.url=jdbc:mysql://localhost/mydb2 39 | models.Base2.username=root 40 | models.Base2.password=soft123456 41 | models.Base2.pool_size=2 42 | ``` 43 | 44 | 我们只要让我们的模型类继承Base1或Base2,就能正确使用对应的数据库连接。如果那一天又要改回去连接一个数据库了,只要改一下这个activerecord.properties属性文件就OK了。 45 | 46 | AR中同时访问多个数据库时是不是很简单。 47 | -------------------------------------------------------------------------------- /Wiki/plugin.md: -------------------------------------------------------------------------------- 1 | ## etmvc框架中的插件 2 | 3 | etmvc框架拥有一套插件体系结构,如果需要扩展某些功能,就可以通过插件来完成。etmvc框架在初始化时会扫描安装进来的插件,如果发现有插件就进行加载。 4 | 5 | 举个例子,在WEB应用程序中如若需要一个后台服务进程处理一些事情,则使用插件提供的机制可能很合适,又如,在需要整个WEB应用程序加载之前执行一些代码时,也可以利用插件来完成,因为插件的启动执行是在etmvc框架初始化时完成的。 6 | 7 | 编写插件分二个步骤: 8 | 9 | 1、编写插件实现代码,要求实现com.et.mvc.PlugIn接口,如: 10 | 11 | ```java 12 | public class RouteLoader implements PlugIn{ 13 | 14 | @Override 15 | public void destroy() { 16 | } 17 | 18 | @Override 19 | public void init(PlugInContext ctx) { 20 | Route route = new Route("blog/$year/$month/$day", DefaultRouteHandler.class); 21 | route.setController("blog"); 22 | route.setAction("show"); 23 | RouteTable.addRoute(0, route); 24 | } 25 | 26 | } 27 | ``` 28 | 29 | 其中init方法做一些初始化的工作,destroy作一些销毁的工作。 30 | 31 | 2、注册插件,在web.xml中增加一个plugin的参数: 32 | 33 | ```xml 34 | 35 | etmvc 36 | com.et.mvc.DispatcherFilter 37 | 38 | controllerBasePackage 39 | controllers 40 | 41 | 42 | viewBasePath 43 | /views 44 | 45 | 46 | plugin 47 | utils.RouteLoader 48 | 49 | 50 | 51 | etmvc 52 | /* 53 | 54 | ``` 55 | 56 | plugin参数值为插件实现类的名称,如果有多个插件,则以“,”分开。 57 | 58 | 3、重启WEB容器,这样就能正确加载插件了。 59 | -------------------------------------------------------------------------------- /Wiki/route.md: -------------------------------------------------------------------------------- 1 | ## etmvc框架对URL路由的支持 2 | 3 | etmvc框架使用路由技术实现把URL映射到控制器类中的action方法上,典型的http://localhost:8080/xxx/user/show将映射到UserController类中的show方法上,实际上这个规则是允许改变的。etmvc框架将允许你自定义自已的匹配规则来映射你的控制器类及其行为,这就需要定义路由。 4 | 5 | 一个路由的定义由一些占位符组成,占位符由美元符后面跟着字母组成,如“$controller/$action/$id”,这是框架采用的默认路由。根据这个路由,下面的这些例子将被匹配: 6 | 7 | |URL| CONTROLLER| ACTION |ID | 8 | |:--|:----------|:-------|:--| 9 | |/user| UserController| index | | 10 | |/user/show| UserController| show | | 11 | |/blog/show/123| BlogController| show |123 | 12 | 13 | 14 | 如果没匹配到$action,则将默认使用index方法。 15 | 16 | 定义一个新的路由时,必须实例化Route,如下面的这个例子: 17 | 18 | ```java 19 | Route route = new Route("blog/$year/$month/$day", DefaultRouteHandler.class); 20 | route.setController("blog"); 21 | route.setAction("show"); 22 | RouteTable.addRoute(0, route); 23 | ``` 24 | 25 | 其中我们定义了嵌入式变量$year,$month,$day,这个路由规划将能够映射到BlogController类中的方法: 26 | 27 | ```java 28 | public String show(int year, int month, int day) { 29 | return year + "-" + month + "-" + day; 30 | } 31 | ``` 32 | 33 | 嵌入式变量将自动映射成方法的参数。 34 | 35 | 可以定义多个路由规则,匹配是顺序进行的,也将是在路由表中从第一个规则开始进行匹配,找到就按照这个路由查找控制器类和方法。 36 | 37 | 在上面的例子中,这些URL将会有如下的映射: 38 | 39 | |URL| CONTROLLER| ACTION | 40 | |:--|:----------|:-------| 41 | |/blog/2009/07/10| BlogController| show | 42 | |/user/list| UserController| list | 43 | |/product/show| ProductController| show | 44 | 45 | 46 | 利用路由技术可以提供非常优雅的URL,一看URL就知道是那个控制器类和方法在处理。 47 | 48 | 最后有一点需要注意的是:定义一个路由后必须将它加入路由表中,并且确保在应用程序启动时是可用的。 49 | -------------------------------------------------------------------------------- /Wiki/transaction.md: -------------------------------------------------------------------------------- 1 | ## ActiveRecord中使用事务 2 | 3 | ActiveRecord中模型对象调用的每个方法如save, destroy, create, update等都是原子的,都受事务保护。 4 | 5 | 如果需要保证多个数据操作在一个事务中,则需要使用事务控制,如下所示: 6 | 7 | ```java 8 | try { 9 | ActiveRecordBase.beginTransaction(); 10 | //do something 11 | ActiveRecordBase.commit(); 12 | 13 | } catch (Exception ex) { 14 | ActiveRecordBase.rollback(); 15 | } 16 | ``` 17 | 18 | 如上所示,ActiveRecord中的事务是通过beginTransaction, commit, rollback等方法进行控制的。 19 | -------------------------------------------------------------------------------- /Wiki/upload_download.md: -------------------------------------------------------------------------------- 1 | ## etmvc中进行上传和下载 2 | 3 | et-mvc上传文件是对Commons-fileupload组件的封装,所以使用时需要引入commons-fileupload.jar, commons-io.jar, commons-logging.jar三个包。 4 | 5 | 上传文件的第一步就是象下面一样创建一个multipart/form-data表单: 6 | 7 | ```html 8 |
" method="POST" enctype="multipart/form-data"> 9 | 10 | 11 |
12 | ``` 13 | 14 | 然后编写控制器,定义上传的Action方法: 15 | ```java 16 | public class UploadController extends ApplicationController{ 17 | public String doUpload(MultipartFile file) throws Exception{ 18 | file.transferTo(new File("e:/temp/" + file.getOriginalFilename())); 19 | return file.getOriginalFilename()+":"+file.getSize(); 20 | } 21 | } 22 | ``` 23 | 24 | 需要下载文件时,可以使用BinaryView,如下所示: 25 | 26 | ```java 27 | public BinaryView download() throws Exception{ 28 | BinaryView view = BinaryView.loadFromFile("e:/temp/arrow.gif"); 29 | view.setContentType("image/gif"); 30 | //view.setContentDisposition("attachment"); //下载 31 | return view; 32 | } 33 | ``` 34 | 35 | 上传下载就介绍这些,看起来应该是比较简单的。 36 | 37 | 38 | --------------------------------------------------------------------------------