struts2与Mybatis整合

一.导入jar包

本人使用myeclipsep2013版本 ,jdk1.8, tomcat8.0版本

二.配置web.xml

struts2各种版本号不同,web.xml的配置也就不同,本人使用的是2.5版本。

三.写实体类

本人以Users类和Goods类为例:通过用户登录进入到商品页面

package com.ybb.entity;

public class Goods {
 private int id;
 private String name;
 private double price;
 public int getId() {
  return id;
 }
 public void setId(int id) {
  this.id = id;
 }
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public double getPrice() {
  return price;
 }
 public void setPrice(double price) {
  this.price = price;
 }
 public Goods(int id, String name, double price) {
  super();
  this.id = id;
  this.name = name;
  this.price = price;
 }
 public Goods() {
  super();
  // TODO Auto-generated constructor stub
 }
 
}

package com.ybb.entity;

public class Users {
 private int id;
 private String userName;
 private String pass;
 
 
 public int getId() {
  return id;
 }
 public void setId(int id) {
  this.id = id;
 }
 public String getUserName() {
  return userName;
 }
 public void setUserName(String userName) {
  this.userName = userName;
 }
 public String getPass() {
  return pass;
 }
 public void setPass(String pass) {
  this.pass = pass;
 }
 public Users(int id, String userName, String pass) {
  super();
  this.id = id;
  this.userName = userName;
  this.pass = pass;
 }
 public Users() {
  super();
  // TODO Auto-generated constructor stub
 }
}

四.mybatis

猜你喜欢

转载自blog.csdn.net/ybb520chongren_/article/details/82079825