当前位置:编程学习 > JAVA >>

SpringMVC

SpringMVC+SpringJDBC+SpringTransaction


之前学习使用过Spring2.5以及和Hibernate和Struts2的集成,初步了解了Spring,业界对Spring的评价很高,我对其强大的功能只有蜻蜓点水般的体验,一直想学习接触一下Spring3.x,这会儿开始写了一个入门的SpringMVC+SpringJDBC和SpringTransaction的登陆案例,如同盲人摸象般地开始探索大象了。


至于Spring3的新特性,网上都有很多介绍,我看了,有很多东西没有实践过,所以一知半解,这里就不写了,那么就先找找感觉吧,开始我的编程之旅了...


看看我们的准备环境:
Spring3是基于JDK1.5的,对JDK1.6全面支持,所以编译Spring3.0必须使用JDK1.5以上,我用的是1.7版本的,数据库是MySQL5.0,开发工具是Meclipse8.5,。


1.工程名:spring3_learning,Jar包的准备:


这些jar包我都有上传,已经分类好了,可以直接去我的博客下载:http://download.csdn.net/detail/ysjian_pingcx/5335834


2.包结构的设计:


model包放的是与数据库有对应表的实体,vo包是一些Value Object用于辅助信息封装的,util放的是一些系统用到的工具类,controller放的是前段控制器
当模块多的时候,有必要在controller,dao,service,model前面加上模块名,便于管理和维护,此时可以讲util包加上system,
test是一个同等于src的目录,用于jUnit4测试的。


3.model的建立:
User:
[java]  package com.meritit.ysjian.spring3learning.model; 
 
import java.io.Serializable; 
import java.util.Date; 
 
public class User implements Serializable{ 
    private static final long serialVersionUID = -5271584436847697641L; 
 
    private int userId; 
 
    private String userName; 
 
    private String password; 
 
    private int credits; 
 
    private String lastIp; 
 
    private Date lastVisit; 
 
    public String getLastIp() { 
        return lastIp; 
    } 
 
    public void setLastIp(String lastIp) { 
        this.lastIp = lastIp; 
    } 
 
    public Date getLastVisit() { 
        return lastVisit; 
    } 
 
    public void setLastVisit(Date lastVisit) { 
        this.lastVisit = lastVisit; 
    } 
 
    public int getUserId() { 
        return userId; 
    } 
 
    public void setUserId(int userId) { 
        this.userId = userId; 
    } 
 
    public String getUserName() { 
        return userName; 
    } 
 
    public void setUserName(String userName) { 
        this.userName = userName; 
    } 
 
    public String getPassword() { 
        return password; 
    } 
 
    public void setPassword(String password) { 
        this.password = password; 
    } 
 
    public int getCredits() { 
        return credits; 
    } 
 
    public void setCredits(int credits) { 
        this.credits = credits; 
    } 
 
    @Override 
    public String toString() { 
        return "User [credits=" + credits + ", lastIp=" + lastIp 
                + ", lastVisit=" + lastVisit + ", password=" + password 
                + ", userId=" + userId + ", userName=" + userName + "]"; 
    } 

package com.meritit.ysjian.spring3learning.model;

import java.io.Serializable;
import java.util.Date;

public class User implements Serializable{
 private static final long serialVersionUID = -5271584436847697641L;

 private int userId;

 private String userName;

 private String password;

 private int credits;

 private String lastIp;

 private Date lastVisit;

 public String getLastIp() {
  return lastIp;
 }

 public void setLastIp(String lastIp) {
  this.lastIp = lastIp;
 }

 public Date getLastVisit() {
  return lastVisit;
 }

 public void setLastVisit(Date lastVisit) {
  this.lastVisit = lastVisit;
 }

 public int getUserId() {
  return userId;
 }

 public void setUserId(int userId) {
  this.userId = userId;
 }

 public String getUserName() {
  return userName;
 }

 public void setUserName(String userName) {
  this.userName = userName;
 }

 public String getPassword() {
  return password;
 }

 public void setPassword(String password) {
  this.password = password;
 }

 public int getCredits() {
  return credits;
 }

 public void setCredits(int credits) {
  this.credits = credits;
 }

 @Override
 public String toString() {
  return "User [credits=" + credits + ", lastIp=" + lastIp
    + ", lastVisit=" + lastVisit + ", password=" + password
    + ", userId=" + userId + ", userName=" + userName + "]";
 }
}LoginLog:
[java] package com.meritit.ysjian.spring3learning.model; 
import java.io.Serializable; 
import java.util.Date; 
 
public class LoginLog implements Serializable{ 
     
    private static final long serialVersionUID = -1764224611964600980L; 
 
    private int loginLogId; 
 
    private int userId; 
 
    private String ip; 
 
    private Date loginDate; 
 
    public String getIp() { 
        return ip; 
    } 
 
    public void setIp(String ip) { 
        this.ip = ip; 
    } 
 
    public Date getLoginDate() { 
 

补充:软件开发 , Java ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,