图书管理(spring+springMVC+mybatis整合)

2 篇文章 0 订阅
1 篇文章 0 订阅

对于三个框架学习以后,发现配置是一个很繁琐的过程,写一个整合记录,好让自己和需要的人学习学习.
首先用的是Oracle的数据库.
#准备工作
这是BookInfo表
这是BookInfo表
这是BookTypeInfo表
这是BookTypeInfo表
两个表的主键都是ID,有自增的序列.没有增加触发器.
用最简单的表来做框架的整合.
导入相关jar包
导入相关jar包
#开始编程

首先创建文件夹还有基本的实体类

把接口和实现分成两个包,便于以后类多的时候查找,model里面就是放Oracle对应的实体类(对应的列名还有get、set方法)
这里写图片描述
这里写图片描述

编写mybatis里面对应的mapper

先写mapper文件,待会dao的实现就是使用mapper
IBookInfoMapper文件

public interface IBookInfoMapper {
	
		//增加图书信息
		public boolean addBook(BookInfo bookInfo);
		//删除图书信息
		public boolean delBook(int id);
		//修改图书信息
		public boolean editBook(BookInfo bookInfo);
		//获取图书列表
		public List<BookInfo> getAllBook();
		//获取某本图书
		public BookInfo getBook();
}

这个是mybatis里面mapper都需要的

<!DOCTYPE mapper
 	PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
	"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

编写的BookInfoMapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
 	PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
	"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- 声明对应的接口类 -->
<mapper namespace="mapper.IBookInfoMapper">
	<!-- 编写resultMap,使用表关联column对应数据库列名,property对应类的属性名 -->
	<resultMap type="model.BookInfo" id="bookList">
		<id column="id" property="id" />
		<result column="bookName" property="bookName" />
		<result column="price" property="price" />
		<result column="author" property="author" />
		<!-- 利用association体现多对一的关系,property对应BookInfo里面的关联的属性名 -->
		<association property="bookTypeInfo" javaType="model.BookTypeInfo">
			<id column="id" property="id" />
			<result column="bookTypeName" property="bookTypeName" />
		</association>
	</resultMap>
	<!-- 查询图书列表,resultMap声明返回类型 -->
	<select id="getAllBook" resultMap="bookList">
		select b.*,bti.booktypename from BookInfo b join bookTypeInfo bti on b.booktypeId=bti.id
	</select>
	<!--查询某本图书resultMap的id属性就是之后在select中要用到的 -->
	<resultMap type="model.BookInfo" id="bookInfo">
		<id column="id" property="id"></id>
		<result column="bookName" property="bookName" />
		<result column="price" property="price" />
		<result column="author" property="author" />
		<!-- 利用association体现多对一的关系 -->
		<association property="bookTypeInfo" javaType="model.BookTypeInfo">
			<id column="bookTypeId" property="id"></id>
		</association>
	</resultMap>
	<select id="getBook" resultMap="bookInfo">
		select * from BookInfo where id = #{id}
	</select>
	
	<!--新增图书 -->
	<insert id="addBook">
		<!--使用selectKey代替触发器 -->
		<selectKey>select seq_bookId.nextval from dual</selectKey>
		<!--要接收的值用#{接收的属性名},列名有带关联的要从类对应的属性名开始 -->
		insert into bookInfo  values (#{id},#{bookTypeInfo.id},#{bookName},#{author},#{price})
	</insert>
	
	<!--删除图书 -->
	<delete id="delBook">
		delete from BookInfo where id = #{id}
	</delete>
	
	<!--修改图书 -->
	<update id="editBook">
		update BookInfo set bookTypeid =#{bookTypeInfo.id},bookName=#{bookName},author=#{author},price =#{price} where id = #{id}
	</update>
</mapper>

因为后面要用到图书类型的下拉框,所以就顺便吧IBookTypeInfoMapper和BookTypeInfoMapper.xml写了
IBookTypeInfoMapper文件:

public interface IBookTypeInfoMapper {
	//得到所有图书类型
	public List<BookTypeInfo> getBookTypeList();
}

BookTypeInfoMapper.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
 	PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
	"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="mapper.IBookTypeInfoMapper">
<!-- 查找所有图书类型,resultType代表mybatis设置的别名,之后会讲到 -->
 <select id="getAllType" resultType="bookType">
 	select * from BookTypeInfo
 </select>
</mapper>

编写dao和service(实现类加上spring注解)

IBookInfoDao和IBookInfoMapper除了类名其他都一样,这里就不写了.
BookInfoDaoImpl文件:

package dao.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import mapper.IBookInfoMapper;
import model.BookInfo;
import dao.inter.IBookInfoDao;

@Repository
public class BookInfoDaoImpl implements IBookInfoDao{

	@Autowired
	//具体由我们配置好的mybatis的mapper来实现
	private IBookInfoMapper iBookInfoMapper;
	@Override
	public boolean addBook(BookInfo bookInfo) {
		// TODO Auto-generated method stub
		return iBookInfoMapper.addBook(bookInfo);
	}

	@Override
	public boolean delBook(int id) {
		// TODO Auto-generated method stub
		return iBookInfoMapper.delBook(id);
	}

	@Override
	public boolean editBook(BookInfo bookInfo) {
		// TODO Auto-generated method stub
		return iBookInfoMapper.editBook(bookInfo);
	}

	@Override
	public List<BookInfo> getAllBook() {
		// TODO Auto-generated method stub
		return iBookInfoMapper.getAllBook();
	}

	@Override
	public BookInfo getBook(int id) {
		// TODO Auto-generated method stub
		return iBookInfoMapper.getBook(id);
	}

	
}

BookTypeInfoDaoImpl文件:

package dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import mapper.IBookTypeInfoMapper;
import model.BookTypeInfo;
import dao.inter.IBookTypeInfoDao;

@Repository
public class BookTypeInfoDaoImpl implements IBookTypeInfoDao{

	@Autowired
	private IBookTypeInfoMapper iBookTypeInfoMapper;
	@Override
	public List<BookTypeInfo> getBookTypeList() {
		// TODO Auto-generated method stub
		return iBookTypeInfoMapper.getBookTypeList();
	}

}

service里面的接口也是和dao接口一样,这里就把service的接口写到一个java类里面了
IBookService文件:

public interface IBookService{
	
	//增加图书信息
	public boolean addBook(BookInfo bookInfo);
	//删除图书信息
	public boolean delBook(int id);
	//修改图书信息
	public boolean editBook(BookInfo bookInfo);
	//获取图书列表
	public List<BookInfo> getAllBook();
	//获取某本图书
	public BookInfo getBook(int id);
	//得到所有图书类型
	public List<BookTypeInfo> getBookTypeList();
	
}

BookServiceImpl文件:
千万记得service注解要导入正确包。

import org.springframework.stereotype.Service;

@Service
public class BookServiceImpl implements IBookService {
	@Autowired
	private IBookInfoDao iBookInfoDao;
	@Autowired
	private IBookTypeInfoDao iBookTypeInfoDao;
	@Override
	public boolean addBook(BookInfo bookInfo) {
		// TODO Auto-generated method stub
		return iBookInfoDao.addBook(bookInfo);
	}

	@Override
	public boolean delBook(int id) {
		// TODO Auto-generated method stub
		return iBookInfoDao.delBook(id);
	}

	@Override
	public boolean editBook(BookInfo bookInfo) {
		// TODO Auto-generated method stub
		return iBookInfoDao.editBook(bookInfo);
	}

	@Override
	public List<BookInfo> getAllBook() {
		// TODO Auto-generated method stub
		return iBookInfoDao.getAllBook();
	}

	@Override
	public BookInfo getBook(int id) {
		// TODO Auto-generated method stub
		return iBookInfoDao.getBook(id);
	}

	@Override
	public List<BookTypeInfo> getBookTypeList() {
		// TODO Auto-generated method stub
		return iBookTypeInfoDao.getBookTypeList();
	}

}

重要的一步mybatis、spring的配置文件

src下面创建一个config存放配置文件
mybatis.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
    PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
	<typeAliases>
		<typeAlias type="model.BookInfo" alias="book" />
		<typeAlias type="model.BookTypeInfo" alias="bookType" />
	</typeAliases>
	<mappers>
		<mapper resource="mapper/BookMapper.xml" />
		<mapper resource="mapper/BookTypeMapper.xml" />
	</mappers>
</configuration>

src根目录直接放spring配置文件beans.xml省的配置
beans.xml文件(一般要改的地方就数据库的datasource还有spring注解扫描的包):

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="  
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd  
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd  
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd  
">
	<!-- 配置数据库datasource -->
	<bean id="dataSource"
		class="org.springframework.jdbc.datasource.DriverManagerDataSource">
		<property name="driverClassName">
			<value>oracle.jdbc.driver.OracleDriver</value>
		</property>
		<property name="url">
			<value>jdbc:oracle:thin:@localhost:1521:ORCLDB</value>
		</property>
		<property name="username">
			<value>scott</value>
		</property>
		<property name="password">
			<value>root</value>
		</property>
	</bean>
	<!-- SqlSesessionFactory -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<!--配置mybatis文件路径 -->
		<property name="configLocation" value="classpath:/config/mybatis.xml"></property>
		<property name="dataSource" ref="dataSource" />
	</bean>
	<!-- 将mapper接口生成实体类的bean -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="mapper"/>
		<property name="sqlSessionFactory" ref="sqlSessionFactory" />
	</bean>
	<!-- 注解式的扫描包 -->
	<context:component-scan base-package="dao"></context:component-scan>
	<context:component-scan base-package="service"></context:component-scan>
</beans>

接下来就是测试了

写了那么久终于能测试下了555.
吐血,之前配置的BookMapper.xml里面的查找某本图书少了resultMap的声明,因为一次性写的所以找了挺久的.希望读到这篇文章的童鞋一定注意不要这样一口气在mapper里面写那么多方法,可以一个一个来,不然其中一个有问题所有的都不能运行.
放上我的测试类:

public class BookTest {

	//测试新增图书信息
	@Test
	public void addBook(){
		ApplicationContext ac =new ClassPathXmlApplicationContext("beans.xml");
		IBookService bs = ac.getBean("bookService",IBookService.class);
		BookInfo bi  = new BookInfo();
		bi.setAuthor("藤子不二雄3");
		bi.setBookName("机器猫");
		BookTypeInfo bti = new BookTypeInfo();
		bti.setId(5);
		bi.setBookTypeInfo(bti);
		bi.setPrice(35.5);
		try{
			bs.addBook(bi);
			System.out.println("ok");
		}catch(Exception e ){
			e.printStackTrace();
		}
	}
	//测试更改图书信息
	@Test
	public void updateBook(){
		ApplicationContext ac =new ClassPathXmlApplicationContext("beans.xml");
		IBookService bs = ac.getBean("bookService",IBookService.class);
		BookInfo bi  = new BookInfo();
		bi.setId(5);
		bi.setAuthor("测试3");
		bi.setBookName("机器猫");
		BookTypeInfo bti = new BookTypeInfo();
		bti.setId(5);
		bi.setBookTypeInfo(bti);
		bi.setPrice(35.5);
		try{
			bs.editBook(bi);
			System.out.println("ok");
		}catch(Exception e ){
			e.printStackTrace();
		}
	}
	//测试查询所有图书
	@Test
	public void selAllBook(){
		ApplicationContext ac =new ClassPathXmlApplicationContext("beans.xml");
		IBookService bs = ac.getBean("bookService",IBookService.class);
		try{
			List<BookInfo> li =bs.getAllBook();
			for(BookInfo bi:li){
				System.out.println(bi.getAuthor()+"   :"+bi.getBookName()+"  "+bi.getBookTypeInfo().getBookTypeName());
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	//测试查找指定图书
	@Test
	public void getOneBook(){
		ApplicationContext ac =new ClassPathXmlApplicationContext("beans.xml");
		IBookService bs = ac.getBean("bookService",IBookService.class);
		try{
			BookInfo bi =null;
			bi =bs.getBook(2);
			if(bi!=null)
			System.out.println(bi.getAuthor()+"   :"+bi.getBookName());
			else 
				System.out.println("kong ");
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	//测试删除特定图书
	@Test
	public void delBook(){
		ApplicationContext ac =new ClassPathXmlApplicationContext("beans.xml");
		IBookService bs = ac.getBean("bookService",IBookService.class);
		try{
			boolean flag =false;
			flag =bs.deleteBook(5);
			if(flag)
				System.out.println("删除成功");
			else 
				System.out.println("删除失败");
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	@Test
	public void  getAllType(){
		ApplicationContext ac =new ClassPathXmlApplicationContext("beans.xml");
		IBookService bs = ac.getBean("bookService",IBookService.class);
		try{
			List<BookTypeInfo> list = bs.getAllType();
			for(BookTypeInfo bti :list){
				System.out.println(bti.getId()+"  :" +bti.getBookTypeName());
			}
		}catch(Exception e ){
			e.printStackTrace();
		}
	}
}

接下来就准备到视图

配置spring、springMVC有关的web.xml##

 <!-- 加载spring容器 -->
  <listener>
<listener-class>
	org.springframework.web.context.ContextLoaderListener
</listener-class>
  </listener>
  <!-- 设置spring容器加载所有的配置文件的路径 -->
  <context-param>
  	<param-name>contextConfigLocation</param-name>
  	<param-value>classpath*:beans.xml</param-value>
  </context-param>
  <!-- 防止spring内存溢出监听器 -->
  <listener>
  	<listener-class>
  		org.springframework.web.util.IntrospectorCleanupListener
  	</listener-class>
  </listener>
  <!-- 配置springmvc的核心控制器 -->
  <servlet>
	  <servlet-name>springMVC</servlet-name>
	  <servlet-class>
		org.springframework.web.servlet.DispatcherServlet
	  </servlet-class>
	  <!-- 设置配置文件的位置 -->
	  <init-param>
		  <param-name>contextConfigLocation</param-name>
		  <param-value>classpath*:config/spring-mvc.xml</param-value>
	  </init-param>
	  <!-- 启动的时候加载一次 -->
	  <load-on-startup>1</load-on-startup>
  </servlet>
  
  <!-- 进行mapping过滤 -->
  <servlet-mapping>
  <servlet-name>springMVC</servlet-name>
  <url-pattern>/</url-pattern>
  </servlet-mapping>

  <!-- 配置编码过滤 -->
  <filter>
  <filter-name>encodingFilter</filter-name>
  <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  <init-param>
  <param-name>encoding</param-name>
  <param-value>utf-8</param-value>
  </init-param>
  </filter>
  <filter-mapping>
  <filter-name>encodingFilter</filter-name>
  <url-pattern>/*</url-pattern>
  </filter-mapping>

接下来写springMVC的配置文件
因为我在web.xml配置了文件名,文件路径,所以就不需要有配置文件的默认限制了.
在配置好的config里面配置spring-mvc.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans.xsd
	http://www.springframework.org/schema/context
	http://www.springframework.org/schema/context/spring-context-4.0.xsd
	http://www.springframework.org/schema/mvc
	http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
	
	<context:component-scan base-package="controller"></context:component-scan>
	 <!-- 开启注解 -->
	 <mvc:annotation-driven/>
	 
	 <!-- 配置静态资源,配置这个在jsp引用js等文件的时候要记得都放在WEB-INF下面的相对文件夹.如用js文件,路径就是../js/文件名 -->
	 <mvc:resources mapping="/js/**" location="/WEB-INF/js/"/>
     <mvc:resources mapping="/css/**" location="/WEB-INF/css/"/>
     <mvc:resources mapping="/images/**" location="/WEB-INF/images/"/>
	 <mvc:resources location="/WEB-INF/html/" mapping="/html/**"/>
	 
	 <!-- 配置视图 -->
	 <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
	 <property name="prefix" value="/WEB-INF/jsp/"></property>
	 <property name="suffix" value=".jsp"></property>
	 </bean>
</beans>

写对应的jsp页面

book_add.jsp:

<body>
<h2>新增图书</h2>
<form action="addBook" method="post">
<table>
	<tr>
		<td>书名</td><td>作者</td><td>价格</td><td>图书类型</td>
	</tr>
	<tr>
		<td><input name="bookName" type="text"></td>
		<td><input name="author" type="text"></td>
		<td><input name="price" type="text"></td>
		<td>
			<select name="bookTypeInfo.id">
			<c:forEach  items="${list}" var="bookType">
				<option value="${bookType.id }">${bookType.bookTypeName }</option>
			</c:forEach>
			</select>
		</td>
	</tr>
	<tr align="center">
		<td colspan="4"><input type="submit" value="提交"></td>
	</tr>
</table>
</form>
</body>

book_edit.jsp:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="../js/jquery-1.9.0.min.js"></script>
<script>
$(document).ready(function (){
	$("#sub").click(function (){
		var book =$("#BookInfo").serializeArray(); 
		var str = JSON.stringify(book);
		alert(str);
			$.post("editBook",book,function(tip){
				if(tip=='succeed'){
				 window.location = "bookList";
				}else{
					alert("修改失败");
				}
			});
	});
});
</script>
</head>
<body>
<h2>修改图书${book.bookTypeInfo.id }</h2>
<form id="BookInfo" action="" method="post">
<table>
	<tr>
		<td>书名</td><td>作者</td><td>价格</td><td>图书类型</td>
	</tr>
	<tr>
		<td style="display: none;"><input name="id" value="${book.id }" type="text"></td>
		<td><input name="bookName" value="${book.bookName }" type="text"></td>
		<td><input name="author" value="${book.author}" type="text"></td>
		<td><input name="price" value="${book.price}" type="text"></td>
		<td>
			<select  name="bookTypeInfo.id">
			<c:forEach  items="${list}" var="bookType" >	
				<c:choose>
					<c:when test="${bookType.id ==book.bookTypeInfo.id }">
						<option   value="${bookType.id }" selected="selected"> ${bookType.bookTypeName }</option>
					</c:when>
					<c:otherwise>
						<option   value="${bookType.id }" >${bookType.bookTypeName }</option>	
					</c:otherwise>
				</c:choose>
			</c:forEach>
			</select>
		</td>
	</tr>
	<tr align="center">
		<td colspan="4"><input id="sub" type="button" value="提交"></td>
	</tr>
</table>
</form>
</body>
</html>

book_list.jsp:

<body>
<table>
	<tr>
		<td>书名</td><td>作者</td><td>价格</td><td>类型</td><td colspan="2">操作</td>
	</tr>
	<c:forEach items="${list }" var="book">
		<tr>
			<td>${book.bookName}</td>
			<td>${book.author}</td>
			<td>${book.price}</td>
			<td>${book.bookTypeInfo.bookTypeName}</td>
			<td><a href="toEditBook?id=${book.id }">编辑</a></td>
			<td><a href="delBook?id=${book.id }">删除</a></td>
		</tr>
	</c:forEach>
</table>
<a href="toaddBook">新增</a>
</body>

failed_delete.jsp:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>error</title>
</head>
<body style="margin: 0 auto;">
	<h1 >Delete Book Failed</h1>
</body>
</html>

springMVC的controller

src创建controller包,创建BookController

package controller;

import java.util.List;
import model.BookInfo;
import model.BookTypeInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import service.inter.IBookService;


@RequestMapping("book")
@Controller
public class BookController {
	
	@Autowired
	private IBookService bookService;
	@RequestMapping("bookList")
	/**
	 * 获取图书列表并转到页面
	 * @return
	 */
	public ModelAndView showList(){
		List<BookInfo> li = null;
		try{
			li =bookService.getAllBook();
			
		}catch(Exception e){
			e.printStackTrace();
		}
		return new ModelAndView("book_list","list",li);
	}
	
	@RequestMapping("toaddBook")
	/**
	 * 获取所有图书类型并转到页面
	 * @return
	 */
	public ModelAndView toAddBookView(){
		List<BookTypeInfo> li=null;
		try{
			li =bookService.getBookTypeList();
			
		}catch(Exception e){
			e.printStackTrace();
		}
		return new ModelAndView("book_add","list" ,li);
	}
	
	@RequestMapping("addBook")
	/**
	 * 图书新增
	 * @param bi
	 * @return
	 */
	public String  toAddBookView(BookInfo bi){
		try{
			System.out.println(bi.getBookName());
			bookService.addBook(bi);
		}catch(Exception e){
			e.printStackTrace();
		}
		return "redirect:bookList";
	}
	@RequestMapping("toEditBook")
	/**
	 * 这个方法用来把图书对象加入到request然后转到toEdit
	 * @param id
	 * @param redirectAttributes
	 * @return
	 */
	public String toEditBook(int id ,RedirectAttributes redirectAttributes){
		
		BookInfo bi =bookService.getBook(id);
		//相当于在这次的request里面加一个属性
		redirectAttributes.addFlashAttribute("book",bi);
		
		return "redirect:toEdit";
	}
	@RequestMapping("toEdit")
	/**
	 * 获取图书类型然后转到book_edit页面
	 * @return
	 */
	public ModelAndView toEditBook(){
		List<BookTypeInfo> li=null;
		try{
			li =bookService.getBookTypeList();
			
		}catch(Exception e){
			e.printStackTrace();
		}
		return new ModelAndView("book_edit","list" ,li);
	}
	@RequestMapping("editBook")
	@ResponseBody
	/**
	 * 修改方法
	 * @param book
	 * @return
	 */
	public String editBook(BookInfo book){
		try{
			bookService.editBook(book);
			return "succeed";
		}catch(Exception e){
			e.printStackTrace();
		}
		return "falied";
	}
	@RequestMapping("delBook")
	/**
	 * 删除方法
	 * @param id
	 * @return
	 */
	public String delBook(int id){
		boolean flag=false;
		try{
			bookService.delBook(id);
			flag = true;
		}catch(Exception e){
			e.printStackTrace();
		}
		if(flag){
			return "redirect:bookList";
		}else{
			return "failed_delete";
		}
	}
}

最后把我的包和类都截图下
这里写图片描述
整合到这完毕.功能测试成功!哈哈.不过码代码累啊,第一次写整合帖,还出错了.不过经验也学到了,希望能给需要的童鞋一点启发.整个项目我会发上来.给需要的人.
不知道怎么取消下载的积分,=-= 太久没来博客。sorry
源码地址: https://download.csdn.net/download/a526059967/9704924#comment

或者百度云链接:https://pan.baidu.com/s/15xLbN_x5mr68A-jxpUQs2A 提取码:BYcG

评论 12 您还未登录,请先 登录 后发表或查看评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:编程工作室 设计师:CSDN官方博客 返回首页

打赏作者

迷失d_e章鱼

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值