MVC
MVC模式(Model-View-Controller)是软件工程中的一种软件架构模式,把软件系统分为三个基本部分:模型(Model)、视图(View)和控制器(Controller)。
MVC模式最早为Trygve Reenskaug提出,为施乐帕罗奥多研究中心(Xerox PARC)的Smalltalk语言发明的一种软件设计模式。
MVC可对程序的后期维护和扩展提供了方便,并且使程序某些部分的重用提供了方便。而且MVC也使程序简化,更加直观。
控制器Controller:对请求进行处理,负责请求转发;Servlet
特点:控制器接收用户输入并调用模型和视图去完成用户的需求
视图View:界面设计人员进行图形界面设计;JSP
特点:a、视图是用户看到并与之交互的界面
b、向用户显示相关的数据
c、接受用户的输入
d、不进行任何实际的业务处理
模型Model:程序编写程序应用的功能(实现算法等等)、数据库管理;Java对象
用于处理管理数据库、处理业务逻辑、封装实体数据 JavaBean
特点:一个模型能为多个视图提供数据
注意,MVC不是Java的东西,几乎现在所有B/S结构的软件都采用了MVC设计模式。但是要注意,MVC在B/S结构软件并没有完全实现,例如在我们今后的B/S软件中并不会有事件驱动!
实现MVC购物车的绑值和加入购物车初始版:
实体类和数据库辅助类该怎么写还是怎么写
//实体类:商品类
package com.zking.mvc.cart.entity;
import java.io.Serializable;
public class Goods implements Serializable{
private static final long serialVersionUID = -2858362891359151911L;
private int gid;
private String gname;
private int gprice;
private String ginfo;
private String gpath;
private int gkc;
private String gtype;
public Goods() {
// TODO Auto-generated constructor stub
}
public Goods(int gid, String gname, int gprice, String ginfo, String gpath, int gkc, String gtype) {
super();
this.gid = gid;
this.gname = gname;
this.gprice = gprice;
this.ginfo = ginfo;
this.gpath = gpath;
this.gkc = gkc;
this.gtype = gtype;
}
public Goods(String gname, int gprice, String ginfo, String gpath, int gkc, String gtype) {
super();
this.gname = gname;
this.gprice = gprice;
this.ginfo = ginfo;
this.gpath = gpath;
this.gkc = gkc;
this.gtype = gtype;
}
public int getGid() {
return gid;
}
public void setGid(int gid) {
this.gid = gid;
}
public String getGname() {
return gname;
}
public void setGname(String gname) {
this.gname = gname;
}
public int getGprice() {
return gprice;
}
public void setGprice(int gprice) {
this.gprice = gprice;
}
public String getGinfo() {
return ginfo;
}
public void setGinfo(String ginfo) {
this.ginfo = ginfo;
}
public String