首页 > 编程知识 正文

mvc与springmvc的区别,springmvc怎么接收集合

时间:2023-05-04 17:58:33 阅读:40315 作者:1879

一控制器

package org.fkit.controller; import org.fkit.domain.User; importorg.spring framework.stereotype.controller; importorg.spring框架. ui.model; importorg.spring框架. ui.model map; importorg.spring帧web.bind.annotation.request mapping; //Controller注释表示该类是控制器,且多个请求操作@ controllerpublicclassmodelcontroller { @ request mapping (value='/mmin ) 用户对象的username属性user.setUsername ('疯狂软件1 ); 将用户对象添加到模型中的model.addattribute('User ',User ); 返回'结果1 '; } @ request mapping (value='/modelmaptest ' ) publicstringmodelmaptest (modelmapmodelmap ) system.out.println ) model 用户对象的username属性user.setUsername ('疯狂软件2 ); 将用户对象添加到ModelMap的modelmap.addattribute('User ',User ); 返回'结果2 '; }} 二 领域模型

package org.fkit.domain; import java.io.Serializable; //域对象,实现序列化接口的publicclassuserimplementsserializable { privatestaticfinallongserialversionuid=1l; //专用字段私有字符串日志名称; 私有字符串密码; 私有字符串用户名称; //公共生成器public User () { super ); }公共用户(字符串日志名称,字符串密码,字符串用户名称) { super ); this.loginname=loginname; this.password=password; this.username=username; } //set/get方法公共字符串get loginname () { return loginname; } publicvoidsetloginname (string loginname ) { this.loginname=loginname; }公共字符串获取密码() { return password; } publicvoidsetpassword (string password ) { this.password=password; }公共字符串getusername (() { return username; } publicvoidsetusername (string username ) { this.username=username; } @ overridepublicstringtostring ((return ' user ) loginname='loginname ',password=' password ',username=' username '] )

? XML版本=' 1.0 '编码=' utf-8 '? beans xmlns=' http://www.spring框架. org/schema/beans ' xmlns 3360 xsi=' http://www.w3.org/2001/XML方案-实例' xmlns : p=' http://www.spring framework.org/schema/p ' xmlns 3360 MVC=' http://www.spring framme MVC ' xmlns 3360 context=' http://www.spring framework.org/schema/上下文' xsi :方案位置=' http://www.spring beans 3358 www.spring framework.org/schema/beans/spring-beans. MVC 3358 spring-MVC.xsd http://www.spring framework.org/schema/context http://www.spring framework.org/schema/contexx 如果Spring -Spring自动扫描base-pack下的包或子包下的java文件,并扫描具有spring注释的类,则, 将这些类注册为spring的bean-- context 3360 component-scan base-package=' -默认组装-- mvc:annotation-driven/! ---静态资源处理----MVC :默认服务器-处理程序/-查看器p:prefix属性表示前缀p:suffix表示后缀--bean id=' view resolver ' class=' org.spring framework.web.servlework

1result1.jsp

% @ page language=' Java ' content type=' text/html; charset=utf-8 ' pageencoding=' utf-8 ' %! doctype html public '-//W3C//dtd html 4.01 transitional//en ' ' http://www.w3.org/tr/html4/loose.dtd ' html hetd 访问headbodyrequest范围中的model对象: $ { request scope.user.username }/body/html2re sername }

% @ page language=' Java ' content type=' text/html; charset=utf-8 ' pageencoding=' utf-8 ' %! doctype html public '-//W3C//dtd html 4.01 transitional//en ' ' http://www.w3.org/tr/html4/loose.dtd ' html hetd 访问headbodyrequest范围中的model对象: $ { request scope.user.username }/body/html 30

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。