-
SSI(Struts2+Spring+Ibatis)
的简单小项目
1
、
p>
新建
web
项目
2
、
加入
jar
包
、
、
、
、
< br>
、
、
<
/p>
、
、
、
、
、
、
、<
/p>
、
3
、
写实体
bean
package
import
izable;
import
public class Student extends Page {
private int id
private
String username;
private String
password;
private String phone;
private String email;
private String address
private Page
page;
public void setPage(Page page) {
= page;
}
public int getId() {
return id;
}
public void setId(int id) {
= id;
}
public
String getUsername() {
return username;
}
public void setUsername(String
username) {
me = username;
}
public String
getPassword() {
return
password;
}
public void
setPassword(String password) {
rd = password;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
= phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
= email;
}
public String getAddress() {
return address;
}
public void setAddress(String address)
{
s = address;
}
}
package
import izable;
public class Users implements
Serializable {
private String username
;
private String password
public String getUsername() {
return username;
}
public void
setUsername(String username) {
me = username;
}
public String getPassword() {
return password;
}
public void
setPassword(String password) {
rd = password;
}
}
package
import izable;
import
public class Page{
private int
pagesize;//
单页记录
private int currentpage =
1;//
当前页面
private int
countdate;//
总记录数
private int
lastPage;//
上一页
private int
nextPage;//
下一页
private int countPage;
public int getCurrentpage()
{
return currentpage;
}
public void
setCurrentpage(int currentpage)
{
if(currentpage>getCountpage())
{
tpage = getCountpage();
}else {
if(currentpage
< 1)
{
tpage = 1;
}
else
{
tpage = currentpage;
}
}
}
public int
getPagesize() {
return
pagesize;
}
public void
setPagesize(int pagesize) {
ze
= pagesize;
}
public int
getCountdate()
{
return countdate;
}
public void setCountdate(int countdate)
{
ate =
countdate;
}
//
由记录数设定有关的页面数。
public int getCountpage()
{
int i = ate / ze;
if((ate % ze)!=0)
{
i+=1;
}
return i;
}
public int getLastPage()
{
return rentpage()-1;
}
public int getNextPage()
{
return rentpage()+1;
}
p>
//
给
ibatis
用数据
public int
getCurrent()
{
return (tpage-1)*pagesize;
}
public int getNext() {
return tpage*pagesize;
}
public int getCountPage() {
return countPage;
}
public void setCountPage(int countPage)
{
age = countPage;
}
public void setLastPage(int lastPage) {
ge = lastPage;
}
public void setNextPage(int nextPage) {
ge = nextPage;
}
}
4
、
<
/p>
编写
dao
及其实现类
< br>
package
import
import t;
public interface StudentDao
{
public boolean
saveStu(Student student);
public boolean delStu(int id);
public boolean
updateStu(Student student);
public List
public Student
queryById(int id);
public
List dimStu(Student student);
public int getCountSize(Object obj);
}
package
import eption;
import
import tedList;
import Client;
import tDao;
import t;
public
class StudentDaoImpl implements StudentDao {
private
SqlMapClient sqlMapClient;
public void
setSqlMapClient(SqlMapClient sqlMapClient) {
Client =
sqlMapClient;
}
public boolean
delStu(int id) {
try {
int i = (
if(i>0){
return true;
}else{
return false;
}
} catch (SQLException e) {
tackTrace();
return false;
}
}
public List
List list = null;
Student st = new Student();
try {
list =
orList(
} catch
(SQLException e) {
// TODO Auto-generated
catch block
tackTrace();
}
return list;
}
public Student
queryById(int id) {
Student student = null;
try {
student =
(Student) orObject(
} catch (SQLException e) {
tackTrace();
}
return student;
}
public boolean saveStu(Student student)
{
boolean b;
try {
(
b = true;
} catch (SQLException e) {
tackTrace();
b =
false;
}
return b
}
public boolean updateStu(Student
student) {
boolean b
try {
(
b = true;
} catch (Exception e) {
b =
false;
}
return b;
}
public List dimStu(Student student) {
List list =
null;
try {
list = orList(
} catch (SQLException e) {
tackTrace();
}
return list;
}
public int getCountSize(Object obj) {
int i = 0
try {
i =
(Integer)orObject(
} catch (SQLException e) {
// TODO Auto-
generated catch block
tackTrace();
}
return i
}
}
package
import
;
public interface UserDao
{
public boolean
isLogin(Users user);
}
package
import
eption;
import
import Client;
import o;
import
public
class UserDaoImpl implements UserDao {
private SqlMapClient
sqlMapClient;
public void
setSqlMapClient(SqlMapClient sqlMapClient) {
Client =
sqlMapClient;
}
public boolean
isLogin(Users user) {
try {
List
if(()>0)
{
return true;
}
}
catch (SQLException e) {
tackTrace();
}
return false;
}
}
5
、
编写服务层及其实现
package t. servcie;
import
import t;
public
interface StudentDao {
public boolean saveStu(Student
student);
public boolean
delStu(int id);
public
boolean updateStu(Student student);
public List
public Student
queryById(int id);
public
List dimStu(Student student);
public int getCountSize(Object obj);
}
package
import
;
import tDao;
import t;
import tService;
public class
StudentServiceImpl implements StudentService {
private StudentDao sdao;
public void
setSdao(StudentDao sdao) {
= sdao;
}
public boolean delStu(int id) {
boolean b = (id);
if(b){
return true;
}else{
return false;
}
}
public
List
List list = ll();
return list;
}
public Student queryById(int id) {
Student student = yId(id);
return student;
}
public
boolean saveStu(Student student) {
boolean b = u(student);
if(b){
return true;
}else{
return false;
}
}
public
boolean updateStu(Student student) {
boolean b = Stu(student);
if(b){
return true;
}else{
return false;
}
}
public
List
List list = (student);
return list;
}
public int
getCountSize(Object obj) {
return ntSize(obj);
}
}
package e;
import
public
interface UserService {
public boolean
isLogin(Users user);
}
package
import
o;
import
import rvice;
public class
UserServiceImpl implements UserService {
private UserDao udao;
public void
setUdao(UserDao udao) {
=
udao;
}
public
boolean isLogin(Users user) {
boolean b = n(user);
if(b){
return true;
}else{
return false;
}
}
}
6
、
编写<
/p>
Action
类
package
import Context;
import
Support;
import
import
tService;
import rvice;
public class UserAction extends
ActionSupport {
private
UserService us;
private Users user;
public Users getUser() {
return user;
}
public void setUser(Users
user) {
= user;
}
public
UserService getUs() {
return us;
}
public void setUs(UserService us) {
= us;
}
public String Login()
throws Exception {
String
username = rname();
String
password = sword();
boolean b = n(user);
if(b){
return
}else{
if((
text().put(
请输入用户名和密码!
}else if((
text().put(
请输入用户名
!
}else
if((
text().put(
请输入密码!
}else{
text().put(
请检查用
户名和密码!
}
return
}
}
}
package
import
import
rvletRequest;
import
tActionContext;
import
Context;
import Support;
import
import t;
import tService;
public class StudentAction extends
ActionSupport {
private
StudentService ss;
private int id;
private String username;
private String password;
private
String phone;
private String email;
private String address;
private Student student;
private
List
private Page page
;
private final static int pagesize =
3;
private int
countdate;//
总记录
public int getCountdate()
{
return countdate;
}
public void
setCountdate(int countdate) {
ate = countdate;
}
public static int
getPagesize() {
return
pagesize;
}
public Page getPage() {
return page;
}
public void setPage(Page page) {
= page;
}
public List
return list;
}
public void
setList(List
= list;
}
public Student getStudent() {
return student;
}
public void
setStudent(Student student) {
t = student;
}
public int getId() {
return id;
}
public void setId(int id) {
= id;
}
public HttpServletRequest
getRequest() {
return
request;
}
public void setRequest(HttpServletRequest request)
{
t = request;
}
public StudentService
getSs() {
return ss;
}
public void
setSs(StudentService ss) {
= ss;
}
public String getUsername() {
return username;
}
public void
setUsername(String username) {
me = username;
}
public String
getPassword() {
return
password;
}
public void setPassword(String password) {
rd = password;
}
public String getPhone()
{
return phone;
}
public void
setPhone(String phone) {
= phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
= email;
}
public String getAddress()
{
return address;
}
public void
setAddress(String address) {
s = address;
}
HttpServletRequest request = uest();
public String queryAll()
throws Exception {
List
list = ll();
if(()==0){
text().put(
没有可以显示的数据!
}else{
text().put(
}
return
}
public String updateStu()
throws Exception {
String
username = rname();
String
password = sword();
String
phone = ne();
String email
= il();
String address =
ress();
rname(username);
sword(password);
ne(phone);
il(email);
ress(address);
boolean b = Stu(student);
if (b) {
text().put(
更新成功!
return ();
} else {
text().put(
更新失败!
return
}
}
public
String queryById() throws Exception {
int id = ();
Student stu = yId(id);
text().put(
return
}
public String delete() throws
Exception {
int id = ();
boolean b = (id);
if (b) {
text().put(
删除成功!
return ();
}
else {
text().
put(
删除失败!
return
}
}
public String saveStu() throws Exception {
int id = ();
String username = rname();
String password = sword();
String phone = ne();
String email = il();
String address = ress();
(id);
rname(username);
sword(password);
ne(phone);
il(email);
ress(address);
boolean b = u(student);
if (b) {
text().put(
增加成功!
return ();
}
return
}
public String dimStu() throws
Exception {
countdate =
ntSize(new Student());
Student stu = new Student();
esize(3);
ntdate(countdate);
list = (student);
int id = 0;
(id);
text().put(
return
}
}
7
、
配置文件
xml
version
=
encoding
=
?>
<
beans
xmlns
=
xmlns:xsi
=
xmlns:aop
=
xmlns:tx
=<
/p>
xsi:schemaLocation
=
< br>
/schema/beans
/schema/beans/spring-
beans-
/schema/aop
/schema/aop/spring-
aop-2.5.
xsd
/schema/tx
/schema/tx/
d
>
< br>
<
bean
id
=
class
=
ataSource
>
-
-
-
-
-
-
-
-
-
上一篇:卡巴斯基服务器版安装
下一篇:Icinga安装配置手册