Springmvc

1. What is springMVC?

Spring Web MVC is a Java-based, request-driven, lightweight Web framework that implements the MVC design pattern.

2. Add related dependencies

< div class="code">

 

org.springframework
spring-webmvc
${spring.version}

JSTL dependency



jstl
jstl
1.2


taglibs
standard
1.1.2

tomcat-jsp-api

 8.0.4

org.apache.tomcat
tomcat-jsp-api
${tomcat-jsp-api.version}
6

Complete pom

p>

"1.0" encoding=" UTF-8"?>


"
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">
4.0.0

com.cjh
ssm
1.0-SNAPSHOT
war

ssm Maven Webapp

http://www.example.com span>


UTF-8
1.8
1.8
3.7.0 maven.compiler.plugin.version>



5.0.2.RELEASE

3.4.5

5.1.44

5.1.2

1.3.1

2.1.1
2.4.3

2.9.1

4.12
4.0.0
1.18.2

2.9.1
3.2.0
1.7.13

2.9.0
1.7.1.RELEASE.RELEASE redis.spring.version>

2.9.3

8.0.46 tomcat-jsp-api.version>







org.springframework
spring-webmvc
${spring.version}



org.springframework
spring-orm
${spring.version}


org.springframework
spring-tx
${spring.version}


org.springframework
spring-aspects
${spring.version}


org.springframework
spring-web
${spring.version}


org.springframework
spring-test
${spring.version}



org.mybatis
mybatis
${mybatis.version}



org.mybatis
mybatis
${mybatis.version}



mysql
mysql-connector-java
${mysql.version}



com.github.pagehelper
pagehelper
${pagehelper.version}



org.mybatis
mybatis-spring
${mybatis.spring.version}



org.apache.commons
commons-dbcp2
${commons.dbcp2.version}


org.apache.commons
commons-pool2
${commons.pool2.version}




org.apache.logging.log4j
log4j-core
${log4j2.version}


org.apache.logging.log4j
log4j-api
${log4j2.version}



org.apache.logging.log4j
log4j-web
${log4j2.version}



junit
junit
${junit.version}
test


javax.servlet
javax.servlet-api
${servlet.version}
provided


org.projectlombok
lombok
${lombok.version}
provided



org.springframework
spring-context-support
${spring.version}




org.mybatis.caches
mybatis-ehcache
1.1.0




net.sf.ehcache
ehcache
2.10.0





org.slf4j
slf4j-api
${slf4j.version}


org.slf4j
jcl-over-slf4j
${slf4j.version}
runtime




org.apache.logging.log4j
log4j-api
${log4j2.version}


org.apache.logging.log4j
log4j-core
${log4j2.version}



org.apache.logging.log4j
log4j-slf4j-impl
${log4j2.version}



org.apache.logging.log4j
log4j-web
${log4j2.version}
runtime




com.lmax
disruptor
${log4j2.disruptor.version}



redis.clients
jedis
${redis.version}


org.springframework.data
spring-data-redis
${redis.spring.version}



com.fasterxml.jackson.core
jackson-databind
${jackson.version}


com.fasterxml.jackson.core
jackson-core
${jackson.version}


com.fasterxml.jackson.core
jackson-annotations
${jackson.version}


jstl
jstl
1.2


taglibs
standard
1.1.2


org.apache.tomcat
tomcat-jsp-api
${tomcat-jsp-api.version}





ssm



src/main/java

**/*.xml




src/main/resources

*.properties
*.xml







org.apache.maven.plugins
maven-compiler-plugin
${maven.compiler.plugin.version}

${maven.compiler.source}
${maven.compiler.target}
${project.build.sourceEncoding}



org.mybatis.generator
mybatis-generator-maven-plugin
1.3.2



mysql
mysql-connector-java
${mysql.version}



true




maven-clean-plugin
3.1.0



maven-resources-plugin
3.0.2


maven-compiler-plugin
3.8.0


maven-surefire-plugin
2.22.1


maven-war-plugin
3.2.2


maven-install-plugin
2.5.2


maven-deploy-plugin
2.8.2




Modify web.xml

"http://xmlns.jcp.org/xml/ns/javaee"

xmlns:xsi
="http://www.w3.org /2001/XMLSchema-instance"
xsi:schemaLocation
="http://xmlns.jcp.org /xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version
="3.1">
Archetype Created Web Application

contextConfigLocation
classpath:applicationContext.xml



class>org.springframework.web.context.ContextLoaderListener class>




SpringMVC
class>org.springframework.web.servlet.DispatcherServlet class>


contextConfigLocation
/WEB-INF/spring-mvc.xml

1

<async-supported>trueasync-supported>


SpringMVC
/

Add springmvc-servlet.xml(spring-mvc.xml) under WEB-INF

"1.0" encoding="UTF-8< /span>"?>

"
http://www.springframework.org/schema/beans "
xmlns:xsi
="http://www.w3.org /2001/XMLSchema-instance"
xmlns:context
="http://www.springframework.org /schema/context"
xmlns:mvc
="http://www.springframework.org /schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation
="http://www.springframework.org /schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context < span style="color: #008000; text-decoration: underline;">http://www.springframework.org/schema/context/spring-context-4.3.xsd http://www.springframework.org/schema/mvc http://www .springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/aop< /span> http://www.springframework.org/schema/aop/spring-aop.xsd">



base
-package="com.javaxl.ssm"/>



<[email protected] support, @DateTimeFormat support, @Valid support, support for reading and writing XML (JAXB), support for reading and writing JSON (Jackson) -->



class="org.springframework.web.servlet.view.InternalResourceViewResolver">

"viewClass"
value
="org.springframework.web.servlet.view.JstlView ">

"prefix" value="/"/>
"suffix" value=".jsp"/>




"/images/" mapping="/images/**< /span>"/>



Springmvc implementation of helloword

. The first springMVC program: HelloWorld

package com.cjh.controller;


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

import javax.servlet.http.HttpServletRequest;

/**
* There are five situations for the result set processing
* 1. Forward to the page (under webapp)
* 2. Forward to action request
* 3. Redirect to the page
* 4. Redirect to action
* 5. Forward to the page under web_info
*
* @author
* @site
* @company
* @create 2019-09-28 10:58
*/
@Controller
public class HelloController {

@RequestMapping(
"hello")
public String hello(HttpServletRequest request){
request.setAttribute(
"msg","forward to page ");
return "hello";
}

/**
* Redirect to action
* @param request
* @return
*/
@RequestMapping(
"hello2")
public String redirectPage(HttpServletRequest request){
request.setAttribute(
"msg","Redirect to action");
return "redirect: hello";
}

/**
* Redirect to the page
* @param request
* @return
*/
@RequestMapping(
"hello3")
public String redirectPage2(HttpServletRequest request){
// request.setAttribute("msg","Redirect to Page");
Object msg = request.getAttribute("msg");

return "redirect:/hello.jsp";
}

/**
* 转发到action请求
* @param request
* @return
*/
@RequestMapping(
"hello4")
public String forwardAction(HttpServletRequest request){
request.setAttribute(
"msg","重定向到action");
return "forward:hello3";
}

/**
*
* @param request
* @return
*/
@RequestMapping(
"hello5")
public String forwardActionw(HttpServletRequest request){
request.setAttribute(
"msg","转发到webinf页面");
return "abcd";
}

}

新建一个hello.jsp

<%--

Created by IntelliJ IDEA.
User: dell
Date:
2019/9/28
Time:
11:00
To change
this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


Title


hello springmvc


${msg}

Springmvc常用注解及返回值处理

booklsit

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding
="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="/zking" prefix="z" %>
"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


"Content-Type" content="text/html; charset=UTF-8">
Insert title here



"${pageContext.request.contextPath}/book/list"
method
="post">
书名:
"text" name="bname"> "submit"
value
="确定">


"1" width="100%">






"${bookList }" var="b">







编号 名称 价格 操作
${b.bid } ${b.bname } ${b.price }
  &nbsp;


"${pageBean }">

bookEdit

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding
="UTF-8"%>
"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


"Content-Type" content="text/html; charset=UTF-8">
Insert title here



"bookForm" action="" method="post">
bid:
"text" name="bid" value="${b.bid }">

bname:
"text" name="bname" value="${b.bname }">

price:
"text" name="price" value="${b.price }">

"submit" value="提交" onclick="doSubmit(‘${b.bid }‘);">



pagTag

package com.cjh.util;



import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;
import java.io.IOException;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;


public class PageTag extends BodyTagSupport {

private static final long serialVersionUID = 1L;
private PageBean pageBean;
public PageBean getPageBean() {
return pageBean;
}
public void setPageBean(PageBean pageBean) {
this.pageBean = pageBean;
}
@Override
public int doStartTag() throws JspException {
JspWriter
out = pageContext.getOut();
try {
out.print(toHTML());
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return super.doStartTag();
}
private String toHTML() {
StringBuffer sb
= new StringBuffer();
/*
* 拼接向后台提交数据的form表单
* 注意:拼接的form表单中的page参数是变化的,所以不需要保留上一次请求的值
*/
sb.append(
"
"+pageBean.getUrl()+"‘ method=‘post‘>");
sb.append(
"");
Map
parameterMap = pageBean.getMap();
if(parameterMap != null && parameterMap.size() > 0) {
Set
> entrySet = parameterMap.entrySet();
for (Entry entry : entrySet) {
if(!"page".equals(entry.getKey())) {
String[] values
= entry.getValue();
for (String val : values) {
sb.append(
""+entry.getKey()+"‘ value=‘"+val+"‘>");
}
}
}
}
sb.append(
"");

/*
* 展示的分页条
*/
sb.append(
"
");
sb.append(
"每页"+pageBean.getRows()+"条,共"+pageBean.getTotal()+"条,第"+pageBean.getPage()+"页,共"+pageBean.getMaxPage()+"页  首页  ");
sb.append(
" href=‘javascript:gotoPage("+pageBean.getPreivousPage()+")‘>上一页  ");
sb.append(
" href=‘javascript:gotoPage("+pageBean.getNextPage()+")‘>下一页  ");
sb.append(
" href=‘javascript:gotoPage("+pageBean.getMaxPage()+")‘>尾页  ");
sb.append(
" id=‘skipPage‘");
sb.append(
" style=‘text-align: center; font-size: 12px; width: 50px;‘>  ");
sb.append(
" href=‘javascript:skipPage()‘>Go");
sb.append(
"
");

/*
* 给分页条添加与后台交互的js代码
*/
sb.append(
"");
return sb.toString();
}
}

 

bookcontroller

package com.cjh.controller;


import com.cjh.model.Book;
import com.cjh.service.BookService;
import com.cjh.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
* @author
* @site
* @company
* @create 2019-09-28 13:38
*/
@Controller
@RequestMapping(
"/book")
public class BookController {
@Autowired
private BookService bookService;

@RequestMapping(
"/list")
public String list(Book book, HttpServletRequest request){
PageBean pageBean
= new PageBean();
pageBean.setRequest(request);
List
maps = this.bookService.listPager(book, pageBean);
request.setAttribute(
"bookList",maps);
request.setAttribute(
"pageBean",pageBean);
return "bookList";

}
@RequestMapping(
"/preSave")
public String preSave(Book book, HttpServletRequest request){
if (book.getBid() != null){
Book b
= this.bookService.selectByPrimaryKey(book.getBid());
request.setAttribute(
"b",b);

}
return "bookEdit";

}
@RequestMapping(
"/add")
public String add(Book book, HttpServletRequest request){
this.bookService.insert(book);
return "redirect:/book/list";

}
@RequestMapping(
"/del/{bid}")
public String del(@PathVariable(value = "bid") Integer bid, HttpServletRequest request){
this.bookService.deleteByPrimaryKey(bid);
return "redirect:/book/list";

}
@RequestMapping(
"/edit")
public String edit(Book book, HttpServletRequest request){
this.bookService.updateByPrimaryKeySelective(book);
return "redirect:/book/list";

}
}

分享图片

Springmvc静态资源处理

访问下面的图片:

分享图片

修改springmvc-servlet.xml




"/static/" mapping="/static/**"/>

分享图片

 

org.springframework
spring-webmvc
${spring.version}



jstl
jstl
1.2


taglibs
standard
1.1.2

  8.0.4

org.apache.tomcat
tomcat-jsp-api
${tomcat-jsp-api.version}
6

"1.0" encoding="UTF-8"?>


"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">
4.0.0

com.cjh
ssm
1.0-SNAPSHOT
war

ssm Maven Webapp

http://www.example.com


UTF-8
1.8
1.8
3.7.0



5.0.2.RELEASE

3.4.5

5.1.44

5.1.2

1.3.1

2.1.1
2.4.3

2.9.1

4.12
4.0.0
1.18.2

2.9.1
3.2.0
1.7.13

2.9.0
1.7.1.RELEASE

2.9.3

8.0.46







org.springframework
spring-webmvc
${spring.version}



org.springframework
spring-orm
${spring.version}


org.springframework
spring-tx
${spring.version}


org.springframework
spring-aspects
${spring.version}


org.springframework
spring-web
${spring.version}


org.springframework
spring-test
${spring.version}



org.mybatis
mybatis
${mybatis.version}



org.mybatis
mybatis
${mybatis.version}



mysql
mysql-connector-java
${mysql.version}



com.github.pagehelper
pagehelper
${pagehelper.version}



org.mybatis
mybatis-spring
${mybatis.spring.version}



org.apache.commons
commons-dbcp2
${commons.dbcp2.version}


org.apache.commons
commons-pool2
${commons.pool2.version}




org.apache.logging.log4j
log4j-core
${log4j2.version}


org.apache.logging.log4j
log4j-api
${log4j2.version}



org.apache.logging.log4j
log4j-web
${log4j2.version}



junit
junit
${junit.version}
test


javax.servlet
javax.servlet-api
${servlet.version}
provided


org.projectlombok
lombok
${lombok.version}
provided



org.springframework
spring-context-support
${spring.version}




org.mybatis.caches
mybatis-ehcache
1.1.0




net.sf.ehcache
ehcache
2.10.0





org.slf4j
slf4j-api
${slf4j.version}


org.slf4j
jcl-over-slf4j
${slf4j.version}
runtime




org.apache.logging.log4j
log4j-api
${log4j2.version}


org.apache.logging.log4j
log4j-core
${log4j2.version}



org.apache.logging.log4j
log4j-slf4j-impl
${log4j2.version}



org.apache.logging.log4j
log4j-web
${log4j2.version}
runtime




com.lmax
disruptor
${log4j2.disruptor.version}



redis.clients
jedis
${redis.version}


org.springframework.data
spring-data-redis
${redis.spring.version}



com.fasterxml.jackson.core
jackson-databind
${jackson.version}


com.fasterxml.jackson.core
jackson-core
${jackson.version}


com.fasterxml.jackson.core
jackson-annotations
${jackson.version}


jstl
jstl
1.2


taglibs
standard
1.1.2


org.apache.tomcat
tomcat-jsp-api
${tomcat-jsp-api.version}





ssm



src/main/java

**/*.xml




src/main/resources

*.properties
*.xml







org.apache.maven.plugins
maven-compiler-plugin
${maven.compiler.plugin.version}

${maven.compiler.source}
${maven.compiler.target}
${project.build.sourceEncoding}



org.mybatis.generator
mybatis-generator-maven-plugin
1.3.2



mysql
mysql-connector-java
${mysql.version}



true




maven-clean-plugin
3.1.0



maven-resources-plugin
3.0.2


maven-compiler-plugin
3.8.0


maven-surefire-plugin
2.22.1


maven-war-plugin
3.2.2


maven-install-plugin
2.5.2


maven-deploy-plugin
2.8.2




"http://xmlns.jcp.org/xml/ns/javaee"

xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation
="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version
="3.1">
Archetype Created Web Application

contextConfigLocation
classpath:applicationContext.xml



class>org.springframework.web.context.ContextLoaderListenerclass>




SpringMVC
class>org.springframework.web.servlet.DispatcherServletclass>


contextConfigLocation
/WEB-INF/spring-mvc.xml

1

<async-supported>trueasync-supported>


SpringMVC
/

"1.0" encoding="UTF-8"?>

"http://www.springframework.org/schema/beans"
xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context
="http://www.springframework.org/schema/context"
xmlns:mvc
="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation
="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">



base-package="com.javaxl.ssm"/>



<[email protected]支持,@DateTimeFormat支持,@Valid支持,读写XML的支持(JAXB),读写JSON的支持(Jackson)-->



class="org.springframework.web.servlet.view.InternalResourceViewResolver">

"viewClass"
value
="org.springframework.web.servlet.view.JstlView">

"prefix" value="/"/>
"suffix" value=".jsp"/>




"/images/" mapping="/images/**"/>



package com.cjh.controller;


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

import javax.servlet.http.HttpServletRequest;

/**
* 关于结果集处理分五种情况
* 1.转发到页面(webapp下)
* 2.转发到action请求
* 3.重定向到页面
* 4.重定向到action
* 5.转发到web_info下的页面
*
* @author
* @site
* @company
* @create 2019-09-28 10:58
*/
@Controller
public class HelloController {

@RequestMapping(
"hello")
public String hello(HttpServletRequest request){
request.setAttribute(
"msg","转发到页面");
return "hello";
}

/**
* 重定向到action
* @param request
* @return
*/
@RequestMapping(
"hello2")
public String redirectPage(HttpServletRequest request){
request.setAttribute(
"msg","重定向到action");
return "redirect: hello";
}

/**
* 重定向到页面
* @param request
* @return
*/
@RequestMapping(
"hello3")
public String redirectPage2(HttpServletRequest request){
// request.setAttribute("msg","重定向到页面");
Object msg = request.getAttribute("msg");

return "redirect:/hello.jsp";
}

/**
* 转发到action请求
* @param request
* @return
*/
@RequestMapping(
"hello4")
public String forwardAction(HttpServletRequest request){
request.setAttribute(
"msg","重定向到action");
return "forward:hello3";
}

/**
*
* @param request
* @return
*/
@RequestMapping(
"hello5")
public String forwardActionw(HttpServletRequest request){
request.setAttribute(
"msg","转发到webinf页面");
return "abcd";
}

}

<%--

Created by IntelliJ IDEA.
User: dell
Date:
2019/9/28
Time:
11:00
To change
this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


Title


hello springmvc


${msg}

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding
="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="/zking" prefix="z" %>
"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


"Content-Type" content="text/html; charset=UTF-8">
Insert title here



"${pageContext.request.contextPath}/book/list"
method
="post">
书名:
"text" name="bname"> "submit"
value
="确定">


"1" width="100%">






"${bookList }" var="b">







编号 名称 价格 操作
${b.bid } ${b.bname } ${b.price }
  &nbsp;


"${pageBean }">

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding
="UTF-8"%>
"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


"Content-Type" content="text/html; charset=UTF-8">
Insert title here



"bookForm" action="" method="post">
bid:
"text" name="bid" value="${b.bid }">

bname:
"text" name="bname" value="${b.bname }">

price:
"text" name="price" value="${b.price }">

"submit" value="提交" onclick="doSubmit(‘${b.bid }‘);">



package com.cjh.util;



import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;
import java.io.IOException;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;


public class PageTag extends BodyTagSupport {

private static final long serialVersionUID = 1L;
private PageBean pageBean;
public PageBean getPageBean() {
return pageBean;
}
public void setPageBean(PageBean pageBean) {
this.pageBean = pageBean;
}
@Override
public int doStartTag() throws JspException {
JspWriter
out = pageContext.getOut();
try {
out.print(toHTML());
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return super.doStartTag();
}
private String toHTML() {
StringBuffer sb
= new StringBuffer();
/*
* 拼接向后台提交数据的form表单
* 注意:拼接的form表单中的page参数是变化的,所以不需要保留上一次请求的值
*/
sb.append(
"
"+pageBean.getUrl()+"‘ method=‘post‘>");
sb.append(
"");
Map
parameterMap = pageBean.getMap();
if(parameterMap != null && parameterMap.size() > 0) {
Set
> entrySet = parameterMap.entrySet();
for (Entry entry : entrySet) {
if(!"page".equals(entry.getKey())) {
String[] values
= entry.getValue();
for (String val : values) {
sb.append(
""+entry.getKey()+"‘ value=‘"+val+"‘>");
}
}
}
}
sb.append(
"");

/*
* 展示的分页条
*/
sb.append(
"
");
sb.append(
"每页"+pageBean.getRows()+"条,共"+pageBean.getTotal()+"条,第"+pageBean.getPage()+"页,共"+pageBean.getMaxPage()+"页  首页  ");
sb.append(
" href=‘javascript:gotoPage("+pageBean.getPreivousPage()+")‘>上一页  ");
sb.append(
" href=‘javascript:gotoPage("+pageBean.getNextPage()+")‘>下一页  ");
sb.append(
" href=‘javascript:gotoPage("+pageBean.getMaxPage()+")‘>尾页  ");
sb.append(
" id=‘skipPage‘");
sb.append(
" style=‘text-align: center; font-size: 12px; width: 50px;‘>  ");
sb.append(
" href=‘javascript:skipPage()‘>Go");
sb.append(
"
");

/*
* 给分页条添加与后台交互的js代码
*/
sb.append(
"");
return sb.toString();
}
}

package com.cjh.controller;


import com.cjh.model.Book;
import com.cjh.service.BookService;
import com.cjh.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
* @author
* @site
* @company
* @create 2019-09-28 13:38
*/
@Controller
@RequestMapping(
"/book")
public class BookController {
@Autowired
private BookService bookService;

@RequestMapping(
"/list")
public String list(Book book, HttpServletRequest request){
PageBean pageBean
= new PageBean();
pageBean.setRequest(request);
List
maps = this.bookService.listPager(book, pageBean);
request.setAttribute(
"bookList",maps);
request.setAttribute(
"pageBean",pageBean);
return "bookList";

}
@RequestMapping(
"/preSave")
public String preSave(Book book, HttpServletRequest request){
if (book.getBid() != null){
Book b
= this.bookService.selectByPrimaryKey(book.getBid());
request.setAttribute(
"b",b);

}
return "bookEdit";

}
@RequestMapping(
"/add")
public String add(Book book, HttpServletRequest request){
this.bookService.insert(book);
return "redirect:/book/list";

}
@RequestMapping(
"/del/{bid}")
public String del(@PathVariable(value = "bid") Integer bid, HttpServletRequest request){
this.bookService.deleteByPrimaryKey(bid);
return "redirect:/book/list";

}
@RequestMapping(
"/edit")
public String edit(Book book, HttpServletRequest request){
this.bookService.updateByPrimaryKeySelective(book);
return "redirect:/book/list";

}
}




"/static/" mapping="/static/**"/>