Java实战之小米交易商城系统的实现
短信预约 -IT技能 免费直播动态提醒
一、项目简述
环境配置:
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
项目技术:
JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等。
二、效果图
三、核心代码
用户购物车控制层
@CrossOrigin
@RestController
@RequestMapping("carts")
public class CartController {
@Autowired
private RegLogServiceImp regLogServiceImp;
@Autowired
private GoodServiceImp goodServiceImp;
@Autowired
private CartServiceImp cartServiceImp;
@PostMapping("/push")
public CartResult putShop(@RequestBody pushCart pushcart) throws IOException {
CartResult cartResult = new CartResult();
boolean success = TokenUtil.verify(pushcart.getToken());
if (success) {
cartResult.setStatus(0);
User user = regLogServiceImp.getUserByUserName(pushcart.getUsername().trim());
String userid = user.getUserid();
CartGood cartGood = goodServiceImp.getGoodByid(userid, pushcart.getProductId());
if (cartGood == null) {
int goodcount = 1;
CartGoodInsert goodByidinsert = goodServiceImp.getGoodByidinsert(pushcart.getProductId());
goodServiceImp.insCartGood(userid, pushcart.getProductId(), goodByidinsert.getName(),
goodByidinsert.getPrice(), goodcount, goodByidinsert.getSubtitle(), goodByidinsert.getProductStock(),
goodByidinsert.getStatus(), true);
} else {
goodServiceImp.updateCartGood(userid, cartGood.getCount() + 1, pushcart.getProductId(), (cartGood.getCount() + 1) * cartGood.getPrice());
}
cartProductVoList cartProductVoList = cartServiceImp.getCartProduct(userid);
int cartTotalPrice = 0;
boolean selectedAll = true;
int cartTotalQuantity = 0;
for (cartProduct cartProduct : cartProductVoList.getList()) {
cartTotalPrice += cartProduct.getProductTotalPrice();
if (!cartProduct.isProductSelected()) {
selectedAll = false;
}
cartTotalQuantity += cartProduct.getCount();
}
cartResult.setStatus(0);
cartResult.setCartTotalPrice(cartTotalPrice);
cartResult.setCartTotalQuantity(cartTotalQuantity);
cartResult.setData(cartProductVoList);
cartResult.setImageHost("www.mi.com");
cartResult.setSelectedAll(selectedAll);
} else {
cartResult.setStatus(10);
}
return cartResult;
}
@GetMapping("/sum")
public CartResult getCartSum(@RequestParam("username") String username) throws IOException {
CartResult cartResult = new CartResult();
User user = regLogServiceImp.getUserByUserName(username);
String userid = user.getUserid();
cartProductVoList cartProductVoList = cartServiceImp.getCartProduct(userid);
if(cartProductVoList==null){
cartResult.setStatus(0);
cartResult.setCartTotalQuantity(0);
}
else {
int cartTotalQuantity=0;
for(cartProduct cartProduct:cartProductVoList.getList()){
cartTotalQuantity+=cartProduct.getCount();
}
cartResult.setStatus(0);
cartResult.setCartTotalQuantity(cartTotalQuantity);
}
return cartResult;
}
@RequestMapping("/del")
public CartResult delCarts(@RequestParam("id") int goodid,
@RequestParam("username") String username) throws IOException {
User user = regLogServiceImp.getUserByUserName(username);
String userid = user.getUserid();
goodServiceImp.delGoodByid(userid,goodid);
CartResult cartResult = getCarts(username);
return cartResult;
}
@RequestMapping("/getcarts")
public CartResult getCarts (@RequestParam("username") String username) throws IOException {
CartResult cartResult = new CartResult();
User user = regLogServiceImp.getUserByUserName(username);
String userid = user.getUserid();
cartProductVoList cartProductVoList = cartServiceImp.getCartProduct(userid);
if(cartProductVoList==null){
cartResult.setStatus(0);
cartResult.setCartTotalQuantity(0);
cartResult.setSelectedAll(false);
cartResult.setImageHost("www.mi.com");
cartResult.setCartTotalQuantity(0);
}
else {
int carttotalPrice=0;
boolean selectedall=true;
int carttotalQuantity=0;
for(cartProduct cartProduct:cartProductVoList.getList()){
if(cartProduct.isProductSelected())
carttotalPrice+=cartProduct.getProductTotalPrice();
if(!cartProduct.isProductSelected()){
selectedall=false;
}
carttotalQuantity+=cartProduct.getCount();
}
cartResult.setStatus(0);
cartResult.setCartTotalPrice(carttotalPrice);
cartResult.setCartTotalQuantity(carttotalQuantity);
cartResult.setData(cartProductVoList);
cartResult.setImageHost("www.mi.com");
cartResult.setSelectedAll(selectedall);
}
return cartResult;
}
@GetMapping("/updatecart")
public CartResult getCarts (
@RequestParam("goodid") int goodid,
@RequestParam("username") String username,
@RequestParam("quantity") int count,
@RequestParam("selected") boolean selected
) throws IOException {
User user = regLogServiceImp.getUserByUserName(username);
String userid = user.getUserid();
CartGood goodByid = goodServiceImp.getGoodByid(userid, goodid);
goodServiceImp.updaCartNumSel(userid,goodid,count,selected,goodByid.getPrice()*count);
CartResult carts = getCarts(username);
return carts;
}
@GetMapping("/selectAll")
public CartResult SelectAllCart(@RequestParam("username") String username) throws IOException {
User user = regLogServiceImp.getUserByUserName(username);
String userid = user.getUserid();
goodServiceImp.updaCartSelect(userid);
CartResult cartResult = getCarts(username);
return cartResult;
}
@GetMapping("/unSelectAll")
public CartResult unSelectAllCart(@RequestParam("username") String username) throws IOException {
User user = regLogServiceImp.getUserByUserName(username);
String userid = user.getUserid();
goodServiceImp.updaCartunSelect(userid);
CartResult cartResult = getCarts(username);
cartResult.setCartTotalQuantity(0);
cartResult.setCartTotalPrice(0);
return cartResult;
}
}
后台登录控制层
@CrossOrigin
@RestController
@RequestMapping("Login")
public class LoginController {
@Autowired
private LoginServiceImp loginServiceImp;
Map<String, String> keyMap = RSAUtils.createKeys(512);
// String publicKey = keyMap.get("publicKey");
// String privateKey = keyMap.get("privateKey");
// private String publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAIS-9P6aiWK-mNIJxz0R_XXIbHM21pS_ZncpQcE8T5Mu6P6sJfoi5Cw6S4jcSqxNbRs5FSUc59GAkU1Ek9onrz8CAwEAAQ";
private String privateKey = "MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAhL70_pqJYr6Y0gnHPRH9dchsczbWlL9mdylBwTxPky7o_qwl-iLkLDpLiNxKrE1tGzkVJRzn0YCRTUST2ievPwIDAQABAkAviOHaOiRwQ6gdrnq2F7cXcknDiCOW6GMc0J1HQP2Nyn52HKtc9E9Ailm-eQesTw6P-qTsvHMyfuVYz8fLhfkhAiEAvhvoG2Dz6qSN6IHeuPboJP7YHK9zTt6M_NGCJKAenasCIQCywU7eStITcHFTRDjjShH0CfO-vR6q-zgWQPjtNI_YvQIgY8UNiODW4bu-ZdlSY8vghRnhnRxO7YNKhpwFKueFacUCIQCZ-P65ZVNs4ScMZTBnP48VWVk2S-rVto0KRi7lC6h4NQIgEa_GhBO6U2p6G5cGAR25ZiQVH9dFnrMVyPxY7P7-WsA";
@PostMapping("/login")
public LoginResult Login(@RequestBody User adminUser) throws IOException, InvalidKeySpecException, NoSuchAlgorithmException {
User user = loginServiceImp.getUserByUserName(adminUser.getUsername());
LoginResult result = new LoginResult();
LoginData loginData = new LoginData();
if (user == null) {
result.setMsg("无此用户,请重新输入正确用户名");
result.setStatus(2008);
} else {
if (RSAUtils.privateDecrypt(user.getPwd(), RSAUtils.getPrivateKey(privateKey)).equals(adminUser.getPwd())){
result.setStatus(0);
String token = TokenUtil.token(user.getId().trim());
loginData.setToken(token);
result.setMsg("登录成功");
result.setStatus(1010);
result.setData(loginData);
}else{
result.setStatus(2007);
result.setMsg("密码错误");
}
}
return result;
}
}
后台商品管理控制层
@CrossOrigin
@RestController
@RequestMapping("Good")
public class GoodController {
@Autowired
private GoodServiceImp goodServiceImp;
@GetMapping("/getGood")
private GoodResult getGood(@RequestParam("pageIndex") int pageIndex,
@RequestParam("pageSize") int pageSize,
@RequestParam("name") String goodname
) throws IOException {
GoodResult goodResult = goodServiceImp.getGood(pageIndex,pageSize,goodname);
return goodResult;
}
@GetMapping("/getGoodById")
private GoodResult getGoodById(@RequestParam("category") int pageIndex,
@RequestParam("pageSize") int pageSize
) throws IOException {
GoodResult goodResult = goodServiceImp.getGoodById(pageIndex,pageSize);
return goodResult;
}
@RequestMapping("/getGoodByName")
private GoodResult getGoodByName(@RequestParam("name") String goodname) throws IOException {
GoodResult goodResult = goodServiceImp.getGoodByName(goodname);
return goodResult;
}
@RequestMapping("/updGood")
private GoodResult getGoodByName(@RequestParam("good_id") int goodid,
@RequestParam("name") String goodname,
@RequestParam("newhot") int newhot) throws IOException {
GoodResult goodResult = goodServiceImp.updGood(goodid,goodname,newhot);
return goodResult;
}
@GetMapping("/getGoodPicById")
private GoodPicResult getGoodPicById(@RequestParam("category") int pageIndex,
@RequestParam("pageSize") int pageSize
) throws IOException {
GoodPicResult goodpicResult = goodServiceImp.getGoodPic(pageIndex,pageSize);
return goodpicResult;
}
@RequestMapping("/getGoodPicByName")
private GoodPicResult getGoodPicByName(@RequestParam("name") String goodname) throws IOException {
// int categor = Integer.parseInt(category);
GoodPicResult goodResult = goodServiceImp.getGoodPicByName(goodname);
return goodResult;
}
@PostMapping("/pushGood")
private GoodPushResult pushGood(@RequestBody good good) throws IOException {
GoodPushResult goodPushResult = goodServiceImp.getGoodPush(good);
return goodPushResult;
}
@PostMapping("/delGood")
private void delGood(@RequestBody good good) throws IOException {
goodServiceImp.delGood(good);
}
@PostMapping("/delMulGood")
private void delMulGood(@RequestBody List<good> goods) throws IOException {
goodServiceImp.delMulGood(goods);
}
@GetMapping("/getGoodPic")
private GoodPicResult getGoodPic(@RequestParam("pageIndex") int pageIndex,
@RequestParam("pageSize") int pageSize) throws IOException {
GoodPicResult goodPicResult = goodServiceImp.getGoodPic(pageIndex,pageSize);
return goodPicResult;
}
@PostMapping("/updGoodPic")
private void upGoodPic(@RequestBody GoodPic goodPic) throws IOException {
int goodid= goodPic.getGood_id();
String icon= goodPic.getIcon();
String imageHead = goodPic.getImageHead();
String imageFoot = goodPic.getImageFoot();
goodServiceImp.updGoodPic(goodid,icon,1);
goodServiceImp.updGoodPic(goodid,imageHead,2);
goodServiceImp.updGoodPic(goodid,imageFoot,3);
}
}
后台品类控制层
@CrossOrigin
@RestController
@RequestMapping("category")
public class CategoryController {
@Autowired
private CategServiceImp categServiceImp;
@GetMapping("/getCategory")
private CateResult getCategory(@RequestParam("pageIndex") int pageIndex,
@RequestParam("pageSize") int pageSize) throws IOException {
CateResult cateResult = categServiceImp.getCategory(pageIndex, pageSize);
return cateResult;
}
@PostMapping("/updateCategory")
private void updateCategory(@RequestBody Category category) throws IOException {
categServiceImp.updCategory(category.getName(),category.getCategoryId());
}
}
以上就是Java实战之小米交易商城系统的实现的详细内容,更多关于Java交易商城系统的资料请关注编程网其它相关文章!
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341