entity实体(Clothes)
public class Clothes {
/**
*样式
*/
private String style;
/**
* 尺码
*/
private Integer size;
/**
* 颜色
*/
private String colour;
/**
* 数量
*/
private Integer quantity;
/**Clothes初始化所有参数的构造器
* * @param style
* * @param size
* * @param colour
* * @param quantity
*/
public Clothes(String style, Integer size,
String colour, Integer quantity){
this.style = style;
this.size = size;
this.colour = colour;
this.quantity = quantity;
}
public String getStyle() {
return style;
}
public void setStyle(String style) {
this.style = style;
}
public Integer getSize() {
return size;
}
public void setSize(Integer size) {
this.size = size;
}
public String getColour() {
return colour;
}
public void setColour(String colour) {
this.colour = colour;
}
public Integer getQuantity() {
return quantity;
}
public void setQuantity(Integer quantity) {
this.quantity = quantity;
}
@Override
public String toString() {
return "Clothes{" +
"style='" + style + '\'' +
", size=" + size +
", colour='" + colour + '\'' +
", quantity=" + quantity +
'}';
}
}
entity(User)
public class User {
/**
* id
*/
private Integer id;
/**
* 用户名
*/
private String userName;
/**
* 密码
*/
private String password;
/**
* 密保问题
*/
private String question;
/**
* 密保答案
*/
private String answer;
public User(Integer id) {
this.id = id;
}
/**
* 空参构造器
*/
public User() {
}
/**
*User初始化所有参数的构造器
* @param userName
* @param answer
* @param answer
* @param question
*/
public User(Integer id,
String userName, String answer,
String password, String question) {
this.userName = userName;
this.answer = answer;
this.password = password;
this.question = question;
this.id = id;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getQuestion() {
return question;
}
public void setQuestion(String question) {
this.question = question;
}
public String getAnswer() {
return answer;
}
public void setAnswer(String answer) {
this.answer = answer;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Override
public String toString() {
return "User{" +"id='"+id+
", userName='" + userName + '\'' +
", password='" + password + '\'' +
", question='" + question + '\'' +
", answer='" + answer + '\'' +
'}';
}
}
Dao(Clothes)接口
import studio.lemon.clothessystem.entity.Clothes;
import java.io.IOException;
import java.util.List;
/**
* @Author: Lemon
* @Date: 2020/12/15 21:23
*/
public interface IClothesDao {
/**
* 增加服装ClothesDao
* @param clothes
* @return boolean
*/
boolean insertClothesDao(Clothes clothes);
/**
* 根据服装类型style删除服装信息
* @param style
* @return boolean
*/
boolean deleteClothesDao(String style);
/**
* 根据用户id更改服装信息
* @param id
* @return boolean
*/
boolean updateClothesDao(Integer id);
/**
* 根据服装类型style查询服装信息ClothesDao
* @param style
* @return List<Clothes>
*/
List<Clothes> selectClothesByIdDao(String style) ;
}
``
``
Dao(Clothes)实现
import studio.lemon.clothessystem.dao.IClothesDao;
import studio.lemon.clothessystem.entity.Clothes;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class ClothesDaoImpl implements IClothesDao {
/**
* 增加服装信息ClothesDao
* @param clothes
* @return boolean
*/
@Override
public boolean insertClothesDao(Clothes clothes) {
BufferedWriter bufferedWriter = null;
try {
bufferedWriter = new BufferedWriter(new FileWriter("ClothesSystem\\Clothes.txt"));
String returnString=String.format("%s,%s,%s,%s",clothes.getColour(),clothes.getQuantity(),clothes.getSize(),clothes.getStyle());
bufferedWriter.write(returnString);
bufferedWriter.newLine();
bufferedWriter.close();
return true;
} catch (IOException e) {
return false;
}
}
/**
* 根据服装类型style删除服装信息
* @param style
* @return boolean
*/
@Override
public boolean deleteClothesDao(String style) {
BufferedReader bufferedReader = null;
try {
bufferedReader = new BufferedReader(new FileReader("ClothesSystem\\Clothes.txt"));
List<Clothes> clothesList = new ArrayList<>();
String string;
while ((string = bufferedReader.readLine()) != null) {
String[] dates = string.split(",");
Clothes clothes = new Clothes(dates[0], Integer.parseInt(dates[1]), dates[2], Integer.parseInt(dates[3]));
System.out.println(clothes);
clothesList.add(clothes);
}
for (int i = 0; i <= clothesList.size() - 1; i++) {
Clothes clothes = clothesList.get(i);
if (clothes.getStyle().equals(style)) {
clothesList.remove(i);
}
}
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("ClothesSystem\\Clothes.txt"));
for (int i = 0; i < clothesList.size(); i++) {
Clothes clothes = clothesList.get(i);
String returnString = String.format("%s,%s,%s,%s", clothes.getStyle(),clothes.getSize(),clothes.getQuantity(),clothes.getColour());
bufferedWriter.write(returnString);
bufferedWriter.newLine();
}
bufferedReader.close();
bufferedWriter.close();
return true;
} catch (Exception e) {
return false;
}
}
/**
* 根据用户id更改服装信息
* @param id
* @return boolean
*/
@Override
public boolean updateClothesDao(Integer id) {
BufferedReader bufferedReader = null;
try {
bufferedReader = new BufferedReader(new FileReader("ClothesSystem\\Clothes.txt"));
List<Clothes> clothesList=new ArrayList<>();
String string;
while ((string = bufferedReader.readLine()) != null) {
String[] dates=string.split(",");
Clothes returnClothes=new Clothes(dates[0], Integer.parseInt(dates[1]), dates[2], Integer.parseInt(dates[3]));
clothesList.add(returnClothes);
}
for (int i = 0; i <=clothesList.size()-1 ; i++) {
Clothes clothes = clothesList.get(i);
if (clothes.getStyle().equals(clothes.getStyle())){
clothesList.set(i,clothes);
}
}
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("ClothesSystem\\Clothes.txt"));
for (int i = 0; i <clothesList.size() ; i++) {
Clothes returnclothes=clothesList.get(i);
String returnString=String.format("%s,%s,%s,%s",returnclothes.getColour(),returnclothes.getQuantity(),returnclothes.getSize(),returnclothes.getStyle() );
bufferedWriter.write(returnString);
bufferedWriter.newLine();
}
bufferedReader.close();
bufferedWriter.close();
return true;
} catch (Exception e) {
return false;
}
}
/**
* 根据服装类型style查询服装信息ClothesDao
* @param style
* @return List<Clothes>
*/
@Override
public List<Clothes> selectClothesByIdDao(String style) {
BufferedReader bufferedReader = null;
try {
bufferedReader = new BufferedReader(new FileReader("ClothesSystem\\Clothes.txt"));
List<Clothes> clothesList = new ArrayList<>();
String string;
while ((string = bufferedReader.readLine()) != null) {
String[] dates = string.split(",");
if (dates[3]==style){
Clothes clothes = new Clothes(dates[0], Integer.parseInt(dates[1]), dates[2], Integer.parseInt(dates[3]));
clothesList.add(clothes);
}
}
bufferedReader.close();
return clothesList;
} catch (Exception e) {
return null;
}
}
}
Dao(User)接口
import studio.lemon.clothessystem.entity.User;
import java.io.IOException;
import java.util.List;
public interface IUserDao {
/**
* 增加用户IUserDao
* @param user
* @return boolean
*/
boolean insertUserDao(User user) ;
/**
* 根据用户id删除用户IUserDao
* @param id
* @return boolean
*/
boolean deleteUserDao(Integer id) ;
/**
* 根据用户id更改用户信息IUserDao
* @param id
* @param user
* @return boolean
* @throws IOException
*/
boolean updateUserDao(User user,Integer id) ;
/**
* 根据密保问题question查询用户信息
* @param question
* @return List<User>
*/
List<User> retrieveUserDao(String question);
}
Dao(User)实现
import studio.lemon.clothessystem.dao.IUserDao;
import studio.lemon.clothessystem.entity.User;
import java.io.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class UserDaoImpl implements IUserDao {
/**
* 增加用户IUserDao
* @param user
* @return boolean
*/
@Override
public boolean insertUserDao(User user) {
BufferedWriter bufferedWriter = null;
try {
bufferedWriter = new BufferedWriter(new FileWriter("ClothesSystem\\User.txt",true));
String returnString=String.format("%s,%s,%s,%s,%s",user.getId(),user.getUserName(),user.getPassword(),user.getQuestion(),user.getAnswer());
bufferedWriter.write(returnString);
bufferedWriter.newLine();
bufferedWriter.close();
return true;
} catch (Exception e) {
System.out.println("数据增加失败");
return false;
}
}
/**
* 根据用户id删除用户IUserDao
* @param id
* @return boolean
*/
@Override
public boolean deleteUserDao(Integer id) {
BufferedReader bufferedReader = null;
try {
bufferedReader = new BufferedReader(new FileReader("ClothesSystem\\User.txt"));
List<User> userList=new ArrayList<>();
String string;
while ((string=bufferedReader.readLine())!=null){
String[] dates=string.split(",");
User user=new User(Integer.parseInt(dates[0]),dates[1],dates[2],dates[3],dates[4]);
System.out.println(user);
userList.add(user);
}
for (int i = 0; i <=userList.size()-1 ; i++) {
User user=userList.get(i);
if (user.getId().equals(id)){
userList.remove(i);
}
}
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("ClothesSystem\\User.txt"));
for (int i = 0; i <userList.size() ; i++) {
User user=userList.get(i);
String returnString=String.format("%s,%s,%s,%s,%s",user.getId(),user.getUserName(),user.getPassword(),user.getQuestion(),user.getAnswer());
bufferedWriter.write(returnString);
bufferedWriter.newLine();
}
bufferedWriter.close();
return true;
} catch (Exception e) {
System.out.println("删除失败");
return false;
}
}
/**
* 根据用户id更改用户信息IUserDao
* @param id
* @return boolean
*/
@Override
public boolean updateUserDao(User user, Integer id) {
BufferedReader bufferedReader = null;
try {
bufferedReader = new BufferedReader(new FileReader("ClothesSystem\\User.txt"));
List<User> userList=new ArrayList<>();
String string;
while ((string=bufferedReader.readLine())!=null){
String[] dates=string.split(",");
User returnUser=new User(Integer.parseInt(dates[0]),dates[1],dates[2],dates[3],dates[4]);
userList.add(returnUser);
}
for (int i = 0; i <=userList.size()-1 ; i++) {
User returnUser=userList.get(i);
if (returnUser.getId().equals(id)){
userList.set(i,user);
}
}
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("ClothesSystem\\User.txt"));
for (int i = 0; i <userList.size() ; i++) {
User returnUser=userList.get(i);
String returnString=String.format("%s,%s,%s,%s,%s",returnUser.getId(),returnUser.getUserName(),returnUser.getPassword(),returnUser.getQuestion(),returnUser.getAnswer());
bufferedWriter.write(returnString);
bufferedWriter.newLine();
}
bufferedReader.close();
bufferedWriter.close();
return true;
} catch (Exception e) {
System.out.println("更改失败");
return false;
}
}
/**
* 根据密保问题question查询用户信息
* @param question
* @return List<User>
*/
@Override
public List<User> retrieveUserDao(String question) {
BufferedReader bufferedReader = null;
try {
bufferedReader = new BufferedReader(new FileReader("ClothesSystem\\User.txt"));
List<User> userList=new ArrayList<>();
String string;
while ((string=bufferedReader.readLine())!=null){
String[] dates=string.split(",");
if (dates[4].equals(question)){
User user=new User(Integer.parseInt(dates[0]),dates[1],dates[2],dates[3],dates[4]);
userList.add(user);
}
}
bufferedReader.close();
return userList;
} catch (Exception e) {
System.out.println("数据查询失败");
return null;
}
}
}
Service(Clothes)接口
import studio.lemon.clothessystem.entity.Clothes;
import java.io.IOException;
import java.util.List;
public interface IClothesService {
/**
* 增加服装Clothesservice
* @param clothes
* @return booleanclothes
*/
boolean insertClothesService(Clothes clothes);
/**
* 根据服装类型style删除服装信息
* @param style
* @return boolean
*/
boolean deleteClothesService(String style);
/**
* 根据用户id更改服装信息
* @param id
* @return boolean
*/
boolean addClothesService(Integer id);
/**
* 根据服装类型style查询服装信息Clothesservice
* @param style
* @return List<Clothes>
*/
List<Clothes> selectClothesByIdService(String style);
}
Service(Clothes)实现
import studio.lemon.clothessystem.dao.IClothesDao;
import studio.lemon.clothessystem.dao.impl.ClothesDaoImpl;
import studio.lemon.clothessystem.entity.Clothes;
import studio.lemon.clothessystem.service.IClothesService;
import java.io.IOException;
import java.util.List;
/**
* @Author: Lemon
* @Date: 2020/12/17 22:03
*/
public class ClothesServiceImpl implements IClothesService {
/**
* Clothes创建Dao对象
*/
IClothesDao iClothesDao=new ClothesDaoImpl();
/**
* 增加服装ClothesService
* @param clothes
* @return boolean
*/
@Override
public boolean insertClothesService( Clothes clothes) {
List<Clothes> clothesList= iClothesDao.selectClothesByIdDao(String.valueOf(clothes.getStyle()));
if (clothesList.size()==0){
boolean judgment= iClothesDao.insertClothesDao(clothes);
if (judgment){
System.out.println("增加成功");
return true;
}
return false;
}
return false;
}
/**
* 根据服装类型style删除服装信息
* @param style
* @return boolean
*/
@Override
public boolean deleteClothesService(String style) {
iClothesDao.deleteClothesDao(style);
return true;
}
/**
* 根据用户id更改服装信息
* @param id
* @return boolean
*/
@Override
public boolean addClothesService(Integer id) {
if (iClothesDao.updateClothesDao(id)){
return true;
}
return false;
}
/**
* 根据服装类型style查询服装信息ClothesService
* @param style
* @return List<Clothes>
*/
@Override
public List<Clothes> selectClothesByIdService(String style) {
List<Clothes> list=iClothesDao.selectClothesByIdDao("卫衣");
for (int i = 0; i <list.size() ; i++) {
System.out.println(list.get(i));
}
return null;
}
}
Service(User)接口
import studio.lemon.clothessystem.entity.User;
import java.io.IOException;
public interface IUserService {
/**
* 增加用户IUserservice
* @param user
* @return boolean
*/
boolean insertUserService(User user);
/**
* 根据用户id删除用户IUserservice
* @param id
* @return boolean
*/
boolean deleteUserService(Integer id);
/**
* 根据用户id更改用户信息IUseservice
* @param id
* @return boolean
*/
boolean updateUserService(User user,Integer id);
/**
* 根据密保问题question找回用户密码password
* @param question
* @return boolean
*/
boolean retrieveUserService(String question);
}
Service(User)实现
import studio.lemon.clothessystem.dao.IUserDao;
import studio.lemon.clothessystem.dao.impl.UserDaoImpl;
import studio.lemon.clothessystem.entity.User;
import studio.lemon.clothessystem.service.IUserService;
import java.io.IOException;
import java.util.List;
public class UserServiceImpl implements IUserService {
/**
* User创建Dao对象
*/
IUserDao iUserDao=new UserDaoImpl();
/**
* 增加用户IUserservice
* @param user
* @return boolean
* @throws IOException
*/
@Override
public boolean insertUserService(User user) {
List<User> userList=iUserDao.retrieveUserDao(user.getQuestion());
if (userList.size()==0){
iUserDao.insertUserDao(user);
System.out.println("用户添加成功");
return true;
}
System.out.println("用户添加失败");
return false;
}
/**
* 根据用户id删除用户IUserservice
* @param id
* @return boolean
* @throws IOException
*/
@Override
public boolean deleteUserService(Integer id) {
iUserDao.deleteUserDao(id);
return false;
}
/**
* 根据用户id更改用户信息IUseservice
* @param id
* @return boolean
* @throws IOException
*/
@Override
public boolean updateUserService(User user, Integer id) {
iUserDao.updateUserDao(user,id);
return false;
}
/**
* 根据密保问题question找回用户密码password
* @param question
* @return boolean
* throws IOException
*/
@Override
public boolean retrieveUserService(String question) {
iUserDao.retrieveUserDao(question);
return false;
}
}
Contoller(Clother)
import studio.lemon.clothessystem.entity.Clothes;
import studio.lemon.clothessystem.service.IClothesService;
import studio.lemon.clothessystem.service.impi.ClothesServiceImpl;
import java.util.List;
public class ClothesController {
IClothesService iClothesservice=new ClothesServiceImpl();
/**
* 增加服装ClothesDao
* @param clothes
* @return boolean
*/
public boolean insertClothesController(Clothes clothes) {
return iClothesservice.insertClothesService(clothes);
}
/**
* 根据服装类型style删除服装信息
*
* @param style
* @return boolean
*/
public boolean deleteClothesController(String style) {
return iClothesservice.deleteClothesService(style);
}
/**
* 根据用户id更改服装信息
* @param id
* @return boolean
*/
public boolean addClothesController(Integer id) {
return iClothesservice.addClothesService(id);
}
/**
* 根据服装类型style查询服装信息ClothesDao
*
* @param style
* @return List<Clothes>
*/
public List<Clothes> selectClothesController(String style) {
return iClothesservice.selectClothesByIdService(style);
}
}
Contoller(User)
import studio.lemon.clothessystem.entity.User;
import studio.lemon.clothessystem.service.IUserService;
import studio.lemon.clothessystem.service.impi.UserServiceImpl;
public class UserController {
IUserService iUserService=new UserServiceImpl();
/**
* 增加用户IUserService
* @param user
* @return boolean
*/
public boolean insertUserController(User user) {
return false;
}
/**
* 根据用户id删除用户IUserService
* @param id
* @return boolean
*/
public boolean deleteUserController(Integer id) {
return false;
}
/**
* 根据用户id更改用户信息IUseService
* @param id
* @return boolean
*/
public boolean updateUserController(User user, Integer id) {
return false;
}
/**
* 根据密保问题question找回用户密码password
* @param question
* @return boolean
*/
public boolean retrieveUserController(String question) {
return false;
}
}
Views(Clothers)
import studio.lemon.clothessystem.controller.ClothesController;
import studio.lemon.clothessystem.entity.Clothes;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
public class ClothesViews {
ClothesController clothesController=new ClothesController();
public void insertClothes(){
clothesController.insertClothesController(new Clothes("卫衣",2,"红色",7));
}
/**
* 服装信息删除
*/
public void deleteClothes() {
System.out.println("欢迎进入服装信息删除界面");
System.out.println("请输入您的账号(id)");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
try {
int id = Integer.parseInt(bufferedReader.readLine());
System.out.println(id);
if (id < 5) {
System.out.println("您没有权限");
} else if (id > 5 && id < 10) {
System.out.println("登陆成功" );
System.out.println("您想删除的服装类型是:1、卫衣 2、帽子 3、雪地靴");
String style = bufferedReader.readLine();
int a=Integer.parseInt(style);
if(a==1){
clothesController.deleteClothesController(style);
System.out.println("卫衣信息删除成功");
}
if(a==2){
clothesController.deleteClothesController(style);
System.out.println("帽子信息删除成功");
}if(a==3){
clothesController.deleteClothesController(style);
System.out.println("雪地靴信息删除成功");
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 更改服装信息
*/
public void addClothes(){
System.out.println("欢迎进入更改服装信息界面");
System.out.println("请输入您的账号(id)");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
try {
int id = bufferedReader.read();
if (id < 5) {
System.out.println("您没有权限");
} else if (id > 5 && id < 10) {
System.out.println("登陆成功" +
"目前您只能更改卫衣的信息");
clothesController.addClothesController(id);
}
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 查询服装信息
*/
public void selectClothes(){
System.out.println("您想查询的信息是");
ClothesController clothesController=new ClothesController();
System.out.println(clothesController.selectClothesController("1"));
}
}
View(User)
import studio.lemon.clothessystem.controller.UserController;
import studio.lemon.clothessystem.entity.User;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class UserVies {
UserController userController=new UserController();
/**
* 删除用户信息
*/
public void deleteUser() {
System.out.println("欢迎进入用户信息删除界面");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
int id = 0;
try {
id = bufferedReader.read();
userController.deleteUserController(id);
System.out.println("您已删除成功");
} catch (IOException e) {
e.printStackTrace();
}
}/**
* 增加用户IUserService
*/
public void insertUser(){
System.out.println("欢迎进入用户信息增加界面,请输入您的id");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
int id = 0;
try {
id = bufferedReader.read();
userController.insertUserController(new User(id));
} catch (IOException e) {
e.printStackTrace();
}
}
public void updateUser(){
System.out.println("欢迎进入用户信息更改界面");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
int id = 0;
try {
id = bufferedReader.read();
userController.updateUserController(new User(id),id);
System.out.println("您已修改成功");
} catch (IOException e) {
e.printStackTrace();
}
}
}
CView
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class CView {
UserVies userVies=new UserVies();
ClothesViews clothesViews=new ClothesViews();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String m;
public void CL(){
try {
System.out.println("欢迎进入服装管理系统,请先注册");
userVies.insertUser();
System.out.println("你已注册成功,可以查看信息");
clothesViews.selectClothes();
System.out.println("请问您是否要删除服装信息 1 是 2否");
m = bufferedReader.readLine();
switch (Integer.parseInt(m)){
case 1:
if (m.equals("1")){
clothesViews.deleteClothes();
}
case 2:
System.out.println("请问您是否要增加服装信息 1 是 2 否");
m = bufferedReader.readLine();
if (m.equals("1")){
clothesViews.addClothes();
System.out.println("增加成功");
}
break;
default:
System.out.println("输入指令异常");
break;
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Utils Create
import java.io.IOException;
public class Create {
public static void main(String[] args) throws IOException {
CreateFileName createFileName=new CreateFileName();
CreatePathName createPathName=new CreatePathName();
createPathName.create("ClothesSystem");
createFileName.create("ClothesSystem\\User.txt");
createFileName.create("ClothesSystem\\Clothes.txt");
}
}
Utils CreateFileName
import java.io.File;
import java.io.IOException;
public class CreateFileName {
//创建文件
public boolean create(String filename) throws IOException {
File file = new File(filename);
file.createNewFile();
if (file.exists()) {
return false;
}
if (file.createNewFile()) {
return true;
} else {
return false;
}
}
}
Utils
import java.io.File;
import java.io.IOException;
public class CreatePathName {
//创建目录
public boolean create(String Filename) throws IOException {
File file = new File(Filename);
if (file.exists()) {
return false;
}
if (!Filename.endsWith(File.separator)) {
Filename = Filename + File.separator;
}
if (file.mkdir()) {
return true;
} else {
return false;
}
}
}
博客介绍了Java项目的结构,包含Clothes和User的entity实体,对应的Dao接口及实现,Service接口及实现,Contoller和Views,还有CView和Utils相关内容,展示了项目各部分的构建。
985

被折叠的 条评论
为什么被折叠?



