1月29日

抽取 接口  alt +shift+t

 

cvs2.5 安装 只需要 设置 仓库路径 

 

----------------------------------

struts2今天的点体会

 

获得struts2 action 里获得web元素 request session application 的方式 有4种 一般用如下2种  通常用ioc方式(第2种)

    第一种 通过容器获得

public class LoginAction extends ActionSupport {   
       
    private Map request;   
    private Map session;   
    private Map application;   
       
    public LoginAction1() {   
        request = (Map)ActionContext.getContext().get("request");   
        session = ActionContext.getContext().getSession();   
        application = ActionContext.getContext().getApplication();   
    }   
  
       public String execute() {   
        request.put("r1", "r1");   
        session.put("s1", "s1");   
        application.put("a1", "a1");   
        return SUCCESS;    
    }   
       
}  

 

 第2种

 

import java.util.Map;   
  
import org.apache.struts2.interceptor.ApplicationAware;   
import org.apache.struts2.interceptor.RequestAware;   
import org.apache.struts2.interceptor.SessionAware;   
  
import com.opensymphony.xwork2.ActionContext;   
import com.opensymphony.xwork2.ActionSupport;   
  
public class LoginAction extends ActionSupport implements RequestAware,SessionAware, ApplicationAware {   
       
    private Map<String, Object> request;   
    private Map<String, Object> session;   
    private Map<String, Object> application;   
       
    public String execute() {   
        request.put("r1", "r1");   
        session.put("s1", "s1");   
        application.put("a1", "a1");   
        return SUCCESS;    
    }   
  
    @Override  
    public void setRequest(Map<String, Object> request) {   
        this.request = request;   
    }   
  
    @Override  
    public void setSession(Map<String, Object> session) {   
        this.session = session;   
    }   
  
    @Override  
    public void setApplication(Map<String, Object> application) {   
        this.application = application;   
    }   
       
       
}  

 

通常 request 都被action 默认给封装了 不需要我们给出

       application也通常 用Java里面static 属性值代替了

 

ognl  用来提取 action里传过来的值 ,也可以调用其他对象属性和方法的

 

如果对象没有传值 那么调用 会是空

对象要是有空参数的构造方法、

 

<li>访问值栈中的action的普通属性: username = <s:property value="username"/> </li>
		<li>访问值栈中对象的普通属性(get set方法):<s:property value="user.age"/> | <s:property value="user['age']"/> | <s:property value="user[\"age\"]"/> | wrong: <%--<s:property value="user[age]"/>--%></li>
		<li>访问值栈中对象的普通属性(get set方法): <s:property value="cat.friend.name"/></li>
		<li>访问值栈中对象的普通方法:<s:property value="username.length()"/></li>
		<li>访问值栈中对象的普通方法:<s:property value="cat.miaomiao()" /></li>
		<li>访问值栈中action的普通方法:<s:property value="m()" /></li>
		<hr />
		<li>访问静态方法:<s:property value="@com.bjsxt.struts2.ognl.S@s()"/></li>
		<li>访问静态属性:<s:property value="@com.bjsxt.struts2.ognl.S@STR"/></li>
		<li>访问Math类的静态方法:<s:property value="@@max(2,3)" /></li>
		<hr />
		<li>访问普通类的构造方法:<s:property value="new com.bjsxt.struts2.ognl.User(8)"/></li>
		<li>访问普通类的构造方法的属性:<s:property value="new com.bjsxt.struts2.ognl.User(8).age"/></li>
		<hr />
		<li>访问List:<s:property value="users"/></li>
		<li>访问List中某个元素:<s:property value="users[1]"/></li>
		<li>访问List中元素某个属性的集合:<s:property value="users.{age}"/></li>
		<li>访问List中元素某个属性的集合中的特定值:<s:property value="users.{age}[0]"/> | <s:property value="users[0].age"/></li>
		<li>访问Set:<s:property value="dogs"/></li>
		<li>访问Set中某个元素:<s:property value="dogs[1]"/></li>  set 没顺序 所以取不到
		<li>访问Map:<s:property value="dogMap"/></li>
		<li>访问Map中某个元素:<s:property value="dogMap.dog101"/> | <s:property value="dogMap['dog101']"/> | <s:property value="dogMap[\"dog101\"]"/></li>
		<li>访问Map中所有的key:<s:property value="dogMap.keys"/></li>
		<li>访问Map中所有的value:<s:property value="dogMap.values"/></li>
		<li>访问容器的大小:<s:property value="dogMap.size()"/> | <s:property value="users.size"/> </li>
		<hr />
		<li>投影(过滤):<s:property value="users.{?#this.age==1}[0]"/></li>
		<li>投影:<s:property value="users.{^#this.age>1}.{age}"/></li>
		<li>投影:<s:property value="users.{$#this.age>1}.{age}"/></li>
		<li>投影:<s:property value="users.{$#this.age>1}.{age} == null"/></li>
		<hr />
		<li>[]:<s:property value="[0].username"/></li>

 

 

 

 

users.{?#this.age==1}[0]"  访问users这个list的的age属性里为1的 第1个 use

 

--------------------------------------------------------------------------------------------------------

ssh分页  在要分页的位置 注入 pageBean  然后在 前台给pageBean传入 我们分页的一些参数

 

在action里调用service的时候传入 已经给参数的pageBean ,得到新的 pageBean 就是分页后的结果!

 

-----------------------------------------------------------------------------------------------------------------------

明天看 struts2的 标签! 要加速了 这个速度太慢了!

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值