以下例子只是举个例子,不要较真~
新手初学struts2,感觉前台jsp页面只要写成:
账号:那么我在后台的struts2中的action只要将其name写成private属性,在前台提交表单后,我后台再给其个get和set方法,就能得到了,如:
private UserService userService;//service层
private String username;// 账号
private String password;// 密码
private int num;//正整数
private String hide;
省略相应的get和set方法......
int newnum1 = Integer.paseInt("hide");
int newnum2 = nenum1+num;
User user = new User(username,password,newnum2);
boolean flag = userService.regist(user);//调用service层的注册方法
if(flag==true){
return "success";
}else{
returm "false";
}
private String hide; 也可以改成private int hide;
struts2的数据填充可以:
1、private 字段 然后带有getter/setter
2、public 字段
3、ModelDriven
它们都是使用OGNL完成数据填充
建议,学习:
BeanUtils 最简单的数据填充包
OGNL 功能更强大
学struts2 downpour的资料非常不错
[url]http://www.iteye.com/topic/295414[/url]
[code="java"]初学的很不错哦 :lol: [/code]
private String hide; int newnum1 = Integer.paseInt("hide");,我觉得这两行代码,可以写成一行:你只要在action中些成如下形式:private Integer hide,页面传过来的值struts2会根据类型转换成integer,你没必要在自己讲string类型转换为integer