浏览 3046 次
|
锁定老贴子 主题:struts2.01实践中的问题和经验!
该帖已经被评为新手帖
|
|
|---|---|
| 作者 | 正文 |
|
最后更新时间:2006-12-05
1,绝对不要使用SPRING中的自动装配,也就是说不要用STRUTS2.01例子中的方法.
2,这个问题比较怪,看看谁能解释:
/**
* 取记录数
*
* @param queryString
* @param values
* @return
*/
public int count(final String queryString, final Object[] values) {
int count = 0;
Query queryObject = getSession().createQuery(queryString);
if (values != null) {
for (int i = 0; i < values.length; i++) {
queryObject.setParameter(i, values[i]);
}
}
//count = ((Integer) queryObject.iterate().next()).intValue();
/** 原来在 hibernate3.0+spring1.2.8 下正常,搞不懂在hibernate3.2+Spring2.0 为什么得改成下面的代码*/
count = ((Long) queryObject.iterate().next()).intValue();
return count;
}
3.发现一个BUG.当在SPRING配置中定义一个BEAN,在STRUTS2.01中也配置时,录入验校失败. package my.user.struts;
import my.user.pojo.Team;
import my.user.service.TeamTreeService;
import com.opensymphony.xwork2.ActionSupport;
public class TeamAction extends ActionSupport {
private Team team;
private TeamTreeService teamTreeService;
public TeamAction(TeamTreeService teamTreeService) {
this.teamTreeService = teamTreeService;
}
public void setTeam(Team team) {
this.team = team;
}
public String add() {
teamTreeService.saveLeaf(team);
return SUCCESS;
}
}
这个POJO是映射是一个子类的映射 package my.user.pojo;
import java.util.Date;
import java.util.List;
import my.base.pojo.ILeaf;
/**
* Team generated by MyEclipse - Hibernate Tools
*/
public class Team implements java.io.Serializable,ILeaf {
// Fields
private String id;
private String parentId;
private String name;
private Date createDate;
private String note;
private ILeaf parent;
private List children=new java.util.Vector();
// Constructors
/** default constructor */
public Team() {
}
/** full constructor */
public Team(String parentId, String name, Date createDate, String note) {
this.parentId = parentId;
this.name = name;
this.createDate = createDate;
this.note = note;
}
// Property accessors
public String getId() {
return this.id;
}
public void setId(String id) {
this.id = id;
}
public String getParentId() {
return this.parentId;
}
public void setParentId(String parentId) {
this.parentId = parentId;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public Date getCreateDate() {
return this.createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public String getNote() {
return this.note;
}
public void setNote(String note) {
this.note = note;
}
public List getChildren() {
return children;
}
public void addChild(ILeaf team){
children.add(team);
team.setParent(this);
}
public ILeaf getParent() {
return parent;
}
public void setParent(ILeaf team) {
this.parent= team;
}
public void setChildren(List children) {
this.children = children;
}
}
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping auto-import="false">
<import class="my.user.pojo.Team" rename="Team" />
<class name="my.base.pojo.ILeaf" table="ileaf">
<id name="id" type="java.lang.String">
<column name="id" length="50" />
<generator class="uuid.hex" />
</id>
<!--
<property name="parentId" type="java.lang.String">
<column name="parent_id" length="50" />
</property>
-->
<property name="name" type="java.lang.String">
<column name="name" />
</property>
<property name="createDate" type="java.util.Date">
<column name="createDate" length="19" />
</property>
<property name="note" type="java.lang.String">
<column name="note" />
</property>
<joined-subclass name="my.user.pojo.Team" table="team">
<key column="id"/>
<!-- 树型结构配置 -->
<bag name="children" inverse="true" order-by="createDate DESC"
cascade="save-update">
<key column="parent_id" />
<one-to-many class="my.user.pojo.Team" />
</bag>
<many-to-one name="parent" column="parent_id" not-found="ignore"
cascade="save-update" />
</joined-subclass>
</class>
</hibernate-mapping>
spring配置 <bean id="teamAction" class="my.user.struts.TeamAction" singleton="false">
<constructor-arg index="0">
<ref local="teamTreeService"/>
</constructor-arg>
</bean>
struts2.01配置 <!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="user" namespace="/user" extends="struts-default">
<action name="Team!*" method="{1}" class="teamAction">
<result name="input">/user/addTeam.jsp</result>
<result type="redirect">HelloWorld.jsp</result>
</action>
</package>
</struts>
此时一切正常,但是录入框的验校失败. 我想是一个BUG! 声明:JavaEye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
|
| 返回顶楼 | |
|
最后更新时间:2006-12-05
reply 2: hibernate 3.2开始count返回为Long型 |
|
| 返回顶楼 | |
|
最后更新时间:2006-12-14
hi,你好,我在测试struts2+spring+ibatis整合,看了你的例子3,自己做的老是过不去,能把你的发给我看看吗,我的applicationcontext.xml,struts.xml不知道是否配置有问题,当我直接访问action的时候老是抱找不到错误
我的struts.xml如下: <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <!-- <include file="example.xml"/> --> <!-- Add packages here --> <package name="default" extends="struts-default"> <action name="DateReport" class="DateReport"> <result name="success" type="dispatcher">/test/test.jsp</result> </action> </package> </struts> 帮忙看看那里有问题,多谢,我的msn:icedcoco2004@homail.com |
|
| 返回顶楼 | |
|
最后更新时间:2006-12-14
我的applicationcontext.xml配置如下:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans default-autowire="autodetect"> <!-- default-lazy-init="true" --> <!-- <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>/WEB-INF/classes/jdbc.properties</value> </list> </property> </bean> --> <!-- <bean id="datasource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName"> <value>jdbc/adcms</value> </property> </bean> --> <bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true"> <property name="transactionManager" ref="transactionManager"/> <property name="transactionAttributes"> <props> <prop key="insert*">PROPAGATION_REQUIRED</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="*">PROPAGATION_REQUIRED,readOnly</prop> </props> </property> </bean> <!-- <bean id="StatSRService" parent="baseTransactionProxy" singleton="false"> <property name="target"> <bean class="com.airinbox.sr.service.StatSRServiceImpl" singleton="false"> <property name="statDao" ref="statDao"/> </bean> </property> </bean> --> <bean id="moSRService" parent="baseTransactionProxy" autowire="no"> <property name="target"> <bean class="com.airinbox.sr.service.MoSRServiceImp" autowire="no"> <property name="moDao" ref="moDao"/> </bean> </property> </bean> <bean id="promoteChannelService" parent="baseTransactionProxy"> <property name="target"> <bean class="com.airinbox.sr.service.PromoteChannelServiceImp"> <property name="promoteChannelDao" ref="promoteChannelDao"/> </bean> </property> </bean> <bean id="DateReport" class="com.airinbox.sr.action.DateReport" singleton="false"> <constructor-arg index="0"> <ref local="moSRService"/> </constructor-arg> </bean></beans> 红色部分为我的action 你看我这样的配置有问题吗? 在我访问的时候(http://localhost:8080/struts2test/DateReport.action)报错找不到DateReport |
|
| 返回顶楼 | |
|
最后更新时间:2006-12-17
引用 3.发现一个BUG.当在SPRING配置中定义一个BEAN,在STRUTS2.01中也配置时,录入验校失败.
找到原因了,被折磨的一个星期. 发现的问题竞然......... 吐血!!!! |
|
| 返回顶楼 | |






