SSH做项目遇见的问题,以及解决办法

由于三个框架的版本都比较高,所以遇到各种问题!!

1、hibernateTemplate不建议使用find(String hql,Object value)方法

解决办法:用它的findByExample(Obejct entity)方法,里面传一个实体类对象参数即可!需要注意的时,实体类的属性中不要有基本类型的数据,用包装类型;如果是条件查询,就在实体类中封装你的条件,如果是查询所有,就传一个没有设置属性值的实体对象即可(用空参构造new出来的)!

2、hibernateTemplate的findByExample不能通过主键来查找到数据

解决办法:
根据主键查找数据,用hibernateTemplate的get(Class clazz,Serializable id )方法来查询!!前面的参数是实体对象.class,后面一个参数是id值!

3、struts2中值栈数据的存取

(1)存数据:
在action中定义一个变量名字叫xxx,生成getXxx方法,然后在方法中把查询道德结果赋给这个值即可存入值栈中;
如:action类中

private List<Customer> list;
	public List<Customer> getList() {
   
		return list;
	}

	public String list(){
   
		list = customerService.findAll();
		return "listSuccess";
	}

(2)取数据:在页面中,可以用EL表达式,但是不建议
首先映入struts2的标签库:

<%@ taglib uri="/struts-tags" prefix="s" %>

然后用struts2提供的标签取数据:

<s:property value="xxx"/>

如:

<!--获取值栈中的数据  -->
<s:iterator value="list" var="cus">
<tr>
	<td>
		<!--遍历这个要加#,直接获取数据不用加-->
		<s:property value="#cus.cusName"/>
	</td>
	<td>
		<s:property value="#cus.cusLevel"/>
	</td>
	<td>
		<s:property value="#cus.msgRes"/>
	</td>
	<td>
		<s:property value="#cus.contacts"/>
	</td>
	<td>
		<s:property value="#cus.fixedTel"/>
	</td>
	<td>
		<s:property value="#cus.mobileTel"/>
	</td>
	<td>
		<a href="${pageContext.request.contextPath}/customer_edit?id=<s:property value="#cus.cusId"/>">编辑</a>
		<a href="${pageContext.request.contextPath}/customer_delete?id=<s:property value="#cus.cusId"/>">删除</a>
	</TD>
</tr>
</s:iterator>
4、跳转Action的时候报错:

There is no Action mapped for namespace [/] and action name [xxxxxx] associated with context path [/xxxxx].
这是因为新版本的struts2用通配符时会出现的问题,所以要在Struts2的配置文件struts.xml的action标签中去配置:

<!--{1}表示第一个通配符*的表示的内容-->
<action name="customer_*" class="customerAction" method="{1}">
	<result name="方法1返回的字符串">方法1执行完想要跳转的页面</result>
	<result name="方法2返回的字符串">方法2执行完想要跳转的页面</result>
	<!--下面这个标签就是新版本struts2用来声明通配符使用的方法的,用了通配符就必须加它-->
	<allowed-methods>方法名1,方法名2</allowed-methods>
	</action>
5、Action之间的相互跳转(转发):

在Struts2的配置文件struts.xml中:

<action name="customer_*" class="customerAction" method="{1}">
	<!--这个type="chain"就是说明这是一个跳转到action的路径-->
	<result name="addSuccess" type=
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值