溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Java如何實(shí)現(xiàn)在線購書商城系統(tǒng)

發(fā)布時(shí)間:2021-11-12 13:44:00 來源:億速云 閱讀:189 作者:小新 欄目:開發(fā)技術(shù)

這篇文章主要為大家展示了“Java如何實(shí)現(xiàn)在線購書商城系統(tǒng)”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“Java如何實(shí)現(xiàn)在線購書商城系統(tǒng)”這篇文章吧。

一、項(xiàng)目簡述

功能:一個(gè)基于JavaWeb的網(wǎng)上書店的設(shè)計(jì)與實(shí)現(xiàn),歸納 出了幾個(gè)模塊,首先是登錄注冊模塊,圖書查找模塊,購 物車模塊,訂單模塊,個(gè)人中心模塊,用戶管理模塊,圖 書管理模塊等。 該項(xiàng)目是javaJeb技術(shù)的實(shí)戰(zhàn)操作,采用了MVC設(shè)計(jì)模 式,包括基本的entity, jscript, servlet,以及ajax異步請 求,查詢分頁,持久化層方法的封裝等等,對javaweb技 術(shù)的鞏固很有幫助,為J2EE的學(xué)習(xí)打下基礎(chǔ),適用于課程 設(shè)計(jì),畢業(yè)設(shè)計(jì)。

二、項(xiàng)目運(yùn)行

環(huán)境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)。

項(xiàng)目技術(shù): JSP + Entity+ Servlert + html+ css + JavaScript + JQuery + Ajax + Fileupload 等等。

Java如何實(shí)現(xiàn)在線購書商城系統(tǒng)

Java如何實(shí)現(xiàn)在線購書商城系統(tǒng)

Java如何實(shí)現(xiàn)在線購書商城系統(tǒng)

Java如何實(shí)現(xiàn)在線購書商城系統(tǒng)

書信息管理代碼:

書信息管理:
 
@Controller
@RequestMapping("/book")
public class BookInfoController {
 
 
 
    @Autowired
    private IBookInfoService bookInfoService;
 
    @Autowired
    private BookDescMapper bookDescMapper;
 
    /**
     * 查詢某一本書籍詳情
     *
     * @param bookId
     * @param model
     * @return
     */
    @RequestMapping("/info/{bookId}")
    public String bookInfo(@PathVariable("bookId") Integer bookId, Model model) throws BSException {
        //查詢書籍
        BookInfo bookInfo = bookInfoService.findById(bookId);
        //查詢書籍推薦列表
        List<BookInfo> recommendBookList = bookInfoService.findBookListByCateId(bookInfo.getBookCategoryId(), 1, 5);
        //查詢書籍詳情
        BookDesc bookDesc = bookDescMapper.selectByPrimaryKey(bookId);
        //增加訪問量
        bookInfoService.addLookMount(bookInfo);
        Collections.shuffle(recommendBookList);
        model.addAttribute("bookInfo", bookInfo);
        model.addAttribute("bookDesc", bookDesc);
        model.addAttribute("recommendBookList", recommendBookList);
        return "book_info";
    }
 
 
    /**
     * 通過關(guān)鍵字和書籍分類搜索書籍列表
     *
     * @param keywords
     * @return
     */
    @RequestMapping("/list")
    public String bookSearchList(@RequestParam(defaultValue = "", required = false) String keywords,
                                 @RequestParam(defaultValue = "0", required = false) int cateId,//分類Id,默認(rèn)為0,即不按照分類Id查
                                 @RequestParam(defaultValue = "1", required = false) int page,
                                 @RequestParam(defaultValue = "6", required = false) int pageSize,
                                 Model model) {
        keywords = keywords.trim();
        PageInfo<BookInfo> bookPageInfo = bookInfoService.findBookListByCondition(keywords, cateId, page, pageSize,0);//storeId為0,不按照商店Id查詢
 
        model.addAttribute("bookPageInfo", bookPageInfo);
 
        model.addAttribute("keywords", keywords);
 
        model.addAttribute("cateId", cateId);
 
        return "book_list";
    }
 
}

shiro安全框架配置代碼:

@Configuration
/**
 * shiro安全框架
 */
public class ShiroConfig {
 
 
    @Bean(name = "lifecycleBeanPostProcessor")
    public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
        return new LifecycleBeanPostProcessor();
    }
 
    @Bean
    public SecurityManager securityManager(EhCacheManager ehCacheManager) {
        DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
        securityManager.setRealm(myShiroRealm());
        //securityManager.setRememberMeManager(rememberMeManager());
        securityManager.setCacheManager(ehCacheManager);
        return securityManager;
    }
 
 
    @Bean
    public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager) {
 
        ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
        shiroFilterFactoryBean.setSecurityManager(securityManager);
 
        Map<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
 
        //攔截器
        filterChainDefinitionMap.put("/img/**", "anon");
        filterChainDefinitionMap.put("/fonts/**", "anon");
        filterChainDefinitionMap.put("/static/**", "anon");
        filterChainDefinitionMap.put("/css/**", "anon");
        filterChainDefinitionMap.put("/js/**", "anon");
        filterChainDefinitionMap.put("/book/**", "anon");
        filterChainDefinitionMap.put("/upload/**", "anon");
        filterChainDefinitionMap.put("/page/**", "anon");
        filterChainDefinitionMap.put("/user/info", "user");
        filterChainDefinitionMap.put("/user/**", "anon");//用戶登錄注冊不需要權(quán)限
 
        filterChainDefinitionMap.put("/index/**",   "anon");//首頁放行
        filterChainDefinitionMap.put("/", "anon");
 
        //配置退出 過濾器,其中的具體的退出代碼Shiro已經(jīng)替我們實(shí)現(xiàn)了
        filterChainDefinitionMap.put("/user/logout", "logout");
        //<!-- 過濾鏈定義,從上向下順序執(zhí)行,一般將/**放在最為下邊 -->:這是一個(gè)坑呢,一不小心代碼就不好使了;
        //<!-- authc:所有url都必須認(rèn)證通過才可以訪問; anon:所有url都都可以匿名訪問-->
 
        //filterChainDefinitionMap.put("/admin/**", "roles[admin]");//perms[system]
        filterChainDefinitionMap.put("/**", "authc");
 
 
        // 如果不設(shè)置默認(rèn)會自動尋找Web工程根目錄下的"/login.jsp"頁面
        shiroFilterFactoryBean.setLoginUrl("/page/login");
        // 登錄成功后要跳轉(zhuǎn)的鏈接
        shiroFilterFactoryBean.setSuccessUrl("/index");
 
        //未授權(quán)界面;
        shiroFilterFactoryBean.setUnauthorizedUrl("/403");
        shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
        return shiroFilterFactoryBean;
    }
 
    @Bean
    @DependsOn("lifecycleBeanPostProcessor")
    public MyShiroRealm myShiroRealm() {
        MyShiroRealm myShiroRealm = new MyShiroRealm();
        myShiroRealm.setCredentialsMatcher(hashedCredentialsMatcher());
        myShiroRealm.setCachingEnabled(true);
        //啟用身份驗(yàn)證緩存,即緩存AuthenticationInfo信息,默認(rèn)false
        myShiroRealm.setAuthenticationCachingEnabled(true);
        //緩存AuthenticationInfo信息的緩存名稱 在ehcache.xml中有對應(yīng)緩存的配置
        myShiroRealm.setAuthenticationCacheName("authenticationCache");
        //啟用授權(quán)緩存,即緩存AuthorizationInfo信息,默認(rèn)false
        myShiroRealm.setAuthorizationCachingEnabled(true);
        //緩存AuthorizationInfo信息的緩存名稱  在ehcache.xml中有對應(yīng)緩存的配置
        myShiroRealm.setAuthorizationCacheName("authorizationCache");
        return myShiroRealm;
    }
 
    /**
     *  開啟shiro aop注解支持.
     *  使用代理方式;所以需要開啟代碼支持;
     * @param securityManager
     * @return
     */
    @Bean
    public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager){
        AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();
        authorizationAttributeSourceAdvisor.setSecurityManager(securityManager);
        return authorizationAttributeSourceAdvisor;
    }
 
    @Bean
    public DefaultAdvisorAutoProxyCreator getDefaultAdvisorAutoProxyCreator() {
        DefaultAdvisorAutoProxyCreator daap = new DefaultAdvisorAutoProxyCreator();
        daap.setProxyTargetClass(true);
        return daap;
    }
 
    /**
     * 憑證匹配器
     * (由于我們的密碼校驗(yàn)交給Shiro的SimpleAuthenticationInfo進(jìn)行處理了
     * )
     *
     * @return
     */
    @Bean
    public HashedCredentialsMatcher hashedCredentialsMatcher() {
        HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher();
        hashedCredentialsMatcher.setHashAlgorithmName("md5");//散列算法:這里使用MD5算法;
        hashedCredentialsMatcher.setHashIterations(1);//散列的次數(shù),比如散列兩次,相當(dāng)于 md5(md5(""));
        return hashedCredentialsMatcher;
    }
 
 
    /**
     * cookie對象;
     * rememberMeCookie()方法是設(shè)置Cookie的生成模版,比如cookie的name,cookie的有效時(shí)間等等。
     * @return
     */
    /*@Bean
    public SimpleCookie rememberMeCookie(){
        //這個(gè)參數(shù)是cookie的名稱,對應(yīng)前端的checkbox的name = rememberMe
        SimpleCookie simpleCookie = new SimpleCookie("rememberMe");
        //如果httyOnly設(shè)置為true,則客戶端不會暴露給客戶端腳本代碼,使用HttpOnly cookie有助于減少某些類型的跨站點(diǎn)腳本攻擊;
        simpleCookie.setHttpOnly(true);
        //記住我cookie生效時(shí)間,默認(rèn)30天 ,單位秒:60 * 60 * 24 * 30
        //<!-- 記住我cookie生效時(shí)間30天 ,單位秒;-->
        simpleCookie.setMaxAge(1800);
        return simpleCookie;
    }*/
 
    /**
     * cookie管理對象;
     * rememberMeManager()方法是生成rememberMe管理器,而且要將這個(gè)rememberMe管理器設(shè)置到securityManager中
     * @return
     */
    /*@Bean
    public CookieRememberMeManager rememberMeManager(){
        //System.out.println("ShiroConfiguration.rememberMeManager()");
        CookieRememberMeManager cookieRememberMeManager = new CookieRememberMeManager();
        cookieRememberMeManager.setCookie(rememberMeCookie());
        //rememberMe cookie加密的密鑰 建議每個(gè)項(xiàng)目都不一樣 默認(rèn)AES算法 密鑰長度(128 256 512 位)
        cookieRememberMeManager.setCipherKey(Base64.decode("2AvVhdsgUs0FSA3SDFAdag=="));
        return cookieRememberMeManager;
    }*/
 
 
    /**
     * shiro session的管理
     */
    /*@Bean
    public DefaultWebSessionManager sessionManager() {
        DefaultWebSessionManager sessionManager = new DefaultWebSessionManager();
        sessionManager.setGlobalSessionTimeout(tomcatTimeout*1000);
        //設(shè)置sessionDao對session查詢,在查詢在線用戶service中用到了
        sessionManager.setSessionDAO(sessionDAO());
        //配置session的監(jiān)聽
        Collection<SessionListener> listeners = new ArrayList<SessionListener>();
        listeners.add(new BDSessionListener());
        sessionManager.setSessionListeners(listeners);
        //設(shè)置在cookie中的sessionId名稱
        sessionManager.setSessionIdCookie(simpleCookie());
        return sessionManager;
    }*/
 
    @Bean
    @DependsOn("lifecycleBeanPostProcessor")
    public EhCacheManager ehCacheManager(CacheManager cacheManager) {
        EhCacheManager em = new EhCacheManager();
        //將ehcacheManager轉(zhuǎn)換成shiro包裝后的ehcacheManager對象
        em.setCacheManager(cacheManager);
        em.setCacheManagerConfigFile("classpath:ehcache.xml");
        return em;
    }
}

以上是“Java如何實(shí)現(xiàn)在線購書商城系統(tǒng)”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI