闲着无聊配置一遍SSM以及添加功能增删改查,如下图,其中坎坷也挺多!!!
1.工程如下图。(请忽略红叉,没有错误)
2.首先配置pom.xml文件。
<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.summer</groupId>
<artifactId>ssmdemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<!-- springMVC -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!-- spring jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!-- spring aop -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!-- mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.2</version>
</dependency>
<!-- mybatis与spring整合 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.1</version>
</dependency>
<!-- 数据库连接池 和驱动-->
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.40</version>
</dependency>
<!-- jstl junit servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- spring单元测试 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.7.RELEASE</version>
<scope>test</scope>
</dependency>
<!-- 引入Mybatis分页插件 -->
<!-- 引入5.0版本在测试的时候会报错 4.2版本也会报错
4.2版本总是出现String无法转换为某个对象的错误
-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.1.5</version>
</dependency>
</dependencies>
</project>
3.实体类:
package cn.com.model;
/**
*
* @author L
*
*/
public class User {
//主键
private int id;
//用户名
private String username;
//年龄
private String age;
public User() {
super();
}
public User(int id, String username, String age) {
super();
this.id = id;
this.username = username;
this.age = age;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
}
4.创建DAO接口(Mybaits中Mapper就是dao)
5.实现DAO接口(我这里就是UserMapper.xml)
<?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">
<!--
namespace:必须与对应的接口全类名一致 UserMapper.java
id :必须与对应接口的某个对应的方法名一致即必须要和UserMapper.java接口中的方法同名。
-->
<mapper namespace="cn.com.dao.UserMapper">
<!-- 新增 -->
<insert id="saveUser" parameterType="User" >
insert into t_user(user_name,user_age) values (#{username},#{age})
</insert>
<!-- 修改 -->
<update id="updateUser" parameterType="User" >
update t_user set user_name=#{username},user_age=#{age} where user_id=#{id}
</update>
<!-- 删除 -->
<delete id="deleteUser" parameterType="int">
delete from t_user where user_id=#{id}
</delete>
<!-- 根据id查找单个用户 -->
<select id="findUserById" parameterType="int" resultType="User">
select user_id id,user_name username,user_age age from t_user where user_id=#{id}
</select>
<!-- 查询所有 -->
<select id="findAll" resultType="User">
select user_id id,user_name userName,user_age age from t_user
</select>
</mapper>
6.配置applicationContext.xml(也有叫spring.xml)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
">
<!-- 注解扫描包 -->
<context:component-scan base-package="cn.com" />
<!-- 加载jdbc.properties文件 -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!--第一步: 配置数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="jdbcUrl" value="${jdbc.url}"></property>
<property name="driverClass" value="${jdbc.driver}"></property>
<property name="user" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean>
<!-- 配置和mybatis的整合 -->
<!--第二步: 创建sqlSessionFactory工厂 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<!-- 指定Mybatis全局配置文件的位置 -->
<property name="configLocation" value="classpath:sqlConfig.xml"></property>
</bean>
<!-- 配置mybatis的代理接口开发 * 接口类名和映射文件必须同名 * 接口类和映射文件必须在同一个目 录下 * 接口的映射文件的namespace名称必须是接口的全限定名
* 接口的方法名必须和映射的statement的id一致 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 扫描所有dao接口的实现,加入到ioc容器中 -->
<property name="basePackage" value="cn.com.dao"></property>
<property name="SqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>
<!--第三步: 事物 -->
<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 配置拦截service -->
<aop:config>
<aop:pointcut expression="execution(* cn.com.service..*(..))" id="txPoint"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPoint"/>
</aop:config>
<!-- 配置事物增强,事物如何切入-->
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<!-- 所有方法都是事物方法 -->
<tx:method name="*"/>
<!-- 以get开始的所有方法 -->
<tx:method name="get*" read-only="true"/>
</tx:attributes>
</tx:advice>
</beans>
7.配置Mybaits配置文件(我写的是 sqlConfig.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>
<!-- 别名设置 -->
<typeAliases>
<package name="cn.com.model" />
</typeAliases>
<!-- mybatis分页插件 -->
<plugins>
<plugin interceptor="com.github.pagehelper.PageHelper">
<property name="dialect" value="mysql"/>
<property name="offsetAsPageNum" value="false"/>
<property name="rowBoundsWithCount" value="false"/>
<property name="pageSizeZero" value="true"/>
<property name="reasonable" value="false"/>
<property name="supportMethodsArguments" value="false"/>
<property name="returnPageInfo" value="none"/
</plugin>
</plugins>
</configuration>
8.配置log4.properties
### set log levels ###
log4j.rootLogger = INFO , console , debug , error
### console ###
log4j.appender.console = org.apache.log4j.ConsoleAppender
log4j.appender.console.Target = System.out
log4j.appender.console.layout = org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern = %-d{yyyy-MM-dd HH\:mm\:ss} [%p]-[%c] %m%n
### log file ###
log4j.appender.debug = org.apache.log4j.DailyRollingFileAppender
log4j.appender.debug.File = ../logs/springmvc-demo.log
log4j.appender.debug.Append = true
log4j.appender.debug.Threshold = INFO
log4j.appender.debug.layout = org.apache.log4j.PatternLayout
log4j.appender.debug.layout.ConversionPattern = %-d{yyyy-MM-dd HH\:mm\:ss} [%p]-[%c] %m%n
### exception ###
log4j.appender.error = org.apache.log4j.DailyRollingFileAppender
log4j.appender.error.File = ../logs/springmvc-demo_error.log
log4j.appender.error.Append = true
log4j.appender.error.Threshold = ERROR
log4j.appender.error.layout = org.apache.log4j.PatternLayout
log4j.appender.error.layout.ConversionPattern = %-d{yyyy-MM-dd HH\:mm\:ss} [%p]-[%c] %m%n
###\u9700\u8981\u58F0\u660E\uFF0C\u7136\u540E\u4E0B\u65B9\u624D\u53EF\u4EE5\u4F7Fdruid sql\u8F93\u51FA\uFF0C\u5426\u5219\u4F1A\u629B\u51FAlog4j.error.key not found
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} %l %c%n%p: %m%n
### druid sql ###
log4j.logger.druid.sql=warn,stdout
log4j.logger.druid.sql.DataSource=warn,stdout
log4j.logger.druid.sql.Connection=warn,stdout
log4j.logger.druid.sql.Statement=warn,stdout
log4j.logger.druid.sql.ResultSet=warn,stdout
9.配置jdbc.properties(数据连接地址/账户/密码/数据库名称请自行更改)
#jdbc.properties
jdbc.url = jdbc:mysql://127.0.1.100:3306/test?characterEncoding=utf-8
jdbc.driver = com.mysql.jdbc.Driver
jdbc.username= root
jdbc.password= root
10.配置springmvc.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/context/spring-tx.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
">
<!-- 扫描注解包 -->
<context:component-scan base-package="cn.com.dao"/>
<context:component-scan base-package="cn.com.controller"/>
<context:component-scan base-package="cn.com.service"/>
<!-- 配置sprigmvc视图解析器:解析逻辑试图
后台返回逻辑试图:index
视图解析器解析出真正物理视图:前缀+逻辑试图+后缀====/WEB-INF/page/index.jsp-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/page/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<!--1: mvc:annotation-driven默认创建了 RequestMappingHandlerMapping和 RequestMappingHandlerAdapter对象
提供对JSon数据格式的支持-->
<mvc:annotation-driven />
<!-- 2.配置静态资源访问 -->
<mvc:default-servlet-handler/>
</beans>
11.配置web.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>ssmdemo</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- 加载Spring容器配置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 配置SpringMVC核心控制器 -->
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- 拦截所有请求 -->
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- 字符编码过滤器 -->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
12.service类
13.seviceImpl实现
package cn.com.serviceImpl;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.com.dao.UserMapper;
import cn.com.model.User;
import cn.com.service.UserService;
/**
*
* @author L
*
*/
@Service
public class UserServiceImpl implements UserService {
/**
* 注入UserMapper接口
*/
@Autowired
private UserMapper userMapper;
/**
* 新增用户
*/
@Override
public void saveUser(User user) {
userMapper.saveUser(user);
}
/**
* 更新用户
*/
@Override
public boolean updateUser(User user) {
return userMapper.updateUser(user);
}
/**
* 根据Id删除用户
*/
@Override
public boolean deleteUser(int id) {
return userMapper.deleteUser(id);
}
/**
* 根据id查找用户
*/
@Override
public User findUserById(int id) {
User user = userMapper.findUserById(id);
return user;
}
/**
* 查询所有用户
*/
@Override
public List<User> findAll() {
List<User> allUser = userMapper.findAll();
return allUser;
}
}
14.Controller类
package cn.com.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.com.model.User;
import cn.com.service.UserService;
@Controller
@RequestMapping("/user")
/**
*
* @author L
*
*/
public class UserController {
@Autowired
private UserService userService;
/**
*跳转到添加用户界面
*/
@RequestMapping("toAddUser")
public String toAddUser(){
return "addUser";
}
/**
* 添加用户并重定向
* @param model
* @param user
* @return
*/
@RequestMapping("addUser")
public String addUser(Model model,User user){
if(user != null){
userService.saveUser(user);
}
return "redirect:/user/userInfo";
}
/**
* 修改用户
* @param model
* @param request
* @param user
* @return
*/
@RequestMapping("updateUser")
public String UpdateUser(Model model,User user){
if(userService.updateUser(user)){
user = userService.findUserById(user.getId());
model.addAttribute("user", user);
return "redirect:/user/userInfo";
}
return "/error";
}
/**
* 查询所有用户
* @param request
* @param model
* @return
*/
@RequestMapping("getAllUser")
public String getAllUser(Model model){
List<User> user = userService.findAll();
model.addAttribute("userList",user);
return "allUser";
}
/**
* 查询单个用户
* @param id
* @param request
* @param model
* @return
*/
@RequestMapping("/getUser")
public String getUser(int id,Model model){
model.addAttribute("user", userService.findUserById(id));
return "editUser";
}
/**
* 根据id删除用户
* @param id
* @param request
* @param response
*/
@RequestMapping("/delUser")
public String deleteUser(int id,Model model){
model.addAttribute("user", userService.deleteUser(id));
return "redirect:/user/userInfo";
}
/**
* 分页查询用户信息
* @param pn 默认从第一页开始 请求参数
* @param model
* @return
*/
@RequestMapping("userInfo")
public String getUsers(@RequestParam(value="pn",defaultValue="1")Integer pn,Model model){
//从第一条开始 每页查询五条数据
PageHelper.startPage(pn, 5);
List<User> users = userService.findAll();
//将用户信息放入PageInfo对象里
PageInfo page = new PageInfo(users,5);
model.addAttribute("pageInfo", page);
return "allUser";
}
}
后台的到这基本完成,下面是前台部分
15.登录index.jsp页面
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
pageContext.setAttribute("path", request.getContextPath());
%>
<!DOCTYPE htm >
<html>
<head>
<title>首页</title>
<style type="text/css">
a {
text-decoration: none;
color: #fff;
font-size: 14px;
}
h3 {
180px;
height: 38px;
margin: 100px auto;
text-align: center;
line-height: 38px;
background: #5BC0DE;
border-radius: 4px;
}
</style>
</head>
<body>
<h3>
<a href="${path}/user/userInfo">进入用户管理页</a>
</h3>
</body>
</html>
16.所有数据页面allUser.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
pageContext.setAttribute("path", request.getContextPath());
%>
<!DOCTYPE HTML>
<html>
<head>
<title>用户列表</title>
<link
href="${path}/static/bootstrap-3.3.7-dist/css/bootstrap.min.css"
rel="stylesheet">
<script type="text/javascript"
src="${path}/static/bootstrap-3.3.7-dist/js/jquery-1.10.1.min.js"></script>
<script type="text/javascript"
src="${path}/static/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<!-- 标题 -->
<div class="row">
<div class="col-md-12">
<h1>用户管理</h1>
</div>
</div>
<!-- 按钮 -->
<div class="row">
<div class="col-md-4 col-md-offset-8">
<a class="btn btn-primary" href="${path}/user/toAddUser">新增</a>
</div>
</div>
<!-- 表格 -->
<div class="row">
<div class="col-md-12">
<table class="table table-hover">
<tr>
<th>id</th>
<th>用户名</th>
<th>年龄</th>
<th>操作</th>
</tr>
<c:forEach items="${pageInfo.list }" var="user">
<tr>
<td>${user.id}</td>
<td>${user.username }</td>
<td>${user.age }</td>
<!-- <td><a class="edit">编辑</a> <a
class="delete">删除</a></td> -->
<td>
<a type="button" href="${path}/user/getUser?id=${user.id}" class="btn btn-info btn-sm">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
编辑</a>
<a type="button" href="${path}/user/delUser?id=${user.id}" class="btn btn-danger btn-sm">
<span class="glyphicon glyphicon-trash" aria-hidden="true" ></span>
删除</a>
</td>
</tr>
</c:forEach>
</table>
</div>
</div>
<hr style="height:1px;border:none;border-top:1px solid #ccc;" />
<!-- 分页导航栏 -->
<!-- 分页信息 -->
<div class="row">
<!-- 分页文字信息,其中分页信息都封装在pageInfo中 -->
<div class="col-md-6">
当前第:${pageInfo.pageNum}页,总共:${pageInfo.pages}页,总共:${pageInfo.total}条记录
</div>
<!-- 分页条 -->
<div class="col-md-6">
<nav aria-label="Page navigation">
<ul class="pagination">
<li><a href="${path}/user/userInfo?pn=1">首页</a></li>
<c:if test="${pageInfo.hasPreviousPage }">
<li>
<a href="${path}/user/userInfo?pn=${pageInfo.pageNum-1}" aria-label="Previous">
<span aria-hidden="true">«</span>
</a>
</li>
</c:if>
<c:forEach items="${pageInfo.navigatepageNums }" var="page_Num">
<c:if test="${page_Num == pageInfo.pageNum }">
<li class="active"><a href="#">${ page_Num}</a></li>
</c:if>
<c:if test="${page_Num != pageInfo.pageNum }">
<li><a href="${path}/user/userInfo?pn=${ page_Num}">${ page_Num}</a></li>
</c:if>
</c:forEach>
<c:if test="${pageInfo.hasNextPage }">
<li>
<a href="${path}/user/userInfo?pn=${pageInfo.pageNum+1}" aria-label="Next">
<span aria-hidden="true">»</span>
</a>
</li>
</c:if>
<li><a href="${path}/user/userInfo?pn=${pageInfo.pages}">末页</a></li>
</ul>
</nav>
</div>
</div>
</div>
</body>
</html>
17.编辑用户页面,editUser
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>编辑用户</title>
<script type="text/javascript">
function updateUser() {
var form = document.forms[0];
form.action = "<%=basePath %>user/updateUser";
form.method = "post";
form.submit();
}
</script>
</head>
<body>
<h1>添加用户</h1>
<form action="" name="userForm">
<input type="hidden" name="id" value="${user.id }" /> 姓名:<input
type="text" name="username" value="${user.username }" /> 年龄:<input
type="text" name="age" value="${user.age }" /> <input type="button"
value="编辑" onclick="updateUser()" />
</form>
</body>
</html>
18.添加用户页面,addUser
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<html>
<title>添加用户</title>
</head>
<body>
<h1>添加用户</h1>
<form action="" name="userForm">
姓名:<input type="text" name="username"><br>
年龄:<input type="text" name="age"><br>
<input type="button" value="添加"
onclick="addUser()">
</form>
<script type="text/javascript">
function addUser() {
var form = document.forms[0];
form.action = "<%=basePath %>user/addUser";
form.method = "post";
form.submit();
}
</script>
</body>
</html>
static中的文件下载地址:
https://codeload.github.com/twbs/bootstrap/zip/v3.3.7
注:
如果项目名称和我的不同,那么xml中扫描注解的包需要改动,否则报错,显示找不到类,这属于直接映射的配置