public class SystemPrivilege {
private SystemPrivilegePK id;
/* 权限名称 */
@Column(length=20,nullable=false)
private String name;
...简略一部分get,set
}
public class SystemPrivilegePK implements Serializable{
private static final long serialVersionUID = -7393112044057119072L;
/* 模块名 */
@Column(length=25, name="model")
private String model;
/* 权限值 */
@Column(length=25, name="privilegeValue")
private String privilegeValue;
...简略一部分get,set
}public class PrivilegeGroup {
@Id @GeneratedValue
private Integer id;
@Column(length=20,nullable=false)
private String name;
@ManyToMany(cascade=CascadeType.REFRESH,fetch=FetchType.EAGER)
@JoinTable(name="group_privilege",joinColumns=@JoinColumn(name="groupid"),
inverseJoinColumns={@JoinColumn(name="model", referencedColumnName="model"),
@JoinColumn(name="privilegeValue", referencedColumnName="privilegeValue")})...简略一部分get,set
}现在要进行权限组增加功能。
jsp叶面如下<input type="text" name="name" size="32" maxlength="32" />
<input type="checkbox" name="privileges" value="department,delete">
部门删除
<input type="checkbox" name="privileges" value="department,insert">
部门添加
<input type="checkbox" name="privileges" value="department,update">
部门修改
<input type="checkbox" name="privileges" value="department,view">
部门查看 <br>
<input type="checkbox" name="privileges" value="privilegeGroup,delete">
权限组删除
<input type="checkbox" name="privileges" value="privilegeGroup,insert">
权限组添加
<input type="checkbox" name="privileges" value="privilegeGroup,update">
权限组修改
<input type="checkbox" name="privileges" value="privilegeGroup,view">
权限组查看
提交action中如下。是struts2框架下。接受privileges参数出问题。咨询一下。public class PrivilegeGroupManageAction {
private String name;
private SystemPrivilegePK[] privileges;
private Integer groupid;
public String addUI() throws Exception{
ActionContext.getContext().put("privileges", systemPrivilegeService.getScrollData().getResultlist());
return "add";
}
public String add() throws Exception{System.out.println(getName());
System.out.println(getPrivileges()); System.out.println("添加成功");
return "message";
}文件代码完毕!!问题如下
若action中。
private SystemPrivilegePK[] privileges;定义,则System.out.println(getPrivileges());不能输出任何内容 private String[] privileges;定义,则System.out.println(getPrivileges());能输出Ljava.lang.String;@aee320原先是struts1下,在form中定义。public class PrivilegeGroupForm extends BaseForm {
private Integer groupid;
private String name;
private SystemPrivilegePK[] privileges;则参数接受正常!请问怎么搞!?谢谢
private SystemPrivilegePK id;
/* 权限名称 */
@Column(length=20,nullable=false)
private String name;
...简略一部分get,set
}
public class SystemPrivilegePK implements Serializable{
private static final long serialVersionUID = -7393112044057119072L;
/* 模块名 */
@Column(length=25, name="model")
private String model;
/* 权限值 */
@Column(length=25, name="privilegeValue")
private String privilegeValue;
...简略一部分get,set
}public class PrivilegeGroup {
@Id @GeneratedValue
private Integer id;
@Column(length=20,nullable=false)
private String name;
@ManyToMany(cascade=CascadeType.REFRESH,fetch=FetchType.EAGER)
@JoinTable(name="group_privilege",joinColumns=@JoinColumn(name="groupid"),
inverseJoinColumns={@JoinColumn(name="model", referencedColumnName="model"),
@JoinColumn(name="privilegeValue", referencedColumnName="privilegeValue")})...简略一部分get,set
}现在要进行权限组增加功能。
jsp叶面如下<input type="text" name="name" size="32" maxlength="32" />
<input type="checkbox" name="privileges" value="department,delete">
部门删除
<input type="checkbox" name="privileges" value="department,insert">
部门添加
<input type="checkbox" name="privileges" value="department,update">
部门修改
<input type="checkbox" name="privileges" value="department,view">
部门查看 <br>
<input type="checkbox" name="privileges" value="privilegeGroup,delete">
权限组删除
<input type="checkbox" name="privileges" value="privilegeGroup,insert">
权限组添加
<input type="checkbox" name="privileges" value="privilegeGroup,update">
权限组修改
<input type="checkbox" name="privileges" value="privilegeGroup,view">
权限组查看
提交action中如下。是struts2框架下。接受privileges参数出问题。咨询一下。public class PrivilegeGroupManageAction {
private String name;
private SystemPrivilegePK[] privileges;
private Integer groupid;
public String addUI() throws Exception{
ActionContext.getContext().put("privileges", systemPrivilegeService.getScrollData().getResultlist());
return "add";
}
public String add() throws Exception{System.out.println(getName());
System.out.println(getPrivileges()); System.out.println("添加成功");
return "message";
}文件代码完毕!!问题如下
若action中。
private SystemPrivilegePK[] privileges;定义,则System.out.println(getPrivileges());不能输出任何内容 private String[] privileges;定义,则System.out.println(getPrivileges());能输出Ljava.lang.String;@aee320原先是struts1下,在form中定义。public class PrivilegeGroupForm extends BaseForm {
private Integer groupid;
private String name;
private SystemPrivilegePK[] privileges;则参数接受正常!请问怎么搞!?谢谢
解决方案 »
- 刚才看了一个关于字符串的问题,我又有了个新的问题~~~
- 取值问题
- Struts2+JasperReport结合导出WORD,PDF等问题
- 春节一直在加班,郁闷!跪求答案# An unexpected error has been detected by HotSpot Virtual Machine: # SIGSEGV (0xb) at pc=0xb6d3dbe3, pid=14454,
- 关于乱码的问题
- Java Web开发中的过滤器
- 新手求助
- 问一个特别奇怪的问题~~~~太奇怪了。。。
- 对一个实体EJB设置了ejb-ref/ejb-local-ref后有什么用?
- java中的http接口
- 能不能像移动更换套餐实现当月修改下月生效
- jsp传值到action乱码
是这样的,Struts2会自动帮你转换一些类型, 比如说基本类型,还有struts2支持的,比如说Date,Enum等等.! 如果不在这些类型范围之内, 你就要自定义转换器.!
这里你就要定义一个类型转换器.!
第一步:继承DefaultTypeConverter和StrutsTypeConverter两个类中的一个,以DefaultTypeConverter为例好了,重写convertValue(Object value, Class toType)这个方法.!
if(toType == SystemPrivilegePK[].class){
String[] str = (String[])value;
SystemPrivilegePK[] ret = new SystemPrivilegePK[str.length];
for(int i = 0; i < str.length; i++){
ret[i] = new SystemPrivilegePK(str[i].split(",")[0],str[i].split(",")[1]);
}
return ret;
}else{
//把上面的反过来搞, 把SystemPrivilegePK[]转成String,然后return
}
第二步:注册转换器
ActionClassName-conversion.properties;//action类名自己去替换,这个文件放在与action同包下.!
文件里面写上
SystemPrivilegePK的完整类名 = 转换器的完整类名 第三步 按照上面两步搞完,如果出错, 在你的页面上的checkBox的name privileges[0] 逐一加上索引访问(太久没做数组的转换器了,细节不太记得页面要不要索引访问)友情提示: 千万不要用struts2标签, 否则撞到TemplateEngineException不要怪我没提醒过你, 这是个bug
谢谢。搞定了。struts2类型转换器注册了即可。原来是struts1下,我有个类型转换器,没有起作用,还不知道。呵呵。