关于Struts2用ModelDriven传值时表关联对象的问题

满院落梅香 满院落梅香 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
最近在用Struts2做一些练习,遇到一些问题,请教各位:
前台有一个添加新闻的网页addNews.jsp

<form action="news_add" method="POST">
新闻标题:<input type="text" name="title"><br>
新闻类型:<input type="text" name="newsType"><br>
新闻正文:<input type="text" name="info"><br>
<input type="submit" value="提交">
</form>



action类

public class NewsAction extends ActionSupport implements ModelDriven<News>
{
public String add() throws Exception {
System.out.println("进入添加新闻的方法!");


System.out.println("新闻正文:"+news.getInfo());
System.out.println("新闻正文:"+news.getTitle());
// System.out.println("新闻类型:"+news.getNewsType().getTitle());
return this.SUCCESS;
}
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
return super.execute();
}
private News news = new News();
@Override
public News getModel() {
// TODO Auto-generated method stub
return news;
}

}





JavaBean:
News:int id,String title,info NewsType newsType;
NewsType:int id,String title,boolean enable
省略setter和getter方法

现在的问题是,jsp一提交控制台报错
警告: Error setting expression 'newsType' with value '[Ljava.lang.String;@151c590'
ognl.MethodFailedException: Method "setNewsType" failed for object net.news.vo.News@c7195b [java.lang.NoSuchMethodException: net.news.vo.News.setNewsType([Ljava.lang.String;)]



度娘关于Struts2传值的问题,举例都是单表,没有表关联的例子,恳请各位赐教,谢谢
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
满院落梅香
Web 开发 81,107 成员 341,720 内容