写出Java代码,线上账本管理系统,功能需求: (1)用户管理:实现系统用户登录功能; (2)账本管理:实现账单类型的增、改、删;账本信息(包括收入、支出的详细信息)的增、删、改、查。 (3)账单管理:日账单导出,用户单天账单信息的查询、导出;年账单导出,用户全年账单信息的查询、导出;用户年账单的统计。 (4)用户日常管理:用户日程、纪念日、重要事件的增、删、改、查,并向用户发送提醒信息。 (5)用户反馈管理:向小程序作者发送反馈消息。
时间: 2023-11-21 11:05:34 浏览: 52
用JAVA编写的账本程序(源代码)
抱歉,由于篇幅限制,我无法在这里展示完整的Java代码。但我可以给你提供一个大致的代码框架,供你参考。
1. 用户管理
- 用户实体类
```
public class User {
private Long id;
private String username;
private String password;
private String email;
private String phoneNumber;
// getter and setter
}
```
- 用户登录控制器
```
@Controller
public class LoginController {
@Autowired
private UserService userService;
@GetMapping("/login")
public String login() {
return "login";
}
@PostMapping("/login")
public String login(String username, String password, HttpSession session) {
User user = userService.login(username, password);
if (user != null) {
session.setAttribute("user", user);
return "redirect:/home";
} else {
return "login";
}
}
}
```
2. 账本管理
- 账单类型实体类
```
public class BillType {
private Long id;
private String name;
// getter and setter
}
```
- 账单实体类
```
public class Bill {
private Long id;
private BigDecimal amount;
private Date date;
private String remark;
private BillType type;
private User user;
// getter and setter
}
```
- 账单管理控制器
```
@Controller
public class BillController {
@Autowired
private BillService billService;
@GetMapping("/bill")
public String list(Model model) {
List<Bill> bills = billService.getAllBills();
model.addAttribute("bills", bills);
return "bill/list";
}
@GetMapping("/bill/add")
public String add(Model model) {
List<BillType> types = billService.getAllBillTypes();
model.addAttribute("types", types);
return "bill/add";
}
@PostMapping("/bill/add")
public String add(Bill bill, HttpSession session) {
User user = (User) session.getAttribute("user");
bill.setUser(user);
billService.addBill(bill);
return "redirect:/bill";
}
@GetMapping("/bill/edit/{id}")
public String edit(@PathVariable Long id, Model model) {
Bill bill = billService.getBillById(id);
List<BillType> types = billService.getAllBillTypes();
model.addAttribute("bill", bill);
model.addAttribute("types", types);
return "bill/edit";
}
@PostMapping("/bill/edit")
public String edit(Bill bill) {
billService.updateBill(bill);
return "redirect:/bill";
}
@GetMapping("/bill/delete/{id}")
public String delete(@PathVariable Long id) {
billService.deleteBill(id);
return "redirect:/bill";
}
}
```
3. 账单管理
- 账单管理控制器
```
@Controller
public class BillManageController {
@Autowired
private BillService billService;
@GetMapping("/bill/export/day")
public void exportDayBill(Date date, HttpServletResponse response) {
List<Bill> bills = billService.getDayBills(date);
// 导出Excel或CSV文件
}
@GetMapping("/bill/export/year")
public void exportYearBill(Integer year, HttpServletResponse response) {
List<Bill> bills = billService.getYearBills(year);
// 导出Excel或CSV文件
}
@GetMapping("/bill/statistics/year")
public String statisticsYearBill(Integer year, Model model) {
BigDecimal income = billService.getYearIncome(year);
BigDecimal expense = billService.getYearExpense(year);
model.addAttribute("income", income);
model.addAttribute("expense", expense);
return "bill/statistics";
}
}
```
4. 用户日常管理
- 日程实体类
```
public class Schedule {
private Long id;
private String name;
private Date date;
private String remark;
private User user;
// getter and setter
}
```
- 日程管理控制器
```
@Controller
public class ScheduleController {
@Autowired
private ScheduleService scheduleService;
@GetMapping("/schedule")
public String list(Model model) {
List<Schedule> schedules = scheduleService.getAllSchedules();
model.addAttribute("schedules", schedules);
return "schedule/list";
}
@GetMapping("/schedule/add")
public String add() {
return "schedule/add";
}
@PostMapping("/schedule/add")
public String add(Schedule schedule, HttpSession session) {
User user = (User) session.getAttribute("user");
schedule.setUser(user);
scheduleService.addSchedule(schedule);
return "redirect:/schedule";
}
@GetMapping("/schedule/edit/{id}")
public String edit(@PathVariable Long id, Model model) {
Schedule schedule = scheduleService.getScheduleById(id);
model.addAttribute("schedule", schedule);
return "schedule/edit";
}
@PostMapping("/schedule/edit")
public String edit(Schedule schedule) {
scheduleService.updateSchedule(schedule);
return "redirect:/schedule";
}
@GetMapping("/schedule/delete/{id}")
public String delete(@PathVariable Long id) {
scheduleService.deleteSchedule(id);
return "redirect:/schedule";
}
}
```
5. 用户反馈管理
- 反馈实体类
```
public class Feedback {
private Long id;
private String content;
private User user;
// getter and setter
}
```
- 反馈管理控制器
```
@Controller
public class FeedbackController {
@Autowired
private FeedbackService feedbackService;
@GetMapping("/feedback")
public String add() {
return "feedback/add";
}
@PostMapping("/feedback")
public String add(Feedback feedback, HttpSession session) {
User user = (User) session.getAttribute("user");
feedback.setUser(user);
feedbackService.addFeedback(feedback);
return "redirect:/feedback";
}
}
```
以上只是一个大致的代码框架,具体实现还需要进一步细化和完善。
阅读全文