Java-动态数据接口
-
实现效果
动态数据接口 |
---|
|
-
axios 异步请求
请求与渲染 |
---|
|
实现过程总结
Demo源文件
-
Servlet
-
dao package com.example.book.dao;
import com.example.book.entity.BookInfo;
import java.util.List;
public interface BookInfoDao {
BookInfo selectBookByName(String booName);
List<BookInfo> selectAllBook();
int addInCartCount(String bookId, int count);
int reduceCardCount(String bookId, int count);
}
-
server 层 package com.example.book.service;
import com.example.book.entity.BookInfo;
import java.util.List;
public interface BookInfoService {
BookInfo lookUpBookByName(String bookName);
List<BookInfo> organizingBooks();
int editAddBookInShoppingCart(String bookId, int count);
int editReduceBookInShoppingCart(String bookId, int count);
}
-
请求与处理controller package com.example.book.controller;
import com.alibaba.fastjson.JSON;
import com.example.book.entity.BookInfo;
import com.example.book.service.BookInfoService;
import com.example.book.service.impl.BookInfoServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@WebServlet(name = "ShowAllBookInfo", value = "/showAllBookInfo")
public class ShowAllBookInfo extends HttpServlet {
private BookInfoService bookInfoService = new BookInfoServiceImpl();
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List<BookInfo> bookInfos = bookInfoService.organizingBooks();
String jsonString = JSON.toJSONString(bookInfos);
System.out.println(jsonString);
response.setContentType("application/json;charset=utf-8");
response.getWriter().write(jsonString);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
-
前端
- 使用表格展示数据
Element-UI axios 进行异步请求JSON 格式化插件选择FeHelper - 过滤器
Vue 配置项
|