ssm-购物车实现1

实现页面跳转
http://www.jt.com/cart/show.html

package com.jt.web.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/cart")
public class CartController {
    //http://www.jt.com/cart/show.html
    //跳转购物车
    @RequestMapping("/show")
    public String show(){
        return "cart";
    }
}

创建项目


ssm-购物车实现1_第1张图片

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

   

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }

    #实现图片回显 配置图片服务器 image.jt.com
    server{
        listen 80;
        server_name image.jt.com;
        #个别电脑需要区分斜杠
        location / {
            root D:/jtupload; 
        }
    }
    #配置tomcat负载均衡 1.轮询 2.权重 3.ip_hash方式
    upstream jt{
        #ip_hash;
        server localhost:8091 max_fails=1 fail_timeout=60s;
        server localhost:8092 max_fails=1 fail_timeout=60s;
        server localhost:8093 max_fails=1 fail_timeout=60s;
    }
    #Linux集群部署
    upstream jtLinux{
        server 192.168.161.130:8091;
        server 192.168.161.130:8092;
        server 192.168.161.130:8093;
    }
    #后台系统
    server{
        listen 80;
        server_name manage.jt.com;
        location / {
            #proxy_pass http://jtLinux;
            proxy_pass http://localhost:8091;
            #proxy_connect_timeout       1;  
            #proxy_read_timeout      1;  
            #proxy_send_timeout      1; 
        }
    }
    #前台系统
    server{
        listen 80;
        server_name www.jt.com;
        location / {
            proxy_pass http://localhost:8092;
        }
    }
    #单点登录系统
    server{
        listen 80;
        server_name sso.jt.com;
        location / {
            proxy_pass http://localhost:8093;
        }
    }
    #购物车系统
    server{
        listen 80;
        server_name cart.jt.com;
        location / {
            proxy_pass http://localhost:8094;
        }
    }
}

导入配置文件
1.修改web.xml



    jt-cart

    
        DispatcherServlet
        org.springframework.web.servlet.DispatcherServlet
        
        
        
            contextConfigLocation
            classpath:/spring/applicationContext*.xml
        
        1
    
    
    
    
        DispatcherServlet
        /
    
    
    
        characterEncodingFilter
        org.springframework.web.filter.CharacterEncodingFilter
        
            encoding
            UTF-8
        
    
    
        characterEncodingFilter
        /*
    
    
        index.jsp
    

2.修改applicationContext.xml


    
    
    
    
    
        
            
            
                classpath:/property/jdbc.properties
                classpath:/property/redis.properties
            
        
    
    
    
        
        
        
        
    
    
    
    
    
        
    
    
    
        
            
            
            
            
            
        
    
    
                        
    
        
        
    

3.修改mybatis


    
    
        
        
        
        
    
    
    
        
    

4.修改映射文件的路径


ssm-购物车实现1_第2张图片


  



5.编辑pojo


ssm-购物车实现1_第3张图片
package com.jt.common.po;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Table(name="tb_cart")
public class Cart extends BasePojo{
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Long id;//主键
    private Long userId;//用户id
    private Long itemId;//商品id
    private String itemTitle;//商品标题
    private String itemImage;//商品的第一张图片
    private Long itemPrice;//商品的价格
    private Integer num;//商品的数量
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public Long getUserId() {
        return userId;
    }
    public void setUserId(Long userId) {
        this.userId = userId;
    }
    public Long getItemId() {
        return itemId;
    }
    public void setItemId(Long itemId) {
        this.itemId = itemId;
    }
    public String getItemTitle() {
        return itemTitle;
    }
    public void setItemTitle(String itemTitle) {
        this.itemTitle = itemTitle;
    }
    public String getItemImage() {
        return itemImage;
    }
    public void setItemImage(String itemImage) {
        this.itemImage = itemImage;
    }
    public Long getItemPrice() {
        return itemPrice;
    }
    public void setItemPrice(Long itemPrice) {
        this.itemPrice = itemPrice;
    }
    public Integer getNum() {
        return num;
    }
    public void setNum(Integer num) {
        this.num = num;
    }
    
}

6.打包工具类


ssm-购物车实现1_第4张图片

7.写好层级代码


ssm-购物车实现1_第5张图片

你可能感兴趣的:(ssm-购物车实现1)