IDEA+Java控制台实现商品管理系统建议收藏
Posted 水坚石青
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了IDEA+Java控制台实现商品管理系统建议收藏相关的知识,希望对你有一定的参考价值。
目录
一、系统介绍
1.开发环境
开发工具:IDEA2018.2
JDK版本:jdk1.8
2.技术选型
Java语言开发,使用ArrayList存储信息。
3.系统功能
1.实现系统登录
2.实现商品信息的增删改查
4.获取资源
1.CSDN下载
2.免费获取
关注微信公众号加我微信联系我。
二、系统展示
1.登录系统
2.查询商品信息
3.增加商品信息
4.更新商品信息
5.删除商品信息
三、部分代码
BussinessService
package service;
import common.Constant;
import common.Response;
import entity.Shop;
import java.util.ArrayList;
import java.util.List;
public class BusinessService {
private static List<Shop> businessList = new ArrayList<>();
static {
businessList.add(new Shop("1","方便面","10","5","北京"));
businessList.add(new Shop("2","面包","20","5","天津"));
businessList.add(new Shop("3","矿泉水","50","2","武汉"));
}
// 查询
public Response query(String name){
if(name == null || "".equals(name)){
return new Response("error","编号为空。");
}
for(Shop shop : businessList){
if(name.equals(shop.getGoodsId())){
return new Response("success","查询成功。", shop);
}
}
return new Response("error","未查询到此"+ Constant.MAIN_CLASS +",请重新输入:");
}
// 增加
public Response add(Shop shop){
for(Shop s : businessList){
if(s.getGoodsId().equals(shop.getGoodsId())){
return new Response("error","该"+ Constant.MAIN_CLASS+"已存在。");
}
}
businessList.add(shop);
return new Response("success", Constant.MAIN_CLASS+"添加成功。", shop);
}
// 编辑
public Response checkProp(Shop shop, String prop, String value){
if(prop == null || "".equals(prop)){
return new Response("error","属性为空。");
}
String[] props = {"stuId","stuName","stuSex","stuAge","stuWeight"};
switch(prop){
case "goodsId" :
shop.setGoodsId(value);
break;
case "goodsName" :
shop.setGoodsName(value);
break;
case "goodsStock" :
shop.setGoodsStock(value);
break;
case "goodsPrice" :
shop.setGoodsPrice(value);
break;
case "goodsAddress" :
shop.setGoodsAddress(value);
break;
default:
return new Response("error","该属性不存在。");
}
return new Response("success","编辑成功。");
}
// 删除
public Response delete(String name){
if(name == null || "".equals(name)){
return new Response("error", Constant.MAIN_CLASS+"编号为空。");
}
for(Shop shop: businessList){
if(shop.getGoodsId().equals(name)){
businessList.remove(shop);
return new Response("success", Constant.MAIN_CLASS+"删除成功。");
}
}
return new Response("error", Constant.MAIN_CLASS+"不存在。");
}
}
LoginService
package service;
import common.Account;
import common.Response;
import entity.User;
import java.util.ArrayList;
import java.util.List;
public class LoginService {
private static List<User> userList = new ArrayList();
static{
userList.add(new User(Account.ADMIN.getUsername(), Account.ADMIN.getPassword()));
userList.add(new User(Account.USER1.getUsername(), Account.USER1.getPassword()));
userList.add(new User(Account.USER2.getUsername(), Account.USER2.getPassword()));
userList.add(new User(Account.USER3.getUsername(), Account.USER3.getPassword()));
}
public Response login(String username, String password){
if(username == null || "".equals(username)){
return new Response("error","用户名为空,请输入用户名。");
}
if(password == null || "".equals(password)){
return new Response("error","密码为空,请输入密码。");
}
for (User user : userList){
if(username.equals(user.getUsername()) && password.equals(user.getPassword())){
return new Response("success","登陆成功!");
}
}
return new Response("error","用户名或密码输入错误,请检查并重新输入。");
}
}
四、其他
1.其他系统实现
2.获取源码
点击以下链接获取源码。
3.运行项目
直接导入项目,打开Main运行程序。
4.备注
如有侵权请联系我删除。
5.支持博主
如果您觉得此文对您有帮助,请点赞加关注加收藏。祝您生活愉快!想要获取其他资源可关注左侧微信公众号获取!
以上是关于IDEA+Java控制台实现商品管理系统建议收藏的主要内容,如果未能解决你的问题,请参考以下文章