基于ssm开发网上书店系统

基于ssm的书店管理系统

适合学习
开发工具:MyEclipse2014 / IDEA
Java版本:JDK 1.8
服务器:tomcat 8.0
数据库:MySQL 5.6
系统采用技术:Spring+SpringMVC+Mybatis+jQuery+bootstrap+Ajax+maven+面向接口编程

项目代码
package com.lxhf.service.impl;

import java.util.List;

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

import com.lxhf.constants.Constants;
import com.lxhf.bean.Book;
import com.lxhf.bean.Page;
import com.lxhf.mapper.BookMapper;
import com.lxhf.service.BookService;

@Service
public class BookServiceImpl implements BookService {

@Autowired
private BookMapper bookMapper;

@Override
public List<Book> findBookAll() {
	return bookMapper.findBookAll();
}

@Override
public void addBook(Book book) {
	bookMapper.addBook(book);

}

@Override
public void deleteBook(Integer id) {
	bookMapper.deleteBook(id);
}

@Override
public void deleteBookByCategoryId(Integer categoryId) {
	bookMapper.deleteBookByCategoryId(categoryId);
}

@Override
public void updateBook(Book book) {

	bookMapper.updateBook(book);
}

@Override
public Book getBookById(Integer id) {
	return bookMapper.getBookById(id);
}

@Override
public Page findPageBook(Integer current) {

	int count = bookMapper.getCount();
	int totalPage = count % Constants.PAGESIZE == 0 ? count / Constants.PAGESIZE
			: count / Constants.PAGESIZE + 1;

	List<Book> books = bookMapper.findPage((current - 1) * Constants.PAGESIZE, Constants.PAGESIZE);
	Page page = new Page(totalPage, books);

	return page;
	
}

@Override
public Page findPageCategory(Integer categoryId, Integer current) {

	int categoryCount = bookMapper.getCategoryCount(categoryId);
	// totalPage 鎬婚〉鏁�
	int totalPage = categoryCount % Constants.CATEGORYPAGESIZE == 0 ? categoryCount / Constants.CATEGORYPAGESIZE
			: categoryCount / Constants.CATEGORYPAGESIZE + 1;

	List<Book> books = bookMapper.findPageCategory(categoryId, (current - 1) * Constants.CATEGORYPAGESIZE,
			Constants.CATEGORYPAGESIZE);


	Page page = new Page(totalPage, books);

	return page;
}

@Override
public Page findPageBookByName(String name, Integer current) {
	int nameCount = bookMapper.getNameCount(name);
	int totalPage = nameCount % Constants.PAGESIZE == 0 ? nameCount / Constants.PAGESIZE
			: nameCount / Constants.PAGESIZE + 1;

	List<Book> books = bookMapper.findPageBookByName(name, (current - 1) * Constants.PAGESIZE, Constants.PAGESIZE);
	Page page = new Page(totalPage, books);

	return page;
}

@Override
public Page findPageBookByAuthor(String author, Integer current) {
	int authorCount = bookMapper.getAuthorCount(author);
	int totalPage = authorCount % Constants.PAGESIZE == 0 ? authorCount / Constants.PAGESIZE
			: authorCount / Constants.PAGESIZE + 1;

	List<Book> books = bookMapper.findPageBookByAuthor(author, (current - 1) * Constants.PAGESIZE,
			Constants.PAGESIZE);
	Page page = new Page(totalPage, books);

	return page;
}

@Override
public Page findPageBookByDesc(String desc, Integer current) {
	int descCount = bookMapper.getDescCount(desc);
	int totalPage = descCount % Constants.PAGESIZE == 0 ? descCount / Constants.PAGESIZE
			: descCount / Constants.PAGESIZE + 1;

	List<Book> books = bookMapper.findPageBookByDesc(desc, (current - 1) * Constants.PAGESIZE, Constants.PAGESIZE);
	Page page = new Page(totalPage, books);

	return page;
}

@Override
public Page findPageBookByCName(String relatedField, Integer current) {
	int cNameCount = bookMapper.getCNameCount(relatedField);
	int totalPage = cNameCount % Constants.PAGESIZE == 0 ? cNameCount / Constants.PAGESIZE
			: cNameCount / Constants.PAGESIZE + 1;

	List<Book> books = bookMapper.findPageBookByCName(relatedField, (current - 1) * Constants.PAGESIZE,
			Constants.PAGESIZE);
	Page page = new Page(totalPage, books);

	return page;
}

@Override
public Page findPageBookByCDesc(String relatedField, Integer current) {
	int cDescCount = bookMapper.getCDescCount(relatedField);
	int totalPage = cDescCount % Constants.PAGESIZE == 0 ? cDescCount / Constants.PAGESIZE
			: cDescCount / Constants.PAGESIZE + 1;

	List<Book> books = bookMapper.findPageBookByCDesc(relatedField, (current - 1) * Constants.PAGESIZE,
			Constants.PAGESIZE);
	Page page = new Page(totalPage, books);
	return page;
}

@Override
public Page findPageBookByAll(String relatedField, Integer current) {
	int allCount = bookMapper.getAllCount(relatedField);
	int totalPage = allCount % Constants.PAGESIZE == 0 ? allCount / Constants.PAGESIZE
			: allCount / Constants.PAGESIZE + 1;

	List<Book> books = bookMapper.findPageBookByAll(relatedField, (current - 1) * Constants.PAGESIZE,
			Constants.PAGESIZE);
	Page page = new Page(totalPage, books);

	return page;
}

@Override
public Page findPageBookByPress(String relatedField, Integer current) {
	int pageCount = bookMapper.getPressCount(relatedField);
	int totalPage = pageCount % Constants.PAGESIZE == 0 ? pageCount / Constants.PAGESIZE
			: pageCount / Constants.PAGESIZE + 1;

	List<Book> books = bookMapper.findPageBookByPress(relatedField, (current - 1) * Constants.PAGESIZE,
			Constants.PAGESIZE);
	Page page = new Page(totalPage, books);

	return page;
}

}

package com.lxhf.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lxhf.bean.CarItem;
import com.lxhf.mapper.CarMapper;
import com.lxhf.service.CarService;

@Transactional(rollbackFor = Exception.class)
@Service
public class CarServiceImpl implements CarService {

@Autowired
CarMapper carMapper;

//query caritem in caritem
@Override
public CarItem findCarItemByIdandCustomerId(Integer id,Integer customerid) {
	
	return carMapper.findCarItemByBookIdandCustomerId(id,customerid);
}

//insert in caritem
@Override
public void insertCarItem(CarItem caritem) {
	carMapper.insertOneCarItem(caritem);
	
}

//update caritem's num and money
@Override
public void updateCarItemNumandMoney(Integer id,float money ,int num) {
	
	carMapper.updateNumandMoney(id,money,num);
}

//find CarItem By CustomerId
@Override
public List<CarItem> findCarItemByCustomerId(Integer customerid) {
	List<CarItem> list= carMapper.findCarItemByCustomerId(customerid);
	if(list!=null)
		return list;
	return null;
}


//delete CarItem By CustomerId
@Override
public void deleteCarItemByCustomerId(Integer customerid) {
	carMapper.deleteByCustomerId(customerid);
}

@Override
public void deleteCarItemById(Integer id) {
	carMapper.deleteById(id);
	
}

}

<?xml version="1.0" encoding="UTF-8"?>

<!-- 加载配置文件 -->
<context:property-placeholder location="classpath:db.properties" />
<!-- 数据库连接池 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
	destroy-method="close">
	<property name="driverClassName" value="${jdbc.driver}" />
	<property name="url" value="${jdbc.url}" />
	<property name="username" value="${jdbc.username}" />
	<property name="password" value="${jdbc.password}" />
	<property name="maxActive" value="10" />
	<property name="maxIdle" value="5" />
</bean>

<!-- 让spring管理sqlsessionfactory 使用mybatis和spring整合包中的 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
	<!-- 数据库连接池 -->
	<property name="dataSource" ref="dataSource" />
	<!-- 加载mybatis的全局配置文件 -->
	<property name="configLocation" value="classpath:SqlMapConfig.xml" />
</bean>
<!-- 配置Mapper扫描器 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
	<property name="basePackage" value="com.lxhf.mapper" />
</bean>

<!-- service层的注解扫描 -->
<context:component-scan base-package="com.lxhf.service" />

<!-- 配置申明式事务管理器 -->
<bean id="transactionManager"
	class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
	<!-- 数据源 -->
	<property name="dataSource" ref="dataSource" />
</bean>

<!-- 注解方式配置事务 -->
<tx:annotation-driven transaction-manager="transactionManager" />

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

如有疑问或者代码看不懂的请联系:jjl906935093@163.com

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值