第04项目:淘淘商城(SpringMVC+Spring+Mybatis)【第十一天】(购物车+订单)

https://pan.baidu.com/s/1bptYGAb#list/path=%2F&parentPath=%2Fsharelink389619878-229862621083040

第04项目:淘淘商城(SpringMVC+Spring+Mybatis)【第七天】(redis缓存)

第04项目:淘淘商城(SpringMVC+Spring+Mybatis)【第八天】(solr服务器搭建、搜索功能实现)

第04项目:淘淘商城(SpringMVC+Spring+Mybatis)【第九天】(商品详情页面实现)

第04项目:淘淘商城(SpringMVC+Spring+Mybatis)【第十天】(单点登录系统实现)

第04项目:淘淘商城(SpringMVC+Spring+Mybatis)【第十一天】(购物车+订单)

今天的内容:

1、登录、注册功能的实现。

2、门户系统整合登录、注册功能

3、当用户下订单时需要用户登录,使用拦截器实现用户登录。登录成功后跳转到用户要访问的页面。

4、购物车的实现

a)       添加商品

b)       删除商品

c)       修改商品数量

1   注册功能的实现

登录和注册的功能都放到单点登录系统中完成,供其他系统调用。

需要对静态资源做映射。需要修改springmvc.xml

    <!-- 不拦截释放静态资源的映射 -->
    <mvc:resources location="/WEB-INF/js/" mapping="/js/**" />
    <mvc:resources location="/WEB-INF/css/" mapping="/css/**" />
    <mvc:resources location="/WEB-INF/images/" mapping="/images/**" />

1.1   注册功能实现

1、进行注册之前先进行数据的有效性验证。

a)       用户名不能重复

b)       确认密码和密码文本框的内容要一致。

c)       用户名、密码不能为空。

d)       手机不能为空 并且不能重复。

2、校验完成后注册。可以调用sso系统的注册接口完成注册。

3   登录功能的实现

3.1.1   打开登录页面

使用一个Controller跳转到登录页面。

//页面跳转控制
@Controller
@RequestMapping("/page")
public class PageController {

    @RequestMapping("/showRegister")
    public String showRegister () {
        //返回逻辑视图的jsp文件名
        return "register";
    }

    @RequestMapping("/showLogin")
    public String showLogin() {
        return "login";
    }

}

3.1.2   数据校验

校验用户名密码必须输入。

3.1.4   登录页面回调url

回调url应该是通过一个参数传递给显示登录页面的Controller。参数名为:redirect

需要把回调的url传递给jsp页面。当登录成功后,js的逻辑中判断是否有回调的rul,如果有就跳转到此url,如果没有就跳转到商城首页。

//页面跳转控制
@Controller
@RequestMapping("/page")
public class PageController {

    @RequestMapping("/showRegister")
    public String showRegister () {
        //返回逻辑视图的jsp文件名
        return "register";
    }

    @RequestMapping("/showLogin")
    public String showLogin(String redirect,Model model) {

        model.addAttribute("redirect", redirect);
        return "login";
    }

}

4  使用拦截器实现用户登录

4.1    门户系统整合sso

在门户系统点击登录连接跳转到登录页面。登录成功后,跳转到门户系统的首页,在门户系统中需要从cookie中 把token取出来。所以必须在登录成功后把token写入cookie。并且cookie的值必须在系统之间能共享。

4.1.1   Cookie共享:

1、Domain:必须是相同的。

例如有多个域名:

www.taotao.com

Sso.taotao.com

Search.taotao.com

需要设置domain为:.taotao.com

2、设置path:/

4.1.2   工具类

如果是localhost不要设置domain。直接设置path就可以了。

=======================================

参考资料:

end

登录和注册的功能都放到单点登录系统中完成,供其他系统调用。

需要对静态资源做映射。需要修改springmvc.xml

    <!-- 不拦截释放静态资源的映射 -->
    <mvc:resources location="/WEB-INF/js/" mapping="/js/**" />
    <mvc:resources location="/WEB-INF/css/" mapping="/css/**" />
    <mvc:resources location="/WEB-INF/images/" mapping="/images/**" />

1.1   注册功能实现

1、进行注册之前先进行数据的有效性验证。

a)       用户名不能重复

b)       确认密码和密码文本框的内容要一致。

c)       用户名、密码不能为空。

d)       手机不能为空 并且不能重复。

2、校验完成后注册。可以调用sso系统的注册接口完成注册。

3   登录功能的实现

3.1.1   打开登录页面

使用一个Controller跳转到登录页面。

//页面跳转控制
@Controller
@RequestMapping("/page")
public class PageController {

    @RequestMapping("/showRegister")
    public String showRegister () {
        //返回逻辑视图的jsp文件名
        return "register";
    }

    @RequestMapping("/showLogin")
    public String showLogin() {
        return "login";
    }

}

3.1.2   数据校验

校验用户名密码必须输入。

3.1.4   登录页面回调url

回调url应该是通过一个参数传递给显示登录页面的Controller。参数名为:redirect

需要把回调的url传递给jsp页面。当登录成功后,js的逻辑中判断是否有回调的rul,如果有就跳转到此url,如果没有就跳转到商城首页。

//页面跳转控制
@Controller
@RequestMapping("/page")
public class PageController {

    @RequestMapping("/showRegister")
    public String showRegister () {
        //返回逻辑视图的jsp文件名
        return "register";
    }

    @RequestMapping("/showLogin")
    public String showLogin(String redirect,Model model) {

        model.addAttribute("redirect", redirect);
        return "login";
    }

}

4  使用拦截器实现用户登录

4.1    门户系统整合sso

在门户系统点击登录连接跳转到登录页面。登录成功后,跳转到门户系统的首页,在门户系统中需要从cookie中 把token取出来。所以必须在登录成功后把token写入cookie。并且cookie的值必须在系统之间能共享。

4.1.1   Cookie共享:

1、Domain:必须是相同的。

例如有多个域名:

www.taotao.com

Sso.taotao.com

Search.taotao.com

需要设置domain为:.taotao.com

2、设置path:/

4.1.2   工具类

如果是localhost不要设置domain。直接设置path就可以了。

=======================================

参考资料:

end

原文地址:https://www.cnblogs.com/MarlonKang/p/11725855.html

时间: 2024-07-30 14:20:27

第04项目:淘淘商城(SpringMVC+Spring+Mybatis)【第十一天】(购物车+订单)的相关文章

第04项目:淘淘商城(SpringMVC+Spring+Mybatis) 的学习实践总结【第五天】

https://pan.baidu.com/s/1bptYGAb#list/path=%2F&parentPath=%2Fsharelink389619878-229862621083040 第04项目:淘淘商城(SpringMVC+Spring+Mybatis) 的学习实践总结[第四天] 第04项目:淘淘商城(SpringMVC+Spring+Mybatis) 的学习实践总结[第五天] 开发环境: Eclipse IDE for Enterprise Java DevelopersOS: Wi

第04项目:淘淘商城(SpringMVC+Spring+Mybatis)【第七天】(redis缓存)

https://pan.baidu.com/s/1bptYGAb#list/path=%2F&parentPath=%2Fsharelink389619878-229862621083040 第04项目:淘淘商城(SpringMVC+Spring+Mybatis) 的学习实践总结[第五天] 第04项目:淘淘商城(SpringMVC+Spring+Mybatis) 的学习实践总结[第六天] 第04项目:淘淘商城(SpringMVC+Spring+Mybatis)[第七天](redis缓存) 第04

第04项目:淘淘商城(SpringMVC+Spring+Mybatis)【第八天】(solr服务器搭建、搜索功能实现)

https://pan.baidu.com/s/1bptYGAb#list/path=%2F&parentPath=%2Fsharelink389619878-229862621083040 第04项目:淘淘商城(SpringMVC+Spring+Mybatis) 的学习实践总结[第五天] 第04项目:淘淘商城(SpringMVC+Spring+Mybatis) 的学习实践总结[第六天] 第04项目:淘淘商城(SpringMVC+Spring+Mybatis)[第七天](redis缓存) 第04

第04项目:淘淘商城(SpringMVC+Spring+Mybatis)【第十天】(单点登录系统实现)

https://pan.baidu.com/s/1bptYGAb#list/path=%2F&parentPath=%2Fsharelink389619878-229862621083040 第04项目:淘淘商城(SpringMVC+Spring+Mybatis) 的学习实践总结[第六天] 第04项目:淘淘商城(SpringMVC+Spring+Mybatis)[第七天](redis缓存) 第04项目:淘淘商城(SpringMVC+Spring+Mybatis)[第八天](solr服务器搭建.搜

springmvc+spring+mybatis+maven项目构建

1.首先在myeclipse10中安装maven的插件,将插件放入D:\Program Files (x86)\myEclipse10\MyEclipse Blue Edition 10\dropins\maven中, 2. 新建文件:maven.link填入如下内容:path=D:/Program Files (x86)/myEclipse10/MyEclipse Blue Edition 10/dropins/maven 3.重启myeclipse插件安装成功. 4.在myeclipse10

SpringMVC +Spring + MyBatis + Mysql + Redis(作为二级缓存) 配置

转载:http://blog.csdn.net/xiadi934/article/details/50786293 项目环境: 在SpringMVC +Spring + MyBatis + MySQL.Redis部署在Linux虚拟机. 1.整体思路 参考Ehcache实现MyBatis二级缓存代码(Maven引用对应jar查阅) 使用Spring管理Redis连接池 模仿EhcacheCache,实现RedisCache 2.pom.xml中加入Maven依赖 1 <!-- spring-re

SpringMVC+Spring+Mybatis+Mysql项目搭建

眼下俺在搭建一个自己的个人站点玩玩.一边练习.一边把用到的技术总结一下,日后好复习. 站点框架大致例如以下图所看到的: 眼下仅仅用到了SpringMVC+Spring+Mybatis+Mysql.把它弄到了自己的server上来玩耍. 后台结构图: 眼下主要分为: view–controller层与前台交互,登陆拦截器 utils–工具类.一些经常使用的工具类. interceptor–拦截器.页面请求地址拦截和预防XSS漏洞拦截. impl–接口类,Service层-进行业务处理. excep

基于Springmvc+Spring+Mybatis+Jqueryeasyui个人信息管理平台(日程管理、天气类型、资产管理、理财规划)

基于Springmvc+Spring+Mybatis+Jqueryeasyui个人信息管理平台(日程管理.天气类型.资产管理.理财规划) 课程讲师老牛 课程分类Java 适合人群中级 课时数量78课时 更新程度完毕 服务类型C类普通服务类课程 用到技术Springmvcspringmybatisjquery easyui 涉及项目个人信息管理好友管理报表实现 咨询QQ2050339477 课程链接http://www.dwz.cn/LO1X3 课程背景 本系统主要用于个人信息的管理通过软件工具对

Idea SpringMVC+Spring+MyBatis+Maven调整【转】

Idea SpringMVC+Spring+MyBatis+Maven整合 创建项目 File-New Project 选中左侧的Maven,选中右侧上方的Create from archetype,然后选中下方列表中的webapp,然后点击Next 在GroupId和ArtifactId中填入指定内容,点击Next 直接点Next 输入项目名称,Finish Idea会自动开始下载所依赖的包,等待其完成. 项目结构 项目刚建好的时候是没有这些文件的,所以自己手动创建缺少的文件夹(包) 创建完后