-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
1,308 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
src/main/java/com/example/mall/controller/GoodsServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package com.example.mall.controller; | ||
|
||
import com.example.mall.model.bo.AddGoodsBO; | ||
import com.example.mall.model.bo.AddTypeBO; | ||
import com.example.mall.model.bo.UpdateGoodsBO; | ||
import com.example.mall.model.vo.*; | ||
import com.example.mall.service.GoodsService; | ||
import com.example.mall.service.GoodsServiceImpl; | ||
import com.example.mall.service.UserService; | ||
import com.example.mall.service.UserServiceImpl; | ||
import com.example.mall.util.ParseUtils; | ||
import com.google.gson.Gson; | ||
import org.apache.commons.fileupload.FileItemIterator; | ||
import org.apache.commons.fileupload.FileItemStream; | ||
import org.apache.commons.fileupload.FileUploadException; | ||
import org.apache.commons.fileupload.servlet.ServletFileUpload; | ||
import org.apache.commons.fileupload.util.Streams; | ||
|
||
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.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.HashMap; | ||
|
||
/** | ||
* @Classname BusinessServlet | ||
* @Description 负责后台业务模块 | ||
* @Date 2022-08-20 10:36 | ||
* @Created by Yang Yi-zhou | ||
*/ | ||
@WebServlet("/api/admin/goods/*") | ||
public class GoodsServlet extends HttpServlet { | ||
private Gson gson = new Gson(); | ||
//goods业务层 | ||
private GoodsService goodsService = new GoodsServiceImpl(); | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | ||
//分发 | ||
String contextPath = req.getContextPath(); | ||
String servletPath = req.getServletPath(); | ||
String targetResource = req.getRequestURI().replace(contextPath + servletPath + "/", ""); | ||
if ("getType".equals(targetResource)) { | ||
getType(req, resp); | ||
} else if ("getGoodsByType".equals(targetResource)) { | ||
getGoodsByType(req, resp); | ||
} | ||
|
||
} | ||
|
||
private void getGoodsByType(HttpServletRequest req, HttpServletResponse resp) throws IOException { | ||
//取出TypeId | ||
int typeId = Integer.parseInt(req.getParameter("typeId")); | ||
//根据typeId去数据库取出数据 | ||
GetGoodsByTypeVO goodsByType = goodsService.getGoodsByType(typeId); | ||
//响应 | ||
resp.getWriter().println(gson.toJson(goodsByType)); | ||
} | ||
|
||
private void getType(HttpServletRequest req, HttpServletResponse resp) throws IOException { | ||
//获取商品类型 | ||
GetTypeVO typeVO = goodsService.getType(); | ||
//响应 | ||
resp.getWriter().println(gson.toJson(typeVO)); | ||
|
||
} | ||
|
||
@Override | ||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | ||
//分发 | ||
String targetResource = ParseUtils.parseURIToTargetResource(req); | ||
if ("addType".equals(targetResource)) { | ||
addType(req, resp); | ||
} else if ("imgUpload".equals(targetResource)) { | ||
try { | ||
imgUpload(req, resp); | ||
} catch (FileUploadException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} else if ("addGoods".equals(targetResource)) { | ||
addGoods(req, resp); | ||
} else if ("updateGoods".equals(targetResource)) { | ||
updateGoods(req, resp); | ||
} | ||
|
||
} | ||
|
||
private void updateGoods(HttpServletRequest req, HttpServletResponse resp) throws IOException { | ||
//解析载荷 | ||
UpdateGoodsBO updateGoodsBO = ParseUtils.parseToBO(req, UpdateGoodsBO.class); | ||
} | ||
|
||
private void addGoods(HttpServletRequest req, HttpServletResponse resp) throws IOException { | ||
//解析载荷 | ||
AddGoodsBO addGoodsBO = ParseUtils.parseToBO(req, AddGoodsBO.class); | ||
//交给service处理 | ||
AddGoodsVO addGoodsVO = goodsService.addGoods(addGoodsBO); | ||
//响应 | ||
resp.getWriter().println(gson.toJson(addGoodsVO)); | ||
} | ||
|
||
private void imgUpload(HttpServletRequest req, HttpServletResponse resp) throws IOException, FileUploadException { | ||
ImgUploadVO imgUploadVO = goodsService.imgUpload(req, resp); | ||
//响应 | ||
resp.getWriter().println(gson.toJson(imgUploadVO)); | ||
} | ||
|
||
private void addType(HttpServletRequest req, HttpServletResponse resp) throws IOException { | ||
//解析载荷 | ||
AddTypeBO addTypeBO = ParseUtils.parseToBO(req, AddTypeBO.class); | ||
//添加进数据库 | ||
AddTypeVO addTypeVO = goodsService.addType(addTypeBO); | ||
//响应 | ||
resp.getWriter().println(gson.toJson(addTypeVO)); | ||
|
||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/com/example/mall/controller/ImageServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.example.mall.controller; | ||
|
||
import com.example.mall.util.ParseUtils; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletOutputStream; | ||
import javax.servlet.annotation.WebFilter; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
|
||
/** | ||
* @Classname ImageServlet | ||
* @Description | ||
* @Date 2022-08-20 11:35 | ||
* @Created by Yang Yi-zhou | ||
*/ | ||
@WebServlet("/static/image/*") | ||
public class ImageServlet extends HttpServlet { | ||
@Override | ||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | ||
resp.setContentType("image/jpeg;charset=UTF-8"); | ||
// //拿到图片的名称 | ||
// String contextPath = req.getContextPath(); | ||
// String servletPath = req.getServletPath(); | ||
// String targetResource = req.getRequestURI().replace(contextPath + servletPath + "/", ""); | ||
String targetResource = ParseUtils.parseURIToTargetResource(req); | ||
//拿到图片的真实路径 | ||
String path = this.getServletContext().getRealPath("/static/image/" + targetResource); | ||
// String path = this.getServletContext().getRealPath("static/image/1.jpg"); | ||
//读取图片 | ||
File file = new File(path); | ||
FileInputStream fis = new FileInputStream(file); | ||
int size = fis.available(); | ||
byte[] data = new byte[size]; | ||
fis.read(data); | ||
fis.close(); | ||
//写入响应体 | ||
ServletOutputStream ops = resp.getOutputStream(); | ||
ops.write(data); | ||
ops.flush(); | ||
ops.close(); | ||
|
||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
src/main/java/com/example/mall/controller/UserServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.example.mall.controller; | ||
|
||
import com.example.mall.model.vo.AllUserVO; | ||
import com.example.mall.model.vo.DeleteUserVO; | ||
import com.example.mall.model.vo.SearchUserVO; | ||
import com.example.mall.service.UserService; | ||
import com.example.mall.service.UserServiceImpl; | ||
import com.google.gson.Gson; | ||
|
||
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; | ||
|
||
/** | ||
* @Classname UserServlet | ||
* @Description 负责用户模块 | ||
* @Date 2022-08-20 9:44 | ||
* @Created by Yang Yi-zhou | ||
*/ | ||
@WebServlet("/api/admin/user/*") | ||
public class UserServlet extends HttpServlet { | ||
private Gson gson = new Gson(); | ||
private UserService userService = new UserServiceImpl(); | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | ||
//分发请求 | ||
String contextPath = req.getContextPath(); | ||
String servletPath = req.getServletPath(); | ||
String targetResource = req.getRequestURI().replace(contextPath + servletPath + "/", ""); | ||
if ("allUser".equals(targetResource)) { | ||
allUser(req, resp); | ||
} else if ("deleteUser".equals(targetResource)) { | ||
deleteUser(req, resp); | ||
} else if ("searchUser".equals(targetResource)) { | ||
searchUser(req, resp); | ||
} | ||
} | ||
|
||
private void searchUser(HttpServletRequest req, HttpServletResponse resp) throws IOException { | ||
//解析参数 | ||
String word = req.getParameter("word"); | ||
//根据搜索词去搜索用户 | ||
SearchUserVO searchUserVO = userService.searchUser(word); | ||
//响应 | ||
resp.getWriter().println(gson.toJson(searchUserVO)); | ||
} | ||
|
||
private void deleteUser(HttpServletRequest req, HttpServletResponse resp) throws IOException { | ||
//解析参数 | ||
int id = Integer.parseInt(req.getParameter("id")); | ||
//根据id去数据库删除数据 | ||
DeleteUserVO deleteUserVO = userService.deleteUser(id); | ||
//响应 | ||
resp.getWriter().println(gson.toJson(deleteUserVO)); | ||
} | ||
|
||
private void allUser(HttpServletRequest req, HttpServletResponse resp) throws IOException { | ||
//交给service层取数据 | ||
AllUserVO allUserVO = userService.allUser(); | ||
//写入响应体返回 | ||
resp.getWriter().println(gson.toJson(allUserVO)); | ||
} | ||
|
||
@Override | ||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | ||
super.doPost(req, resp); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.example.mall.mapper; | ||
|
||
import com.example.mall.model.po.GoodsPO; | ||
import com.example.mall.model.po.GoodsSpecPO; | ||
import com.example.mall.model.po.GoodsTypePO; | ||
import org.apache.ibatis.annotations.Param; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @Classname AdminMapper | ||
* @Description | ||
* @Date 2022-08-19 17:52 | ||
* @Created by Yang Yi-zhou | ||
*/ | ||
public interface GoodsMapper { | ||
List<GoodsTypePO> selectAllGoodsTypeFromTableGoodsType(); | ||
|
||
List<GoodsPO> selectGoodsFromTableGoodsByTypeId(@Param("typeId") Integer typeId); | ||
|
||
Integer selectStockNumFromTableGoodsSpecByGoodsId(@Param("goodsId") Integer goodsId); | ||
|
||
Integer insertIntoTableGoodsType(@Param("name") String name); | ||
|
||
GoodsTypePO selectGoodsTypeFromTableGoodsTypeByName(@Param("name") String name); | ||
|
||
Integer insertGoodsIntoTableGoods(@Param("goodsPO") GoodsPO goodsPO); | ||
|
||
Integer insertGoodsSpecListIntoTableGoodsSpec(@Param("specPOList") List<GoodsSpecPO> specPOList); | ||
|
||
Double selectPriceFromTableGoodsById(@Param("id") Integer id); | ||
|
||
Integer updateTableGoodsSetPriceById(@Param("price") Double price, @Param("id") Integer id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.example.mall.mapper; | ||
|
||
import com.example.mall.model.po.UserPO; | ||
import org.apache.ibatis.annotations.Param; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @Classname AdminMapper | ||
* @Description | ||
* @Date 2022-08-19 17:52 | ||
* @Created by Yang Yi-zhou | ||
*/ | ||
public interface UserMapper { | ||
|
||
List<UserPO> selectUserListFromUser(); | ||
|
||
Integer deleteUserById(@Param("id") Integer id); | ||
|
||
List<UserPO> selectUserFromUserByWord(@Param("word") String word); | ||
|
||
} |
Oops, something went wrong.