浅尝前后端交互的滋味—>(黑马旅游网)

该项目包含旅游门户网和后台管理系统两部分,涉及分页功能实现、数据替换、内容修改等难点。在门户网中,实现了分页显示和数据替换功能;后台管理则支持数据修改操作。项目中大量使用了request和response进行数据传递,同时通过SQL语句处理数据,需要注意细节和错误调试。前后端交互主要采用request获取参数和response返回数据的方式。

目录

项目介绍

1.旅游门户网

2.后台管理系统

3.MySQL结构

难点分析

旅游门户网

后台管理

总结

附:前后端交互的请求方式


项目介绍

旅游网共分为旅游门户网以及后台管理系统,功能模块如下:

1.旅游门户网

 

 2.后台管理系统

 

3.MySQL结构

 

难点分析

旅游门户网

①分页功能时: 编写分页功能时。需要把数据库的所有内容调出,并且通过peagBean方法处理,在经过html的处理展示。

 

 

②替换数据时: 发送请求。传出数据,进行数据的替换。

 后台管理

①数据修改:修改内容时,点击修改按钮,传出该行的数据,并跳转至修改的页面,并把数据回显在上面

 

 

 

 

总结

        在此项目中,频繁使用request,response请求传数据,实现页面数据的展示,多次编写SQL语句,需认真仔细,该项目内容多稍不留神就会出错,需多使用DEBUG功能进行调试。

附:前后端交互的请求方式

 
一、接受html传来的参数——request
 //方式一.接受参数
        String currentPageStr = request.getParameter("currentPage");
        String pageSizeStr = request.getParameter("pageSize");
        String cidStr = request.getParameter("cid");

------------------------------------------------------------------------------

 //方式二.从session中获取登录用户
        Object user = request.getSession().getAttribute("user");
------------------------------------------------------------------------------
 //方式三.获取用户名和密码数据
        Map<String, String[]> map = request.getParameterMap();
        //2.封装User对象
        User user = new User();
        try {
            BeanUtils.populate(user, map);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }

        //3.调用Service查询
        // UserService service = new UserServiceImpl();
        User u = service.login(user);
------------------------------------------------------------------------------

二、返回html传来的数据——response

        //方式一.响应数据
        ObjectMapper mapper = new ObjectMapper();

        response.setContentType("application/json;charset=utf-8");
        mapper.writeValue(response.getOutputStream(), info);
------------------------------------------------------------------------------
       //方式二.响应数据

          writeValue(user, response);

------------------------------------------------------------------------------
        
      //方式三.响应数据
            response.setContentType("text/html;charset=utf-8");
            response.getWriter().write(msg);

 

 

 

 

 

 

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>cn.itcast.parent</groupId> <artifactId>itcast-parent</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <groupId>cn.itcast</groupId> <artifactId>travel</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>war</packaging> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </dependency> <!-- 连接池 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> </dependency> <!-- Jackson Json处理工具包 --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> </dependency> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.9.0</version> </dependency> <dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> <version>1.4.7</version> </dependency> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> </dependency> </dependencies> <build> <plugins> <!-- 配置Tomcat插件 --> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <configuration> <port>8080</port> <path>/</path> </configuration> </plugin> </plugins> </build> </project>
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值