spring-boot-tomcat-分页-部署到linux-nginx转发

1.demo结构:


图片.png

2.pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 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>

    <groupId>com.zy</groupId>
    <artifactId>spring-boot01</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>spring-boot01</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.14.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <!--会与本地tomcat冲突
                <scope>provided</scope>
            -->
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!--配置mysql,Mybatis,Druid-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.45</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.0.21</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.1</version>
        </dependency>
        <!--配置分页插件-->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>5.1.2</version>
        </dependency>
        <dependency>
            <groupId>com.github.miemiedev</groupId>
            <artifactId>mybatis-paginator</artifactId>
            <version>1.2.15</version>
        </dependency>
        <!--用于解析Html,不能与jsp的支持包同时存在-->
        <!--<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>-->
        <!--添加jsp相关-->
        <!--用于解析jsp,不能与HTML的支持包同时存在-->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

3.application.yml

spring:
# 配置数据库连接
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/stu
    username: root
    password: 123456
# 配置jsp的解析
  mvc:
    view:
      prefix: /WEB-INF/jsp/
      suffix: .jsp
# 配置HTML的解析
  thymeleaf:
    prefix: classpath:/templates/
logging:
  pattern:
    level: debug
  level:
    com.zy.controller: error
    com.zy.service: info
    com.zy.mapper: debug
  file: D:/springboot.log
# mybatis中,静态资源不发布:此处指的是resources文件夹下的文件
mybatis:
  mapper-locations: classpath:com/zy/mapper/*.xml
  config-location: classpath:sqlMappingConfig.xml
# 使用pageHelper进行分页
pagehelper:
    helperDialect: mysql
    reasonable: true
    support-methods-arguments: true
    params: count=countSql

4.启动类

package com.zy;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@SpringBootApplication
/*配置事务的注解,同时也需要在service层方法上添加注解*/
@EnableTransactionManagement
/*整合mybatis*/
@MapperScan("com.zy.mapper")
/*@可配可不配ComponentScan(basePackages = {"com.zy.service","com.zy.controller"})*/
public class SpringBoot01Application {

    public static void main(String[] args) {
        SpringApplication.run(SpringBoot01Application.class, args);
    }
}

5.config包下类

package com.zy.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class StaticResourceConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /*配置js,css等*/
        registry.addResourceHandler("/js/**").addResourceLocations("WEB-INF/js/");
        registry.addResourceHandler("/css/**").addResourceLocations("WEB-INF/css/");
        registry.addResourceHandler("/fonts/**").addResourceLocations("WEB-INF/fonts/");
        super.addResourceHandlers(registry);
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        /*配置默认访问页:需要在浏览器中输入ip+端口号*/
        registry.addViewController("/").setViewName("forward:/index.jsp");
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
        super.addViewControllers(registry);
    }
}

6.util包下分页工具类

package com.zy.util;

import java.util.List;

public class StudentPageUtils {

    private long totalPages;
    private Integer pageSize;
    private Integer currentPage;
    private List rows;

    @Override
    public String toString() {
        return "StudentPageUtils{" +
                "totalPages=" + totalPages +
                ", pageSize=" + pageSize +
                ", currentPage=" + currentPage +
                ", rows=" + rows +
                '}';
    }

    public long getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(long totalPages) {
        this.totalPages = totalPages;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }

    public List getRows() {
        return rows;
    }

    public void setRows(List rows) {
        this.rows = rows;
    }

    public StudentPageUtils() {

    }

    public StudentPageUtils(long totalPages, Integer pageSize, Integer currentPage, List rows) {

        this.totalPages = totalPages;
        this.pageSize = pageSize;
        this.currentPage = currentPage;
        this.rows = rows;
    }
}

7.controller层

package com.zy.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zy.model.Student;
import com.zy.service.StudentServiceI;
import com.zy.util.StudentPageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("stu/")
public class StudentController {

    @Autowired
    private StudentServiceI studentServiceI;

    // 查询学生信息,包括多条件查询
    @RequestMapping("getStudentByCondition")
    public String getStudentByCondition(Map map, Student student, @RequestParam(defaultValue = "1") Integer pageNo) {
        PageHelper.startPage(pageNo, 2);
        List<Student> list = studentServiceI.getStudentByCondition(student);
        StudentPageUtils pageInfo = new StudentPageUtils();
        pageInfo.setRows(list);
        PageInfo<Student> pageInfoList = new PageInfo<Student>(list);
        pageInfo.setTotalPages(pageInfoList.getPages());
        pageInfo.setCurrentPage(pageNo);
        pageInfo.setPageSize(pageInfoList.getPageSize());
        map.put("pageInfo", pageInfo);
        map.put("stu",student);
        return "stu/stuList";
    }

    // 删除学生信息
    @RequestMapping("deleteStu")
    public String deleteStu(Integer id) {
        studentServiceI.deleteStu(id);
        return "redirect:/index.jsp";
    }

    // 增加学生信息
    @RequestMapping("addStu")
    public String addStu(Student student) {
        studentServiceI.addStu(student);
        return "redirect:/index.jsp";
    }

    // 更新学生信息
    @RequestMapping("updateStu")
    public String updateStu(Student student){
        studentServiceI.updateStu(student);
        return "redirect:/index.jsp";
    }

    // 根据id查询学生信息
    @RequestMapping("getStudentById")
    public String getStudentById(Integer id,Map map){
        Student student = new Student();
        student.setId(id);
        List<Student> list = studentServiceI.getStudentByCondition(student);
        StudentPageUtils pageInfo = new StudentPageUtils();
        pageInfo.setRows(list);
        map.put("pageInfo", pageInfo);
        return "stu/updateStu";
    }
}

8.service层实现类

package com.zy.service.impl;

import com.zy.mapper.StudentMapper;
import com.zy.model.Student;
import com.zy.service.StudentServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service(value="StudentServiceI")
/*配置事务注解*/
public class StudentServiceImpl implements StudentServiceI {

    // 查询学生信息,多条件查询
    @Autowired
    private StudentMapper studentMapper;
    @Override
    public List<Student> getStudentByCondition(Student student) {
        return studentMapper.getStudentByCondition(student);
    }

    // 删除学生
    @Override
    public void deleteStu(Integer id) {
        studentMapper.deleteStu(id);
    }

    // 增加学生信息
    @Override
    public int addStu(Student student) {
        int id = studentMapper.addStu(student);
        return id;
    }

    // 修改学生信息
    @Override
    public void updateStu(Student student) {
        studentMapper.updateStu(student);
    }
}

9.mapper层接口

package com.zy.mapper;

import com.zy.model.Student;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
public interface StudentMapper {

    // 查询学生信息,多条件查询
    List<Student> getStudentByCondition(Student student);

    // 删除学生
    void deleteStu(Integer id);

    // 增加学生信息
    int addStu(Student student);

    // 修改学生信息
    void updateStu(Student student);
}

10.model层实体类

package com.zy.model;

import java.io.Serializable;

public class Student implements Serializable {

    private Integer id;
    private String name;
    private Integer age;
    private String gender;
    private String addr;

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", gender='" + gender + '\'' +
                ", addr='" + addr + '\'' +
                '}';
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getAddr() {
        return addr;
    }

    public void setAddr(String addr) {
        this.addr = addr;
    }

    public Student() {

    }

    public Student(Integer id, String name, Integer age, String gender, String addr) {

        this.id = id;
        this.name = name;
        this.age = age;
        this.gender = gender;
        this.addr = addr;
    }
}

11.resources下的mybatis全局配置文件sqlMappingConfig.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <!--设置全局配置环境-->
    <settings>
        <!--开启全局缓存-->
        <setting name="cacheEnabled" value="true"/>
        <!--开启懒加载-->
        <setting name="lazyLoadingEnabled" value="true"/>
        <!--关闭延迟加载-->
        <setting name="aggressiveLazyLoading" value="false"/>
    </settings>
    <!--配置分页插件pageHelper的拦截器:5.0版本之后的配置-->
    <plugins>
        <plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin>
    </plugins>
</configuration>

12.mybatis其他文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zy.mapper.StudentMapper">

    <!--封装结果集-->
    <resultMap id="studentResultMap" type="com.zy.model.Student">
        <id column="id" property="id" jdbcType="INTEGER"/>
        <result column="name" property="name" jdbcType="VARCHAR"/>
        <result column="age" property="age" jdbcType="INTEGER"/>
        <result column="gender" property="gender" jdbcType="VARCHAR"/>
        <result column="addr" property="addr" jdbcType="VARCHAR"/>
    </resultMap>

    <!--
        // 查询学生信息,多条件查询
        List<Student> getStudentByCondition(Student student);
    -->
    <select id="getStudentByCondition" resultMap="studentResultMap">
        select id,name,age,gender,addr
        from stu
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="name != null and name.trim() != &quot;&quot;">
                and name like concat(concat('%',#{name}),'%')
            </if>
            <if test="age != null">
                and age = #{age}
            </if>
            <if test="gender != null and gender.trim() != &quot;&quot;">
                and gender = #{gender}
            </if>
            <if test="addr != null and addr.trim() != &quot;&quot;">
                and addr like concat(concat('%',#{addr}),'%')
            </if>
        </where>
    </select>

    <!--
        // 删除学生
        void deleteStu(Integer id);
    -->
    <delete id="deleteStu">
        delete from stu
        where id = #{id}
    </delete>

    <!--
        // 增加学生信息
        int addStu(Student student);
    -->
    <insert id="addStu">
        <selectKey keyProperty="id" order="AFTER" resultType="int">
            select last_insert_id()
        </selectKey>
        insert into stu values(null,#{name},#{age},#{gender},#{addr})
    </insert>

    <!--
        // 修改学生信息
        void updateStu(Student student);
    -->
    <update id="updateStu">
        update stu
        set name=#{name},age=#{age},gender=#{gender},addr=#{addr}
        where id=#{id}
    </update>

</mapper>

13.webapp下的index.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<jsp:forward page="/stu/getStudentByCondition"/>

14.WEB-INF下jsp文件


图片.png

14.1stuList.jsp

<%--
  Created by IntelliJ IDEA.
  User: asus
  Date: 2018/6/26
  Time: 18:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <meta name="viewport" content="width=device-width,initial-scale=1"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/bootstrap.min.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/bootstrap-theme.min.css"/>
    <script src="/js/jquery-3.2.1.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="${pageContext.request.contextPath }/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="${pageContext.request.contextPath }/js/jqPaginator.js" type="text/javascript" charset="utf-8"></script>
    <title>学生信息</title>
    <style>
        .modal-dialog{
            text-align: center;
        }
        .add-stu{
            position: absolute;
            right: 300px;
            top: 0;
        }
         .pagination-layout {
             text-align: center;
         }
    </style>
</head>
<body>
<!--展示数据开始-->
<div class="container-fluid main-content">
    <div class="widget-container fluid-height clearfix">
        <div class="widget-content padded clearfix">
            <div class="dataTables_filter">
                <form class="form-inline search-form" action="${pageContext.request.contextPath }/stu/getStudentByCondition" method="post" id="findByCondition">
                    <div class="btn-group">
                        <%--<select id="field" class="form-control" name="field">
                            <option value="00">--请选择筛选条件--</option>
                            <option value="customer_name">学号</option>
                            <option value="customer_industry">姓名</option>
                        </select>
                        <!-- 显示要输入的搜索条件 -->
                        <div class="form-group" id="conditionContent">

                        </div>--%>
                    </div>
                    <div class="input-group" id="conditionContent">
                        <span class="input-group-addon">id:</span><input type="text" class="form-control" size="4" name="id" value="${stu.id}"/>
                        <span class="input-group-addon">name:</span><input type="text" class="form-control" size="4" name="name" value="${stu.name}"/>
                        <span class="input-group-addon">age:</span><input type="text" class="form-control" size="4" name="age" value="${stu.age}"/>
                        <span class="input-group-addon">gender:</span><input type="text" class="form-control" size="4" name="gender" value="${stu.gender}"/>
                        <span class="input-group-addon">addr:</span><input type="text" class="form-control" size="4" name="addr" value="${stu.addr}"/>
                    </div><div class="btn-group">
                        <button type="submit" class="btn btn-success" id="search">搜索</button>
                    </div>
                </form>
            </div>

            <div id="w0" class="grid-view">
                <div class="table-responsive">
                    <!--表格数据-->
                    <table class="table table-hover">
                        <thead>
                        <tr>
                            <th><label class="label-checkbox"> <input type="checkbox" class="select-on-check-all" name="selection_all" value="1"><span class="custom-checkbox"></span> </label>
                            </th>
                            <th nowrap="">学号</th>
                            <th nowrap="">姓名</th>
                            <th nowrap="">年龄</th>
                            <th nowrap="">性别</th>
                            <th nowrap="">地址</th>
                            <th class="action-column" colspan="2">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <!--首页模版代码-->
                        <c:forEach items="${pageInfo.rows}" var="stu">
                            <tr>
                                <td><label class='label-checkbox'> <input type='checkbox' name='selection_one' value='13'><span class='custom-checkbox'></span></label></td>
                                <td>${stu.id}</td>
                                <td>${stu.name}</td>
                                <td>${stu.age}</td>
                                <td>${stu.gender}</td>
                                <td>${stu.addr}</td>
                                <td><a onclick="updateStu(${stu.id})">更新</a></td>
                                <td><a onclick="delStu(${stu.id})">删除</a></td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                    <!--分页代码区域-->
                    <!-- 分页代码区域 -->
                    <div class="pagination-layout">
                        <div class="pagination">
                            <ul class="pagination">

                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--展示数据开始-->

<!--新增学生模态框开始-->
<div class="container">
    <div class="modal" id="mymodal">
        <div class="modal-dialog">
            <div class="modal-content">
                <!--modal头-->
                <div class="modal-header">学生信息增加</div>
                <!--modal体-->
                <div class="modal-body">
                    <form id="frm" action="${pageContext.request.contextPath }/stu/addStu" method="post" role="form" class="form-horizontal">
                        <!--姓名-->
                        <div class="form-group has-feedback">
                            <label for="username" class="col-sm-4 control-label">姓名</label>
                            <div class="col-sm-4">
                                <input type="text" id="username" name="name" class="form-control" placeholder="请输入姓名" />
                                <span class="glyphicon glyphicon-user form-control-feedback"></span>
                            </div>
                        </div>
                        <!--年龄-->
                        <div class="form-group">
                            <label for="age" class="col-sm-4 control-label">年龄</label>
                            <div class="col-sm-4">
                                <input type="text" id="age" name="age" class="form-control" placeholder="请输入年龄" />
                            </div>
                        </div>
                        <!--性别-->
                        <div class="form-group">
                            <label for="gender" class="col-sm-4 control-label">性别</label>
                            <div class="col-sm-4">
                                <input type="text" id="gender" name="gender" class="form-control" placeholder="请输入性别" />
                            </div>
                        </div>
                        <!--地址-->
                        <div class="form-group">
                            <label class="col-sm-4 control-label" for="addr">地址</label>
                            <div class="col-sm-4">
                                <input type="text" id="addr" name="addr" class="form-control" placeholder="请输入地址" />
                            </div>
                        </div>
                    </form>
                </div>
                <!--modal脚-->
                <div class="modal-footer">
                    <!--增加-->
                    <div class="form-group">
                        <div class="col-sm-2 col-sm-offset-3">
                            <button class="btn btn-success" type="button" id="add-submit">增加</button>
                        </div>
                        <div class="col-sm-2 col-sm-offset-2">
                            <button class="btn btn-success" type="reset">重置</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <button class="add-stu btn btn-danger" data-toggle="modal" data-target="#mymodal">增加学生</button>
</div>
<!--新增学生信息模态框结束-->

</body>
<script type="text/javascript">
    /*增加学生信息*/
    $(function(){
        $(".add-stu").on("click",function(){
            $("#mymodal").show();
        });
        $("#add-submit").on("click",function(){
            // 获取姓名并验证
            var name = $("#username").val();
            if(isEmpty(name)){
                alert("姓名不能为空");
                return false;
            }
            // 获取年龄并验证
            var age = $("#age").val();
            if(isEmpty(age)){
                alert("年龄不能为空");
                return false;
            }
            // 获取性别并验证
            var gender = $("#gender").val();
            if(isEmpty(gender)){
                alert("性别不能为空");
                return false;
            }
            // 获取地址并验证
            var addr = $("#addr").val();
            if(isEmpty(addr)){
                alert("地址不能为空");
                return false;
            }
            // 否则,提价表单
            $("#frm").submit();

        });
    })
    // 封装判空的函数
    function isEmpty(name){
        if(name == null || name == undefined){
            return true;
        }
        else{
            if(name.trim() == ""){
                return true;
            }
            else{
                return false;
            }
        }
    }
</script>

<script>
    /*更新学生信息*/
    function updateStu(id) {
        window.location.href="${pageContext.request.contextPath}/stu/getStudentById?id=" + id;
    }
</script>

<script>
    /*删除学生信息*/
    function delStu(id) {
        var boolean = confirm("请问要删除这个学生么?");
        if(boolean){
            window.location.href="${pageContext.request.contextPath}/stu/deleteStu?id=" + id;
        }
    }
</script>

<script type="text/javascript">
    // 4.分页查询数据(含总数据及条件查询)
    var if_first = true;
    $(".pagination").jqPaginator({
        wrapper: '',
        first: '<li class="first"><a href="javascript:;">首页</a></li>',
        prev: '<li class="prev"><a href="javascript:;">上一页</a></li>',
        next: '<li class="next"><a href="javascript:;">下一页</a></li>',
        last: '<li class="last"><a href="javascript:;">尾页</a></li>',
        page: '<li class="page"><a href="javascript:;">{{page}}</a></li>',
        totalPages: ${pageInfo.totalPages },
        totalCounts: 0,
        pageSize: ${pageInfo.pageSize },
        currentPage: ${pageInfo.currentPage },
        visiblePages: 7,
        disableClass: 'disabled',
        activeClass: 'active',
        onPageChange: function(num){
            if(if_first){
                if_first = false;
            }
            else if(!if_first){
                changePage(num);
            }
        }
        /*  */
    });
    function changePage(num){
/*
        var positionname=$("#positionname").val();
*/
        /* 这里需要对数据进行编码,同时servelt层要对数据进行解码,但是要做参数非空判断! */
        window.location.href="${pageContext.request.contextPath }/stu/getStudentByCondition?"+$("#findByCondition").serialize()+"&pageNo="+num;
    }
</script>
</html>

14.2updateStu.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: asus
  Date: 2018/6/26
  Time: 20:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>Title</title>
    <meta name="viewport" content="width=device-width,initial-scale=1"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/bootstrap.min.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/bootstrap-theme.min.css"/>
    <script src="${pageContext.request.contextPath }/js/jquery-3.2.1.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="${pageContext.request.contextPath }/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div class="container-fluid main-content">
    <div class="widget-container fluid-height clearfix mwi1200">
        <div class="heading clearfix">
            <i class="icon-reorder"></i> 修改客户
        </div>
        <div class="widget-content padded clearfix">
            <!--注册form表单-->
            <form action="${pageContext.request.contextPath }/stu/updateStu" method="post" role="form" class="form-horizontal" id="frm">
                <c:forEach items="${pageInfo.rows}" var="stu">
                    <input type="hidden" name="id" value="${stu.id}"/>
                    <!--名称-->
                    <div class="form-group">
                        <label class="col-sm-2 control-label">姓名</label>
                        <div class="col-sm-6">
                            <input type="text" id="username" name="name" value="${stu.name}" class="form-control"  />
                        </div>
                    </div>
                    <!--年龄-->
                    <div class="form-group">
                        <label class="col-sm-2 control-label">年龄</label>
                        <div class="col-sm-6">
                            <input type="text" id="age" name="age" value="${stu.age}" class="form-control"  />
                        </div>
                    </div>
                    <!--性别-->
                    <div class="form-group">
                        <label class="col-sm-2 control-label">性别</label>
                        <div class="col-sm-6">
                            <input type="text" id="gender" name="gender" value="${stu.gender}" class="form-control"  />
                        </div>
                    </div>
                    <!--地址-->
                    <div class="form-group">
                        <label class="col-sm-2 control-label">地址</label>
                        <div class="col-sm-6">
                            <input type="text" id="addr" name="addr" value="${stu.addr}" class="form-control"  />
                        </div>
                    </div>
                </c:forEach>
                <!--新增&返回-->
                <div class="form-group">
                    <span class="col-sm-2"></span>
                    <button class="btn btn-primary" type="button" id="modify" >修改</button>
                    <span class="col-sm-2"></span>
                    <button class="btn btn-default" type="button" id="backToIndex" >返回</button>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    /*增加学生信息*/
    $(function(){
        $("#modify").on("click",function(){
            // 获取姓名并验证
            var name = $("#username").val();
            if(isEmpty(name)){
                alert("姓名不能为空");
                return false;
            }
            // 获取年龄并验证
            var age = $("#age").val();
            if(isEmpty(age)){
                alert("年龄不能为空");
                return false;
            }
            // 获取性别并验证
            var gender = $("#gender").val();
            if(isEmpty(gender)){
                alert("性别不能为空");
                return false;
            }
            // 获取地址并验证
            var addr = $("#addr").val();
            if(isEmpty(addr)){
                alert("地址不能为空");
                return false;
            }
            // 否则,提价表单
            $("#frm").submit();

        });
    })
    // 封装判空的函数
    function isEmpty(name){
        if(name == null || name == undefined){
            return true;
        }
        else{
            if(name.trim() == ""){
                return true;
            }
            else{
                return false;
            }
        }
    }
</script>
</html>

1.15发布到linux服务器
1.15.1使用外部tomcat发布

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

执行打包指令(注意,这里有web页面,所以是war包)

maven clean install -DskipTests=true
图片.png

然后,将该war包上传到tomcat的webapps目录下-->到tomcat的bin目录下: ./startup.sh启动即可
访问方式:ip:port/项目名/路径名
如:此处为:l92.168.0.199:8080/spring-boot01-0.0.1-SNAPSHOT/index.jsp
1.16采用nginx代理,转发请求

    #将/hello请求转发给http://l92.168.0.199:8080/spring-boot01-0.0.1-SNAPSHOT处理(假设server的port是8081)
    location /hello{
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://l92.168.0.199:8080/spring-boot01-0.0.1-SNAPSHOT;
    }

如果用户在浏览器输入:

http://192.168.0.199:8081/hello/toJSP

那么实际的访问地址是:

http://l92.168.0.199:8081/spring-boot01-0.0.1-SNAPSHOT/toJSP
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 219,635评论 6 508
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,628评论 3 396
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 165,971评论 0 356
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,986评论 1 295
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 68,006评论 6 394
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,784评论 1 307
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,475评论 3 420
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,364评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,860评论 1 317
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,008评论 3 338
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,152评论 1 351
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,829评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,490评论 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,035评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,156评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,428评论 3 373
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,127评论 2 356

推荐阅读更多精彩内容