• 基于SSM的图书管理系统


    一、系统简介

    该项目是基于Java的SSM框架实现的图书管理系统

    二、技术实现

    1.后台框架:Spring、SpringMVC、MyBatis、Ajax

    2.UI界面:BootStrap

    3.数据库:MySQL 5.7

    4.加密:md5+随机盐

    运行环境:

    JDK 8

    IntelliJ IDEA

    Tomcat 9.0

    MySQL 5.7

    三、系统功能

    系统共分为三种用户:

    1.普通用户

    书籍列表显示、书籍借阅、书籍归还,

    2.管理员

    用户管理(删除用户,修改用户名),图书管理(编辑,删除,添加)

    四、表设计

    一共有三张表,book用来存放书籍信息,

    bookorder用来保存借书记录和借还状态,user用来保存管理员和用户信息

    book表结构(status用来表示书的借还状态,0表示已还,1表示未还)

    bookorder表结构

    User表结构(grade用于区分角色身份,0是管理员,1是普通用户)

    五、运行效果

    系统登陆界面:

    注册界面(分为管理员注册和普通用户注册)

    管理员界面

    图书管理界面

    普通用户管理界面

    普通用户界面

    借还书籍操作界面

    需求分析:

    1.租书

    首先输入借书人名称,然后输入要借阅的图书编号,显示该图书信息(已经借出的图书不显示),

    2.还书

    首先输入借书人名称,显示该借书人的借阅图书信息,已还图书不显示。在显示借阅图书信息后,可以选择还书。

    3.租还查询

    选择该选项后,显示某个用户所有借书信息,

    图书类型管理图书类型信息包括:编号、名称

    4.添加图书

    接收用户输入的图书信息,写入数据库。

    5.修改图书

    用户输入要修改图书编号,显示图书信息,然后修改图书,并保存到数据库中。

    6.删除图书

    用户输入要删除图书编号,删除图书。

    7.查询全部图书

    选择该选项后,首先显示所有图书信息

    8.修改用户信息

    管理员可以修改用户的名称

    9.用户登录

    10.用户注册

    Entity****实体类

    public class Book {
    
    ??? private int bid;
    
    ??? private String bookname;
    
    ??? private String author;
    
    ??? private String detail;
    
    ??? private int status;//是否借出,1表示可以借,0表示不可借
    
    ??? private int price;
    
    ??? private String category;//种类
    
    }
    
    public class BookOrder {
    
    ??? /**
    
    ???? * 借书订单表
    
    ???? */
    
    ??? private int orderid;
    
    ??? private int userid;
    
    ??? private int bid;
    
    ??? private int orderstatus;//借还状态 0表示已归还,1表示未归还
    
    }
    
    public class User {
    
    ??? private int id;
    
    ??? private String username;
    
    ??? private String password;
    
    ??? private int grade;//角色
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47

    Controller****层

    @Controller
    
    @RequestMapping("/admin")
    
    public class AdminController {
    
    
    
    ??? @Autowired
    
    ??? private BookService bookService;
    
    
    
    ??? @Autowired
    
    ??? private UserService userService;
    
    
    
    ??? //跳转到图书管理页面
    
    ??? @RequestMapping("/bookManage.action")
    
    ??? public String skipBookManage(Model model){
    
    ??????? List<Book> list = bookService.selectAllBook();
    
    ??????? model.addAttribute("list",list);
    
    ??????? return "bookManage";
    
    ??? }
    
    
    
    ??? //跳转到读者管理页面
    
    ??? @RequestMapping("/commonUserManage.action")
    
    ??? public String skipCommonUserManage(){
    
    ??????? return "commonUserManage";
    
    ??? }
    
    
    
    ??? /**
    
    ???? * 读者操作
    
    ???? *? 可以让读者跳转到图书馆,User.jsp
    
    ???? */
    
    
    
    ??? //读者跳转到图书馆
    
    ??? @RequestMapping("/user.action")
    
    ??? public String skipUser(Model model,@Param("id") String username) throws UnsupportedEncodingException {
    
    ??????? //中文编码:
    
    ??????? /**
    
    ???????? * 在前端使用URL传递时,使用encodeURI(encodeURI(username))
    
    ???????? * 后端解析使用java.net.URLDecoder.decode(username,"UTF-8");
    
    ???????? */
    
    ??????? username = java.net.URLDecoder.decode(username,"UTF-8");
    
    ??????? System.out.println(username);
    
    ??????? model.addAttribute("user", userService.getUserByUserName(username).get(0));
    
    ??????? model.addAttribute("list",bookService.selectBookByStatus());
    
    ??????? return "user";
    
    ??? }
    
    
    
    ??? //跳转到admin.jsp
    
    ??? @RequestMapping("/admin.action")
    
    ??? public String skipAdmin(){
    
    ??????? return "admin";
    
    ??? }
    
    
    
    }
    
    
    @Controller
    
    @RequestMapping("/book")
    
    public class BookController {
    
    ??? @Autowired
    
    ??? private BookService bookService;
    
    ??? @Autowired
    
    ??? private BookOrderService bookOrderService;
    
    ??? //删除图书
    
    ??? @RequestMapping("/deleteById.action")
    
    ??? @ResponseBody
    
    ??? public Map<String,String> deleyeById(@RequestParam("bid") int bid){
    
    ??????? bookService.deleteBook(bid);
    
    ??????? Map map = new HashMap<String,String>();
    
    ??????? map.put("msg","删除成功");
    
    ??????? return map;
    
    ??? }
    
    ??? //添加图书
    
    ??? @RequestMapping("/addBook.action")
    
    ??? @ResponseBody
    
    ??? public int addBook(Book book){
    
    ??????? bookService.addBook(book);
    
    ??????? int i = bookService.selectLastNum();
    
    ??????? return i;
    
    ??? }
    
    ??? //修改图书
    
    ??? @RequestMapping("/modify.action")
    
    ??? @ResponseBody
    
    ??? public int modifyBook(Book book){
    
    ??????? System.out.println(book);
    
    ??????? bookService.modifyBook(book);
    
    ??????? return book.getBid();
    
    ??? }
    
    ??? //借书
    
    ??? /**
    
    ???? * 借书所要进行的操作:
    
    ???? *? 将书籍状态改为0
    
    ???? *? 在记录单上添加该用户的信息以及对应的书ID,并设置该订单状态为未完成(未还书,还书即算本次订单完成,未完成状态为1,完成状态为0)
    
    ???? * @param bid
    
    ???? */
    
    ??? @RequestMapping("/updateBookStatusToZero.action")
    
    ??? @ResponseBody
    
    ??? public int updateBookStatusToZero(@Param("id") int id ,@Param("bid") int bid){
    
    ??????? bookService.updateBookStatusToZero(bid);
    
    ??????? //借书订单添加用户以及对应的书籍ID
    
    ??????? bookOrderService.addOrder(id,bid);
    
    ??????? return bid;
    
    ??? }
    
    ??? //还书
    
    ??? @RequestMapping("/updateBookStatusToOne.action")
    
    ??? @ResponseBody
    
    ??? public int updateBookStatusToOne(@Param("bid") int bid){
    
    ??????? //根据书籍的id更改书籍的状态为1
    
    ??????? bookService.updateBookStatusToOne(bid);
    
    ??????? //将订单的状态更改为0(我的借还中书籍的状态需要是1)
    
    ??????? bookOrderService.updateOrderStatus(bid);
    
    ??????? return bid;
    
    ??? }
    
    }
    
    @Controller
    
    @RequestMapping("/login")
    
    public class UserController {
    
    ??? @Autowired
    
    ??? private BookService bookService;
    
    ??? @Autowired
    
    ??? private BookOrderService bookOrderService;
    
    ??? @Autowired
    
    ??? private UserService userService;
    
    ??? //登录校验
    
    ??? @RequestMapping("/checkLogin.action")
    
    ??? public String checkLogin(@RequestParam("username")String username, @RequestParam("password")String password, Model model){
    
    ??????? Map map = userService.checkLogin(username,password);//校验,返回不同的返回值和角色存入map集合
    
    ??????? if(map.get("result").equals("login")){
    
    ??????????? model.addAttribute("msg","账号或密码错误");
    
    ??????? }else if(map.get("result").equals("admin")) {
    
    ??????????? model.addAttribute("user",map.get("user"));//如果是管理员返回管理员管理初始界面,并把管理员存入Attribute
    
    ??????? }else{//user
    
    ??????????? List<Book> list = bookService.selectBookByStatus();//如果是普通用户,返回书籍展示页面并把普通用户存入Attribute
    
    ??????????? model.addAttribute("list",list);
    
    ??????????? model.addAttribute("user",map.get("user"));
    
    ??????? }
    
    ??????? return (String)map.get("result");//返回角色信息或者错误信息,经过前端ajax判断,如果不是错误信息,跳转到user或者admin的action里
    
    ??? }
    
    ?? //用户注册功能实现
    
    ??? @RequestMapping(value = "/addUser.action")
    
    ??? @ResponseBody()
    
    ??? public Map<String, Boolean> addUser(User user, HttpServletRequest request, HttpServletResponse res) throws UnsupportedEncodingException {
    
    ??????? Map<String , Boolean> map = new HashMap<>();
    
    ??????? if(!userService.isInserUser(user)){//不可插入
    
    ??????????? map.put("isUse",false);
    
    ??????????? return map;
    
    ??????? }
    
    ??????? //对用户的密码进行md5加密
    
    ??????? String pwd = SecureUtil.md5(user.getPassword() + user.getUsername());
    
    ??????? user.setPassword(pwd);//把加密的密码设置给user
    
    ??????? userService.addUser(user);//执行添加操作
    
    ??????? map.put("msg",true);
    
    ??????? return map;
    
    ??? }
    
    ??? //用户注册
    
    ??? //跳转到register.jsp
    
    ??? @RequestMapping("/register.action")
    
    ??? public String register(){
    
    ??????? return "register";
    
    ??? }
    
    ??? /*//前端跳转到的页面,暂未启用
    
    ??? @RequestMapping("/admin.action")
    
    ??? public String admin(int id){//传递的参数仅为跳转那个页面
    
    ??????? /*String result;
    
    ??????? if(id == 1){
    
    ??????????? result = "bookManage";
    
    ??????? }else if(id == 2){
    
    ??????????? result = "";
    
    ??????? }
    
    ??????? return result;
    
    ??????? return "";
    
    ??? }*/
    
    ??? //获取所有的普通User
    
    ??? //跳转到getCommonUser.jsp
    
    ??? @RequestMapping("/getCommonUser.action")
    
    ??? public String getCommonUser(Model model){
    
    ??????? model.addAttribute("list",userService.getCommonUser());
    
    ??????? return "commonUserManage";
    
    ??? }
    
    ??? //删除某一个用户
    
    ??? //跳转到deleteUser.jsp
    
    ??? @RequestMapping("/deleteUser.action")
    
    ??? @ResponseBody
    
    ??? public Map<String ,String> deleteUser(@Param("id") int id){
    
    ??????? userService.deleteUser(id);
    
    ??????? Map<String,String> map = new HashMap<>();
    
    ??????? map.put("msg","删除成功!");
    
    ??????? return map;
    
    ??? }
    
    ??? //修改一个用户
    
    ??? //跳转到modifyUser.jsp
    
    ??? @RequestMapping("/modifyUser.action")
    
    ??? @ResponseBody
    
    ??? public int modifyUser(User user){
    
    ??????? System.out.println(user);
    
    ??????? userService.modifyUser(user);
    
    ??????? return user.getId();
    
    ??? }
    
    ??? //跳转到login.jsp
    
    ??? @RequestMapping("/login.action")
    
    ??? public String login(){
    
    ??????? return "login";
    
    ??? }
    
    ??? //我的借还跳转
    
    ??? //跳转到myBorrow.jsp
    
    ??? @RequestMapping("/myBorrow.action")
    
    ??? public String myBorrow(Model model,int id){//一个参数为user 的id
    
    ??????? List<Book> list = bookOrderService.myBorrow(id);
    
    ?? ?????model.addAttribute("list",list);//传递的是我的借还的这个书籍id
    
    ??????? model.addAttribute("user",userService.getUserById(id).get(0));
    
    ??????? return "myBorrow";
    
    ??? }
    
    ??? //我的借还跳转到User.jsp
    
    ??? @RequestMapping("/user.action")
    
    ??? public String jumpUser(Model model,@Param("id") int id){
    
    ??????? //该方法需要传递一个书籍状态为1的书籍列表,key为list
    
    ??????? //还有一个是user的实例
    
    ??????? //user实例的获取:
    
    ??????? model.addAttribute("user",userService.getUserById(id).get(0));
    
    ??????? List<Book> list = bookService.selectBookByStatus();
    
    ?????? ?model.addAttribute("list",list);
    
    ??????? return "user";
    
    ??? }
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    • 309
    • 310
    • 311
    • 312
    • 313
    • 314
    • 315
    • 316
    • 317
    • 318
    • 319
    • 320
    • 321
    • 322
    • 323
    • 324
    • 325
    • 326
    • 327
    • 328
    • 329
    • 330
    • 331
    • 332
    • 333
    • 334
    • 335
    • 336
    • 337
    • 338
    • 339
    • 340
    • 341
    • 342
    • 343
    • 344
    • 345
    • 346
    • 347
    • 348
    • 349
    • 350
    • 351
    • 352
    • 353
    • 354
    • 355
    • 356
    • 357
    • 358
    • 359
    • 360
    • 361
    • 362
    • 363
    • 364
    • 365
    • 366
    • 367
    • 368
    • 369
    • 370
    • 371
    • 372
    • 373
    • 374
    • 375
    • 376
    • 377
    • 378
    • 379
    • 380
    • 381
    • 382
    • 383
    • 384
    • 385
    • 386
    • 387
    • 388
    • 389
    • 390
    • 391
    • 392
    • 393
    • 394
    • 395
    • 396
    • 397
    • 398
    • 399
    • 400
    • 401
    • 402
    • 403
    • 404
    • 405
    • 406
    • 407
    • 408
    • 409
    • 410
    • 411
    • 412
    • 413
    • 414
    • 415
    • 416
    • 417
    • 418
    • 419
    • 420
    • 421
    • 422
    • 423
    • 424
    • 425
    • 426
    • 427
    • 428
    • 429
    • 430
    • 431
    • 432
    • 433
    • 434
    • 435
    • 436
    • 437
    • 438

    Service****层

    public interface UserService {
    
    ??? //检查登录
    
    ??? public Map checkLogin(String username, String password);
    
    ??? //添加用户
    
    ??? public void addUser(User user);
    
    ??? //查询根据用户名是否有重名
    
    ??? public boolean isInserUser(User user);
    
    ??? //查询所有的普通用户
    
    ??? public List<User> getCommonUser();
    
    ??? //删除用户
    
    ??? public void deleteUser(int id);
    
    ??? //修改用户
    
    ??? public void modifyUser(User user);
    
    ??? //根据id查询用户
    
    ??? public List<User> getUserById(int id);
    
    ??? public List<User> getUserByUserName(String username);
    
    }
    
    
    
    public interface BookService {
    
    ??? //查询所有书籍
    
    ??? public List<Book> selectAllBook();
    
    ??? //添加书籍
    
    ??? public int addBook(Book book);
    
    ??? //删除图书
    
    ??? public void deleteBook(int bid);
    
    ??? //修改图书
    
    ??? public void modifyBook(Book book);
    
    ??? //查询库存
    
    ??? public int selectBookNumByBookName(String bookname);
    
    ??? //根据作者名查询图书
    
    ??? public List<Book> selectBookByAuthor(String author);
    
    ??? //查询最后一个主键
    
    ??? public int selectLastNum();
    
    ??? //查询图书状态为1的图书list,即可借状态
    
    ??? public List<Book> selectBookByStatus();
    
    ??? //借书
    
    ??? public void updateBookStatusToZero(int bid);
    
    ??? //还书
    
    ??? public void updateBookStatusToOne(int bid);
    
    }
    
    public interface BookOrderService {
    
    ??? /**
    
    ???? * 添加图书订单
    
    ??? ?* 更改订单状态
    
    ???? */
    
    ??? public void addOrder(int userId, int bid);
    
    ??? public void updateOrderStatus(int bid);
    
    ??? //查询我的借还
    
    ??? public List<Book> myBorrow(int id);
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99

    Dao****层

    public interface BookDao {
    
    ??? /**
    
    ???? * 书的操作:
    
    ???? *? 查询所有图书
    
    ???? *? 添加图书
    
    ???? *? 删除图书
    
    ???? *? 根据作者名查询图书
    
    ???? *
    
    ???? */
    
    ??? @Select("select * from book")
    
    ??? public List<Book> selectAllBook();
    
    ??? @Insert("insert into book(bookname,author,detail,status,price,category) value(#{bookname},#{author},#{detail},${status},${price},#{category})")
    
    ??? public void addBook(Book book);
    
    ??? //查找最后一条记录的主键
    
    ??? @Select("select max(bid) from book")
    
    ??? public List<Integer> selectLastNum();
    
    
    ??? @Delete("delete from book where bid = #{bid}")
    
    ??? public void deleteBookById(int bid);
    
    
    ??? @Select("select count(*) from book where bookname like #{bookname}")
    
    ??? public int selectAllNum(String bookName);
    
    
    ??? @Select("select * from book where author like #{author}")
    
    ??? public List<Book> selectBookByAuthor(String author);
    
    ??? //根据状态查询书籍,查询书籍状态为1的书籍,可借状态
    
    ??? @Select("select * from book where status = 1")
    
    ??? public List<Book> selectBookByStatus();
    
    
    ??? //借书,即将书籍状态改为0
    
    ??? @Select("update book set status = 0 where bid = #{bid}")
    
    ??? public void updateBookStatusToZero(int bid);
    
    
    ??? //还书,即将书籍状态改为1
    
    ??? @Select("update book set status = 1 where bid = #{bid}")
    
    ??? public void updateBookStatusToOne(int bid);
    
    
    ??? //修改图书
    
    ??? @Update("update book set bookname=#{bookname},author=#{author},detail=#{detail},price=#{price},category=#{category} where bid = #{bid}")
    
    ??? public void modifyBook(Book book);
    
    }
    
    public interface BookOrderDao {
    
    ??? /**
    
    ???? * 图书订单Dao
    
    ???? * 新建图书订单,UserId,BookId,订单状态为1,(订单状态为0时表示已还)
    
    ???? * 还书操作:将订单状态置为0
    
    ???? */
    
    
    ??? //添加订单,当进行借书操作时需要
    
    ??? @Insert("insert into bookorder(userid,bid,orderstatus) values(${id},${bid},1)")
    
    ??? public void addOrder(@Param("id") int id, @Param("bid") int bid);
    
    
    ??? //将订单状态置为0,表示已还,当进行还书操作时需要
    
    ??? @Update("update bookorder set orderstatus = 0 where bid = #{bid}")
    
    ??? public void updataOrderStatus(int bid);
    
    
    ??? //根据userid查询对应的用户所有的订单
    
    ??? @Select("SELECT * FROM book where bid = ANY(SELECT bid from bookorder WHERE userid = #{id} and orderstatus = 1)")
    
    ??? public List<Book> selectOrder(int id);//用户的id
    
    }
    
    public interface UserDao {
    
    ??? /**
    
    ???? * 用户表操作的接口
    
    ???? *? 方法有:
    
    ???? *????? 给定用户名,查询密码
    
    ???? *????? 添加用户
    
    ???? */
    
    ??? //获取用户
    
    ??? @Select("select * from user where username = #{username}")
    
    ??? public List<User> getUser(String username);
    
    
    ??? @Insert("insert into user(username,password,grade) value(#{username},#{password},#{grade})")
    
    ??? public void addUser(User user);
    
    
    ??? //查询所有普通用户
    
    ??? @Select("select * from user where grade = 1")
    
    ??? public List<User> getCommonUser();
    
    ??? //删除指定用户
    
    ??? @Delete("delete from user where id = #{id}")
    
    ??? public void deleteUser(int id);
    
    ??? @Update("update user set username = #{username},password = #{password} where id = #{id}")
    
    ??? public void modifyUser(User user);
    
    
    ??? //根据用户id获取用户信息
    
    ??? @Select("select * from user where id = #{id}")
    
    ??? public List<User> getUserById(int id);
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161

    ApplicationContext.xml****配置

    <?xml version="1.0" encoding="UTF-8"?>
    
    <beans xmlns="http://www.springframework.org/schema/beans"
    
    ?????? xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    
    ?????? xmlns:context="http://www.springframework.org/schema/context"
    
    ?????? xmlns:aop="http://www.springframework.org/schema/aop"
    
    ?????? xmlns:tx="http://www.springframework.org/schema/tx"
    
    ?????? xsi:schemaLocation="http://www.springframework.org/schema/beans
    
    ?????? http://www.springframework.org/schema/beans/spring-beans.xsd
    
    ?????? http://www.springframework.org/schema/context
    
    ?????? http://www.springframework.org/schema/context/spring-context.xsd
    
    ?????? http://www.springframework.org/schema/aop
    
    ?????? http://www.springframework.org/schema/aop/spring-aop.xsd
    
    ?????? http://www.springframework.org/schema/tx
    
    ?????? http://www.springframework.org/schema/tx/spring-tx.xsd">
    
    
    ??? <!--开启注解的扫描,希望处理service和dao,controller不需要Spring框架去处理-->
    
    ??? <context:component-scan base-package="com.gx" >
    
    ??????? <!--配置哪些注解不扫描-->
    
    ??????? <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
    
    ??? </context:component-scan>
    
    
    ??? <!--Spring整合MyBatis框架-->
    
    ??? <!--配置连接池-->
    
    ??? <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    
    ??????? <property name="driverClass" value="com.mysql.jdbc.Driver"/>
    
    ??????? <property name="jdbcUrl" value="jdbc:mysql:///bookm?useUnicode=true&amp;characterEncoding=utf8&amp;serverTimezone=CST"/>
    
    ??????? <property name="user" value="root"/>
    
    ?????? ?<property name="password" value="zwh19991219"/>
    
    ??? </bean>
    
    
    ??? <!--配置SqlSessionFactory工厂-->
    
    ??? <bean id="sqlSessonFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    
    ??????? <property name="dataSource" ref="dataSource"/>
    
    ??? </bean>
    
    
    ??? <!--配置IAccountdao接口所在包-->
    
    ??? <bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    
    ??????? <property name="basePackage" value="com.gx.dao"/>
    
    ??? </bean>
    
    ??? <!--配置Spring框架声明式事务管理-->
    
    ??? <!--配置事务管理器-->
    
    ??? <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    
    ??????? <property name="dataSource" ref="dataSource" />
    
    ??? </bean>
    
    
    ??? <!--配置事务通知-->
    
    ??? <tx:advice id="txAdvice" transaction-manager="transactionManager">
    
    ??????? <tx:attributes>
    
    ??????????? <tx:method name="find*" read-only="true"/>
    
    ??????????? <tx:method name="*" isolation="DEFAULT"/>
    
    ??????? </tx:attributes>
    
    ??? </tx:advice>
    
    ??? <!--配置AOP增强-->
    
    ??? <aop:config>
    
    ??????? <aop:advisor advice-ref="txAdvice" pointcut="execution(* com.gx.service.impl.*ServiceImpl.*(..))"/>
    
    ??? </aop:config>
    
    </beans>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108

    Springmvc.xml****配置

    <?xml version="1.0" encoding="UTF-8"?>
    
    <beans xmlns="http://www.springframework.org/schema/beans"
    
    ?????? xmlns:mvc="http://www.springframework.org/schema/mvc"
    
    ?????? xmlns:context="http://www.springframework.org/schema/context"
    
    ?????? xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    
    ?????? xsi:schemaLocation="
    
    ??????? http://www.springframework.org/schema/beans
    
    ??????? http://www.springframework.org/schema/beans/spring-beans.xsd
    
    ??????? http://www.springframework.org/schema/mvc
    
    ??????? http://www.springframework.org/schema/mvc/spring-mvc.xsd
    
    ??????? http://www.springframework.org/schema/context
    
    ??????? http://www.springframework.org/schema/context/spring-context.xsd">
    
    ??? <!--开启注解扫描,只扫描Controller注解-->
    
    ??? <context:component-scan base-package="com.gx">
    
    ??????? <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    
    ??? </context:component-scan>
    
    
    ??? <!--配置的视图解析器对象-->
    
    ??? <bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    
    ??????? <property name="prefix" value="/WEB-INF/pages/"/>
    
    ??????? <property name="suffix" value=".jsp"/>
    
    ??? </bean>
    
    ??? <!--过滤静态资源-->
    
    ??? <mvc:resources location="/css" mapping="/css/**"/>
    
    ??? <mvc:resources location="/js/" mapping="/js/**"/>
    
    ??? <mvc:resources location="/images/" mapping="/images/**"/>
    
    ??? <!--开启SpringMVC注解的支持-->
    
    ??? <mvc:annotation-driven/>
    
    </beans>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56

    需要项目源码可直接点资源下载

    也可以加我个人QQ:903985300 私发给你

    注意:开发软件IDEA,如果是ecplise的读者,需要上网查找IDEA转ecplise的方法

  • 相关阅读:
    partial的使用,对定制化的想法
    基于.NET Core + Quartz.NET+ Vue + IView开箱即用的定时任务UI
    4.1_5 文件存储空间管理
    23 DRF快速入门+部分源码分析
    必须收藏!没有经验的程序员该怎么找工作?
    【MySQL运行原理篇】底层运行结构
    JavaWeb--04YApi,Vue-cli脚手架Node.js环境搭建,创建第一个Vue项目
    瀑布流布局(网格)
    Java集合框架面试指南
    WIFI6E中的MESH组网功能
  • 原文地址:https://blog.csdn.net/m0_67392010/article/details/125398951