中国国家图书馆公司(狗头)委托我开发一个一个专门的中国国家图书馆,出售外星人电子产品以及周边,实现了以下功能。
本项目尚未搭载了服务器,网址给定:
链接: 外星人官方网站.
持久层:依据业务要求规划相关的SQL语句,以及进行配置
业务层:核心功能控制、业务 *** 作以及异常处理
控制层:接受请求,处理响应
前端开发:JS、JQuery、Ajax
单元测试:junit
<?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="com.example.mapper.SingleMapper">
<!-- `name`, `author`, `press`, `price`-->
<!--增-->
<!--增-->
<insert id="addBook" parameterType="book">
insert into `ssm-library`.user_lib(name, author, press, price)
values (#{name}, #{author}, #{press}, #{price})
</insert>
<!--删-->
<delete id="deleteBook" parameterType="int">
delete
from `ssm-library`.user_lib
where bookId = #{bookId}
</delete>
<!--改-->
<update id="updateBook" parameterType="book">
update `ssm-library`.user_lib
set name=#{name},
author=#{author},
press=#{press},
price=#{price}
where bookId = #{bookId}
</update>
<!--根据name查一个-->
<select id="queryUserByName" resultType="User" parameterType="String">
select *
from `ssm-library`.user
where username = #{username}
</select>
<!--改-->
<update id="updateUser" parameterType="User">
update `ssm-library`.user
set password=#{password},
money =#{money}
where username = #{username}
</update>
<!--查所有-->
<select id="queryAllBook" resultType="book">
select *
from `ssm-library`.user_lib
</select>
<!--根据id查一个-->
<select id="queryBookById" resultType="book" parameterType="int">
select *
from `ssm-library`.user_lib
where bookId = #{bookId}
</select>
<!--根据name查all-->
<select id="queryBookByName" resultType="book" parameterType="String">
select *
from `ssm-library`.user_lib
where NAME = #{BookName}
</select>
<insert id="addBookbyBook" parameterType="book">
insert into `ssm-library`.user_lib(name, author, press, price, bootnum)
values (#{name}, #{author}, #{press}, #{price})
</insert>
<!--根据条件查询-->
<select id="conditionQuery" resultType="Book" parameterType="Book">
select * from `ssm-library`.user_lib
<where>
<if test="name != null and name != ''">
name = #{name}
</if>
<if test="author != null and author != ''">
and author=#{author}
</if>
<if test="press != null and press != ''">
and press=#{press}
</if>
</where>
</select>
<select id="ListQuery" resultType="Book">
select * from `ssm-library`.user_lib where NAME like '%#{value}%'
</select>
<!-- 增减图书的数量-->
<!-- 如何选择合适的sql语句进行修改-->
<!--删-->
<delete id="addBookNum" parameterType="int">
delete
from `ssm-library`.user_lib
where NAME = #{BookName}
</delete>
</mapper>
2. 业务层
public interface SingleUserService {
// 增
int addBook(Book book);
// 删
int deleteBook(int bookId);
// 改
int updateBook(Book book);
// 查所有
List<Book> queryAllBook();
// 根据id查一个
Book queryBookById(int bookId);
//条件查询
List<Book> conditionQuery(Book book);
// 根据username查一个
User queryUserByName(String username);
//模糊查询
List<Book> ListQuery(String value);
// 改
int updateUser(User user);
//the number of Book
// 增
int addBookNum(String BookName);
// 删
int deleteBookNum(String BookName);
// 改
int updateBookNum(String BookName);
}
@Service
public class SingleUser implements SingleUserService {
@Autowired
private SingleMapper bookMapper;
@Override
public int addBook(Book book) {
return bookMapper.addBook(book);
}
@Override
public int deleteBook(int bookId) {
return bookMapper.deleteBook(bookId);
}
@Override
public int updateUser(User user) {
return bookMapper.updateUser(user);
}
@Override
public int updateBook(Book book) {
return bookMapper.updateBook(book);
}
@Override
public List<Book> queryAllBook() {
return bookMapper.queryAllBook();
}
@Override
public Book queryBookById(int bookId) {
return bookMapper.queryBookById(bookId);
}
@Override
public List<Book> conditionQuery(Book book) {
return bookMapper.conditionQuery(book);
}
@Override
public List<Book> ListQuery(String value) {
return bookMapper.ListQuery(value);
}
@Override
public int addBookNum(String BookName) {
return bookMapper.addBookNum(BookName);
}
@Override
public User queryUserByName(String username) {
return bookMapper.queryUserByName(username);
}
@Override
public int deleteBookNum(String BookName) {
return bookMapper.deleteBookNum(BookName);
}
@Override
public int updateBookNum(String BookName) {
return bookMapper.updateBookNum(BookName);
}
}
3. 控制层
@Controller
public class SingleUserController {
@Autowired
private SingleUserService bookServiceImpl;
@Autowired
private UserService userService;
@Autowired
private BookService bookLib;
@RequestMapping("/single_user/queryBookByName/{BookName}")
public String show(@PathVariable("BookName") String BookName) {
System.out.println("queryBookByName");
List<Book> books = bookLib.queryBookByName(BookName);
Book book = books.get(0);
bookServiceImpl.addBook(book);
return "redirect:/single_user/list"; // redirect 重定向/跳转
}
@RequestMapping("/single_user/borrow/{bookId}")
@ResponseBody
public String borrow3(@PathVariable("bookId") int bookId) {
Book book = bookLib.queryBookById(bookId);
System.out.println(book);
Book newBook = new Book();
newBook.setBookId(10);
newBook.setAuthor(book.getAuthor());
newBook.setName(book.getName());
newBook.setPress(book.getPress());
newBook.setPrice(book.getPrice());
System.out.println(newBook);
System.out.println("test");
bookServiceImpl.addBook(newBook);
return "redirect:/single_user/list"; // redirect 重定向/跳转
}
@GetMapping("/single_user/delete/{bookId}")
public String deletebook(@PathVariable("bookId") int bookId) {
int i = bookServiceImpl.deleteBook(bookId);
return "redirect:/single_user/list";
}
}
4. 前端页面
<table class="table table-striped">
<tr>
<th>序号</th>
<th>图书名</th>
<th>图书作者</th>
<th>图书出版社</th>
<th>图书单价</th>
<th> *** 作</th>
</tr>
<c:forEach items="${books}" var="book" varStatus="s">
<tr>
<td>${s.count}</td>
<td>${book.name}</td>
<td>${book.author}</td>
<td>${book.press}</td>
<td>${book.price}</td>
<td>${book.bootNum}</td>
<td>
<%-- 这个方法需要修改--%>
<a href="${pageContext.request.contextPath}/single_user/delete/${book.bookId}"
class="btn btn-danger">归还</a>
<%-- <a href="${pageContext.request.contextPath}/single_user/borrow/${book.bookId}" class="btn btn-success">借阅</a>--%>
</td>
</tr>
</c:forEach>
第五节 用户管理
第六节 充值管理
外星人商城项目总结
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)