Jeecms 源码剖析(2)

电脑杂谈  发布时间:2019-09-01 10:02:33  来源:网络整理

for (String dllsql : sqlList) {

stat.addBatch(dllsql);

}

stat.executeBatch();

stat.close();

conn.close();

}

/**

*更新配置

*

*@paramdbHost

*@paramdbName

*@paramdbPort

*@paramdbUser

*@paramdbPassword

*@paramdomain

*@paramcxtPath

*@paramport

*@throwsException

*/

publicstaticvoid updateConfig(String dbHost, String dbPort,

String dbName, String dbUser, String dbPassword, String domain,

String cxtPath, String port) throws Exception {

Connection conn = getConn(dbHost, dbPort, dbName, dbUser, dbPassword);

Statement stat = conn.createStatement();

String sql = “update CORE_WEBSITE set DOMAIN=’” + domain + “‘”;

stat.executeUpdate(sql);

sql = “update CORE_GLOBAL set CONTEXT_PATH=’” + cxtPath + “‘,PORT=”

+ port;

stat.executeUpdate(sql);

stat.close();

jeecms 源码_jeecms教程_jeecms 源码

conn.close();

}

/**

*读取sql子句。“/*”开头为注解,“;”为sql结束。

*

*@paramfileName

* sql文件地址

*@returnlistofsql

*@throwsException

*/

publicstatic List<String> readSql(String fileName) throws Exception {

BufferedReader br = new BufferedReader(new InputStreamReader(

new FileInputStream(fileName), Constants.ENCODING));

List<String> sqlList = new ArrayList<String>();

StringBuilder sqlSb = new StringBuilder();

String s = null;

while ((s = br.readLine()) != null) {

if (s.startsWith(“/*”)) {

continue;

}

if (s.endsWith(“;”)) {

sqlSb.append(s);

sqlSb.setLength(sqlSb.length() – 1);

sqlList.add(sqlSb.toString());

sqlSb.setLength(0);

} else {

sqlSb.append(s);

}

}

br.close();

return sqlList;

}

}

(略)

<!– Spring 刷新Introspector防止存储泄露 –>

<listener> <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>

</listener>

<!– session超时定义,单位为分钟 –>

<session-config>

<session-timeout>20</session-timeout>

</session-config>

<error-page>

<error-code>404</error-code>

<location>/404.html</location>

</error-page>

<error-page>

<error-code>403</error-code>

<location>/403.html</location>

</error-page>

<welcome-file-list>

<welcome-file>index.jspa</welcome-file>

<welcome-file>index.do</welcome-file>

<welcome-file>index.html</welcome-file>

</welcome-file-list>

目录:之一

总共40张表在Spring里面可以用这些方法:

<property name=“mappingLocations”>

<list> <value>classpath:/com/jeecms/core/entity/*.hbm.xml</value> <value>classpath:/com/jeecms/cms/entity/*.hbm.xml</value> <value>classpath:/com/jeecms/article/entity/*.hbm.xml</value> <value>classpath:/com/jeecms/download/entity/*.hbm.xml</value> <value>classpath:/com/jeecms/auxiliary/entity/*.hbm.xml</value>

</list>

</property>

同样Hibernate也可以这么:

<property name=“hibernateProperties”>

<value>

hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect

hibernate.show_sql=true

hibernate.format_sql=false

hibernate.query.substitutions=true 1, false 0

hibernate.jdbc.batch_size=20

hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider

hibernate.cache.provider_configuration_file_resource_path=/ehcache-hibernate.xml

</value>

</property>

<!– 事务配置 –>

<bean id=”txManager” class=”org.springframework.orm.hibernate3.HibernateTransactionManager”>

<property name=”sessionFactory” ref=”sessionFactory” />

</bean>

<!– 使用annotation 自动登录bean,并检查@Required,@Autowired的属性已被注入 –>

<context:component-scan base-package=”com.jeecms” />

<!– 使用annotation定义事务 –>

<tx:annotation-driven transaction-manager=”txManager” />

Spring注解@Component、@Repository、@Service、@Controller区别

Spring 2.5 中不仅提供 @Component 注释外,还定义了几个拥有特殊语境的注解,它们分别是:@Repository、@Service 和 @Controller。在现在的 Spring版本中,这 3 个注释和 @Component 是等效的,但是从注释类的命名上jeecms 源码,很容易看出这 3 个注解分别和持久层、业务层和控制层(Web 层)相对应。虽然现在这 3 个注释和 @Component 相比没有什么新意,但 Spring将在今后的版本中为他们添加特殊的功能。所以,如果 Web 应用程序采用了经典的三层分层结构的话jeecms 源码,最好在持久层、业务层和控制层分别采取 @Repository、@Service 和 @Controller 对分层中的类进行注解,而用 @Component 对这些非常中立的类进行注释。

@Service用于标注业务层模块,@Controller用于标注控制层模块(如struts中的action),@Repository用于标注数据访问部件,即DAO组件,而@Component泛指组件,当组件不好归类的之后,我们可以使用这个注释进行标注。

Spring事务处理

@Repository

public abstract class BaseDaoImpl<T extends Serializable> implements BaseDao<T> {

protected Logger log = LoggerFactory.getLogger(getClass());

protected SessionFactory sessionFactory;

jeecms教程_jeecms 源码_jeecms 源码

@Autowired

public void setSessionFactory(SessionFactory sessionFactory) {

this.sessionFactory = sessionFactory;

}

protected Session getSession() {

return sessionFactory.getCurrentSession();

}

public T save(T entity) {

Assert.notNull(entity);

getSession().save(entity);

return entity;

}

public Object update(Object entity) {

Assert.notNull(entity);

getSession().update(entity);

return entity;

}

public Object saveOrUpdate(Object entity) {

Assert.notNull(entity);

getSession().saveOrUpdate(entity);

return entity;

}

public void delete(Object entity) {

Assert.notNull(entity);

getSession().delete(entity);

}

public T deleteById(Serializable id) {

Assert.notNull(id);

T entity = load(id);


本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/ruanjian/article-121307-2.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    • 程志炫
      程志炫

      应该大力提升女性的经济地位

    • 炮击手
      炮击手

      看最后一个画面

    热点图片
    拼命载入中...