21xrx.com
2025-03-17 01:20:33 Monday
文章检索 我的文章 写文章
JavaEE期末大作业设计与实现——一个基于Spring Boot的图书管理系统
2023-06-14 06:24:47 深夜i     175     0
JavaEE Spring

随着JavaEE课程的深入学习,我们不仅学习了JavaEE的基础知识,还学习了一些常用框架的应用。在期末大作业中,我们需要将所学的知识应用到实际项目中,设计并实现一个完整的Web应用系统。

这里我们设计并实现了一个基于Spring Boot框架的图书管理系统。系统分为前台展示和后台管理两部分,前台主要展示书籍信息和借阅归还等功能,后台管理则包括对图书、借阅者、借阅记录等信息进行管理。

系统中主要采用了Spring Boot框架的许多功能模块,如SpringMVC用于控制层的实现,MyBatis用于持久层的实现。同时,使用了一些常用的开源框架,如Spring Security进行用户认证和授权、Thymeleaf进行前端界面渲染。

下面是部分代码案例:

1. MyBatis Mapper接口和XML映射文件实现:

public interface BookMapper {
  //根据id查询图书信息
  public Book getBookById(Integer id);
  //查询所有图书信息
  public List
  getAllBooks();
 
  //添加图书信息
  public int addBook(Book book);
  //更新图书信息
  public int updateBook(Book book);
  //删除图书信息
  public int deleteBook(Integer id);
}

bookMapper.xml文件:

select id,bookname,author,price,stock from book where id=#{id}

2. Spring Security配置实现:

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
  @Autowired
  private CustomUserDetailsService userDetailsService;
  @Autowired
  private CustomAuthenticationSuccessHandler successHandler;
  @Bean
  public PasswordEncoder passwordEncoder(){
    return new BCryptPasswordEncoder();
  }
  @Override
  protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
  }
  @Override
  protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
        .antMatchers("/login").permitAll()
        .antMatchers("/admin/**").hasRole("admin")
        .anyRequest().authenticated()
        .and()
        .formLogin()
        .loginPage("/login")
        .successHandler(successHandler)
        .and()
        .logout()
        .logoutUrl("/logout")
        .logoutSuccessUrl("/")
        .and()
        .csrf().disable();
  }
}

3. Thymeleaf模板实现:

图书管理系统
   
 
  

     
 图书列表
     
       
         
           
           
           
           
           
         
       
       
         
           
           
           
           
           
         
       
     
 
  
   
    ID
    书名
    作者
    价格
    库存

通过JavaEE期末大作业的设计与实现,我们不仅对JavaEE的各个模块有了更深入的理解,也掌握了一些实际应用的开发技能,在以后的学习和工作中将会受益无穷。

Boot、图书管理系统。

  
  

评论区