主页面
http://localhost:8080/book/index.jsp
index.jsp页面代码
<%@ page language="java" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>图书管理页面</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<a href="addBook.jsp">添加图书</a>
<a href="book/viewSBook.action">浏览图书</a>
</body>
</html>
浏览图书操作
http://localhost:8080/book/book/viewSBook.action
viewBook.jsp页面代码
<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>浏览图书</title>
</head>
<body>
<table align="center" border="1" style="width:80%;">
<tr>
<th colspan="7" align="center">库存图书</th>
</tr>
<tr>
<td align="left" colspan="7"><a href="<%=request.getContextPath()%>/addBook.jsp">添加新书</a></td>
</tr>
<tr>
<td>书名</td>
<td>作者</td>
<td>价格</td>
<td>库存量</td>
<td>ISBN号</td>
<td>出版社</td>
<td>操作</td>
</tr>
<s:iterator value="bookList">
<tr>
<td>
<s:property value="title"/>
</td>
<td>
<s:property value="author"/>
</td>
<td>
<s:property value="price"/>
</td>
<td>
<s:property value="total"/>
</td>
<td>
<s:property value="isbn"/>
</td>
<td>
<s:property value="publisher"/>
</td>
<td>
<a href="<%=request.getContextPath()%>/sbook/modifySBook.action?bookId=${id}">修改信息</a>
<a href="<%=request.getContextPath()%>/sbook/removeSBook.action?bookId=${id}">删除</a>
</td>
</tr>
</s:iterator>
<s:property value="tips"/>
</table>
</body>
</html>
点击修改按钮则进入修改页面
bookMsg.jsp页面代码
<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>修改图书信息</title>
</head>
<body>
<s:form action="/sbook/updateSBook.action">
<s:hidden name="sbook.id">${id}</s:hidden>
<s:textfield name="sbook.title" label="书名" readonly="true">${title}</s:textfield>
<s:textfield name="sbook.author" label="作者">${author}</s:textfield>
<s:textfield name="sbook.price" label="价格">${price}</s:textfield>
<s:textfield name="sbook.total" label="总量">${total}</s:textfield>
<s:textfield name="sbook.isbn" label="ISBN">${isbn}</s:textfield>
<s:textfield name="sbook.publisher" label="出版社">${publisher}</s:textfield>
<s:submit/>
</s:form>
<s:property value="tips" />
</body>
</html>
点击删除操作,直接将对应记录删除
增加操作
http://localhost:8080/book/addBook.jsp
addBook.jsp页面代码
<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>添加图书</title>
</head>
<body>
<s:property value="tips"/>
<s:form action="addSBook" >
<s:textfield name="sbook.title" label="书名"/>
<s:textfield name="sbook.author" label="作者"/>
<s:textfield name="sbook.price" label="价格"/>
<s:textfield name="sbook.total" label="数量"/>
<s:textfield name="sbook.isbn" label="ISBN号"/>
<s:textfield name="sbook.publisher" label="出版社"/>
<s:submit value="添加"/>
</s:form>
<a href="<%=request.getContextPath() %>/viewSBook.action">查看现有图书</a>
</body>
</html>
配置struts.xml文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<include file="struts-default.xml" />
<package name="book" extends="struts-default" >
<!-- 添加图书信息 -->
<action name="addSBook" class="com.dou.book.action.SBookAction" method="addSBook">
<result name="success">/success.jsp</result>
<result name="error">/error.jsp</result>
</action>
<!-- 查看全部图书信息 -->
<action name="viewSBook" class="com.dou.book.action.SBookAction" method="viewSBook">
<result name="success">/viewBook.jsp</result>
<result name="error">/error.jsp</result>
</action>
<!-- 修改指定图书信息 -->
<action name="modifySBook" class="com.dou.book.action.SBookAction" method="modifySBook">
<result name="success">/bookMsg.jsp</result>
<result name="error">/error.jsp</result>
</action>
<!-- 修改指定图书信息 -->
<action name="updateSBook" class="com.dou.book.action.SBookAction" method="updateSBook">
<result name="success">/success.jsp</result>
<result name="error">/error.jsp</result>
</action>
<!-- 删除指定图书信息 -->
<action name="removeSBook" class="com.dou.book.action.SBookAction" method="removeSBook">
<result name="success">/success.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
</struts>
实现com.dou.book.action.SBookAction类中的addSBook方法
package com.dou.book.action;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.dou.book.data.pojo.SBook;
import com.dou.book.data.services.ISBookServices;
@SuppressWarnings("unchecked")
public class SBookAction {
@Autowired
ISBookServices bookServices;
private SBook sbook;
private String tips;
private String bookId;
private List bookList;
/**
* 添加图书信息
*
* @return 返回添加是否成功
*/
public String addSBook() {
String result = "error";
try {
bookServices.saveBook(sbook);
this.setTips("添加成功");
result = "success";
} catch (Exception e) {
e.printStackTrace();
this.setTips("系统出现问题");
}
return result;
}
/**
* 查看所有图书
*
* @return
*/
public String viewSBook() {
String result = "error";
try {
bookList = bookServices.findAllBook();
result = "success";
} catch (Exception e) {
e.printStackTrace();
this.setTips("系统出现问题,请稍后访问");
}
return result;
}
/**
* 修改图书信息
*
* @return
*/
public String modifySBook() {
String result = "error";
try {
sbook = bookServices.getBookById(Integer
.parseInt(this.getBookId()));
result = "success";
} catch (Exception e) {
e.printStackTrace();
this.setTips("系统出现问题");
}
return result;
}
public String updateSBook() {
String result = "error";
try {
bookServices.updateBook(sbook);
result = "success";
} catch (Exception e) {
e.printStackTrace();
this.setTips("更新操作失败");
}
return result;
}
/**
* 删除图书
*
* @return
*/
public String removeSBook() {
String result = "error";
try {
bookServices.removeBook(Integer.parseInt(this.getBookId()));
result = "success";
} catch (Exception e) {
e.printStackTrace();
this.setTips("删除操作失败");
}
return result;
}
public SBook getSbook() {
return sbook;
}
public void setSbook(SBook sbook) {
this.sbook = sbook;
}
public List getBookList() {
return bookList;
}
public void setBookList(List bookList) {
this.bookList = bookList;
}
public String getTips() {
return tips;
}
public void setTips(String tips) {
this.tips = tips;
}
public String getBookId() {
return bookId;
}
public void setBookId(String bookId) {
this.bookId = bookId;
}
}
分享到:
相关推荐
struts2+spring+mybatis增删改查小例子,适合初学者学习
Spring+Struts2+Mybatis的一个增删改查的例子,本例子使用 Spring+Struts2 + Mybatis 框架整合,实现了对用户表数据的增、删、改、查的功能, 基于 Spring 注解实现, 省去了 Spring 繁琐的 bean 手工配置。
用MyBatis+struts2+spring+mysql整合增删改查,简单的项目,希望对新学习同学有所帮助
基于myesplice2014环境 ,jdk1.7 ,简单的struts2+spring+mybatis的增删查改操作
Struts2+Mybatis+Spring整合增删改查实例,采用annotation注解实现
本例子使用 Spring+Struts2 + Mybatis 框架整合,实现了用户登录,对用户表数据的增、删、改、查的功能, 基于 Spring 注解实现, 省去了 Spring 繁琐的 bean 手工配置。
(SSM框架集成)spring+struts2+mybatis三大框架集成实现用户的增删改查入门操作案例!
Struts2SpringMybatis 增删改查,里面的Struts2,spring,Mybatis配置文件都是模块化的管理,实现了社会版本的配置,不再是个人玩弄的小项目。具体的 sql语句也已经加到了WEBRROT目录下面了,自己下载下来可以详细看...
Struts+Spring+Mybatis+EasyUI(jQuery)注解案例。采用注解的方式跟踪代码依赖性,实现替代配置文件功能。里面包含了平时用的增删改查及分页,分页查询时用的是存储过程,提高了数据库的性能。代码简单、易懂。
MyBatis+Struts2+Spring+mysql 开发的一套小型管理系统,以及Jquery 实现显示 界面简洁大方,功能完整! 代码都有注解 容易看懂
适用于初学者理解spring、struts2、mybatis,使用oracle数据库,实现单表增删改查、条件查询和分页、文件上传
SSM框架整合,使用最新版MyBatis-Jar包(Struts2.1+Spring3.0+MyBatis3.06) 下载之后执行.sql文件创建表和sequence ... 项目访问路径 localhost:8080/SSI_Demo...用户的增删改查操作,依赖注入和注解事物管理,适合初学者...
SSM资源SSM资源SSM资源SSM资源SSM资源SSM资源SSM资源SSM资源SSM资源SSM资源
strusts2+spring + ibatis框架增删改查,主要是对三个框架的操作练习。包含jar包。
该项目比较适合初学者,里面都是一些比较简单,容易理解的知识!
使用struts+spring+mybatis框架组合写的一个增删改查的web项目
mybatis+spring+struts2 使用oracle数据库 增删改查,是把csdn原先的mysql数据库改成oracle数据库,直接在myeclipse上导入就行,并添加数据库myuser表,还有id,username,password等字段,压缩包下又myuser用记事本...
spring3.0+struts2+mybatis3.0整合 增,删,查,改,like查询
mybatis+struts+spring增删改查示例新近完成的!适合新手,就四个字段!所需jar,都有截图,myeclipse自带的jar没有,别的jar都有!