文档章节

spring+springmvc+mybatis+logback 框架搭建

 非想非非想
发布于 2016/11/04 15:46
字数 2997
阅读 75
收藏 1

注:本文仅仅属于个人记录文档。

一、项目的总体结构、以及所需要的jar包

1.项目结构(注:此处的rsrc/resources为资源目录,新建时New -> source folder)

2.所需要的jar包

二、配置文件源代码

a. 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>portals</display-name>
	
	<!-- 编码过滤 -->
	<filter>
         <filter-name>encodingFilter</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>encodingFilter</filter-name>
         <url-pattern>/*</url-pattern>
     </filter-mapping>
	
	<!-- 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>
	
	<!-- logback 配置监听器。 若不配置的话  会自动寻找根路径下的logback.xml -->
	<!-- <context-param>  
         <param-name>logbackConfigLocation</param-name>  
         <param-value>classpath:logback.xml</param-value>  
	</context-param>  
	
	<listener>  
         <listener-class>ch.qos.logback.ext.spring.web.LogbackConfigListener</listener-class>  
	</listener> -->
	
	<!-- 配置DispatcherServlet -->
	<servlet>
		<servlet-name>spring</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:spring-mvc.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>spring</servlet-name>
		<!-- 此处配置成 /  注意和/*的区别  -->
		<url-pattern>/</url-pattern>
	</servlet-mapping>
	
	<welcome-file-list>
		<welcome-file>/WEB-INF/login.jsp</welcome-file>
	</welcome-file-list>
	
</web-app>

b.data.properties

driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/user
jdbc.username=
jdbc.password=

webServer=http://localhost:8080/portals

c.applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:aop="http://www.springframework.org/schema/aop" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:util="http://www.springframework.org/schema/util"
	xmlns:tx="http://www.springframework.org/schema/tx"
	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.xsd
	http://www.springframework.org/schema/aop
	http://www.springframework.org/schema/aop/spring-aop.xsd
	http://www.springframework.org/schema/tx
	http://www.springframework.org/schema/tx/spring-tx.xsd
	http://www.springframework.org/schema/util
	http://www.springframework.org/schema/util/spring-util.xsd">
	<!-- 扫描service和dao -->
	<context:component-scan base-package="com.study.service,com.study.dao" />
	<!-- 引入资源文件的三种方式 -->
	<!-- <context:property-placeholder location="classpath:data.properties"/> -->
	<!-- <bean id="propertyConfigurer"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="location">
			<value>classpath:data.properties</value>
		</property>
	</bean> 
	<bean id="dataSource"
		class="org.springframework.jdbc.datasource.DriverManagerDataSource">
		<property name="driverClassName" value="${jdbc.driver}" />
		<property name="url" value="${jdbc.url}" />
		<property name="username" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
	</bean>-->
	<util:properties id="settings" location="classpath:data.properties" />

	<bean id="dataSource"
		class="org.springframework.jdbc.datasource.DriverManagerDataSource">
		<property name="driverClassName" value="#{settings.driver}" />
		<property name="url" value="#{settings['jdbc.url']}" />
		<property name="username" value="#{settings['jdbc.username']}" />
		<property name="password" value="#{settings['jdbc.password']}" />
	</bean>
	<!-- 和mybatis的映射,可以引入comfig文件的配置,也可以不引入 -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<!-- mybatis主配置文件 -->
		<!-- <property name="configLocation" value="/WEB-INF/resource_xml/mybatis-config.xml" /> -->
		<!-- 映射mapper文件 -->
		<property name="mapperLocations" value="classpath*:com/study/sql/mybatis-sql-*.xml"/> 
		<!-- 在sql中写入时    parameterType 可以直接写简写 不必写整个包+class 和主配置文件一块使用-->
		<!-- <property name="typeAliasesPackage" value="com.study.pojo.*"/>  -->
	</bean>

	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.study.dao"></property>
		<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
	</bean>
	<!-- 配置事物 -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>
	
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="*" propagation="REQUIRED"/>
		</tx:attributes>
	</tx:advice>
	
	<aop:config>
		<aop:pointcut id="allServiceMethod" expression="execution(* com.study.service.*.*(..))"/>
		<aop:advisor advice-ref="txAdvice" pointcut-ref="allServiceMethod"/>
	</aop:config>
	<!-- 在容器启动时,完成webServer的注入,前台使用 -->
	<bean id="WebConfig" class="com.study.util.WebConfig">
		<property name="beanName" value="webServer" />
		<property name="webServer" value="#{settings.webServer}"></property>
	</bean>
	
</beans>

d.spring-mvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	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/context
	http://www.springframework.org/schema/context/spring-context.xsd
	http://www.springframework.org/schema/aop
	http://www.springframework.org/schema/aop/spring-aop.xsd
	http://www.springframework.org/schema/mvc
	http://www.springframework.org/schema/mvc/spring-mvc.xsd">
	
	<!-- 扫描controller     service和dao在applicationContext.xml中进行扫描 -->
	<context:component-scan base-package="com.study.controller"/>
	
	<mvc:annotation-driven/>
	
	<!-- 资源映射的两种方式,选择一种即可 -->
	<mvc:default-servlet-handler />
	<!-- <mvc:resources location="/resource/" mapping="/resource/**" /> -->
	
	<!-- 视图解析 -->
	<bean id="viewResolver"
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="viewClass"
			value="org.springframework.web.servlet.view.JstlView" />
		<property name="prefix" value="/WEB-INF/jsp/" />
		<property name="suffix" value=".jsp" />
	</bean>
	
	<!-- 此处原本是配置json的映射      发现引入了
		jackson-annotations-2.8.4.jar
		jackson-core-2.8.4.jar
		jackson-databind-2.8.4.jar   三个jar包就可以实现 -->
	<!-- 在spring 4.x之后  使用 MappingJackson2HttpMessageConverter 
		                                 以前的为 MappingJacksonHttpMessageConverter-->
	<!-- <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
		<property name="messageConverters">
			<list>
				<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
				</bean>
			</list>
		</property>
	</bean> -->
	
</beans>

e.mybatis-config.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>
		<!-- <typeAlias type="com.study.pojo.User" alias="User"/> -->
	</typeAliases>
	<mappers>
		<!-- <mapper resource="com/study/sql/mybatis-sql-user.xml" /> -->
	</mappers>
</configuration>

f.logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- configuration file for LogBack (slf4J implementation) See here for more 
	details: http://gordondickens.com/wordpress/2013/03/27/sawing-through-the-java-loggers/ -->
<configuration scan="true" scanPeriod="30 seconds">

	<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
		<resetJUL>true</resetJUL>
	</contextListener>

	<!-- To enable JMX Management -->
	<jmxConfigurator />

	<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
		<encoder>
			<pattern>%d{yyyy-MM-dd HH:mm:ss}-%-5level %logger{0} - %msg%n
			</pattern>
		</encoder>
	</appender>

	<!-- 滚动记录文件,先将日志记录到指定文件,当符合某个条件时,将日志记录到其他文件 -->
	<appender name="file"
		class="ch.qos.logback.core.rolling.RollingFileAppender">
		<Encoding>UTF-8</Encoding>
		<!-- 指定日志文件的名称 <file>${compilePath}/exam.log</file> -->
		<!-- 当发生滚动时,决定 RollingFileAppender 的行为,涉及文件移动和重命名 TimeBasedRollingPolicy: 
			最常用的滚动策略,它根据时间来制定滚动策略,既负责滚动也负责出发滚动。 -->
		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
			<!-- 滚动时产生的文件的存放位置及文件名称 %d{yyyy-MM-dd}:按天进行日志滚动 %i:当文件大小超过maxFileSize时,按照i进行文件滚动 
				当使用tomcat配置时,修改$(user.dir)为${catalina.base}。获取绝对路径。 -->
			<fileNamePattern>D:/portals/logs/%d{yyyy-MM-dd}-%i.log
			</fileNamePattern>
			<!-- 可选节点,控制保留的归档文件的最大数量,超出数量就删除旧文件。假设设置每天滚动, 且maxHistory是365,则只保存最近365天的文件,删除之前的旧文件。注意,删除旧文件是, 
				那些为了归档而创建的目录也会被删除。 -->
			<MaxHistory>365</MaxHistory>
			<!-- 当日志文件超过maxFileSize指定的大小是,根据上面提到的%i进行日志文件滚动 注意此处配置SizeBasedTriggeringPolicy是无法实现按文件大小进行滚动的,必须配置timeBasedFileNamingAndTriggeringPolicy -->
			<timeBasedFileNamingAndTriggeringPolicy
				class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
				<maxFileSize>50MB</maxFileSize>
			</timeBasedFileNamingAndTriggeringPolicy>
		</rollingPolicy>
		<!-- 日志输出格式:%d表示日期时间,%thread表示线程名,%-5level:级别从左显示5个字符宽度 %logger{50} 表示logger名字最长50个字符,否则按照句点分割。 
			%msg:日志消息,%n是换行符 -->
		<layout class="ch.qos.logback.classic.PatternLayout">
			<pattern>%d{yyyy-MM-dd HH:mm:ss} - [ %-5level ] [ %logger{0} : %line
				] - %msg%n</pattern>
		</layout>
	</appender>
	<!-- 打印sql语句 -->
	<logger name="java.sql.Connection" level="DEBUG" />
	<logger name="java.sql.Statement" level="DEBUG" />
	<logger name="java.sql.PreparedStatement" level="DEBUG" />

	<root level="debug">
		<appender-ref ref="console" />
		<!-- 放开之后,会写入到文件中 -->
		<!-- <appender-ref ref="file" /> -->
	</root>
</configuration>

三、java文件代码

a.User.java

package com.study.pojo;

import java.io.Serializable;

public class User implements Serializable {
	private static final long serialVersionUID = 1L;
	private int id;
	private String name;
	private String sex;
	private int age;
	public User() {
	}
	public User(int id, String name, String sex, int age) {
		super();
		this.id = id;
		this.name = name;
		this.sex = sex;
		this.age = age;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	@Override
	public String toString() {
		return "User [id=" + id + ", name=" + name + ", sex=" + sex + ", age=" + age + "]";
	}
}

b.UserController.java

package com.study.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.study.pojo.User;
import com.study.service.UserService;
import com.study.util.JsonResult;

@Controller
public class UserController {
	@Autowired
	private UserService userService;
	
	@Value("#{settings.driver}")
	private String name;
	
	@RequestMapping("login")
	@ResponseBody  //不可缺少该注解
	public JsonResult login(User user,HttpServletRequest req) {
		System.out.println("================"+user);		
		JsonResult jsonResult = new JsonResult();
		jsonResult.setFlag(true);
		jsonResult.setObject(user);
		jsonResult.setMessage("success");
		return jsonResult;
	}
	
	@RequestMapping("user")
	public String userList(Model model,HttpServletRequest req) {
		List<User> userList = userService.getUserList();
		/*for(int i=100; i<105; i++){
			userList.add(new User(i,"zhangsan","男",i-80));
		}*/
		System.out.println(userList.toString());		
		model.addAttribute("userList", userList);
		return "user";
	}
	
	@RequestMapping("add")
	public String addUser(Model model,HttpServletRequest req) {
		User user = new User(57,"jack","男",18);
		userService.addUser(user);
		/*for(int i=100; i<105; i++){
			userList.add(new User(i,"zhangsan","男",i-80));
		}*/
		System.out.println(user);		
		
		return "";
	}
	
	@RequestMapping("test")
	public String test(Model model,HttpServletRequest req) {
		System.out.println("------------------test--------------------");		
		List<User> userList = userService.getUserList();
		/*for(int i=100; i<105; i++){
			userList.add(new User(i,"zhangsan","男",i-80));
		}*/
		System.out.println(userList.toString());		
		model.addAttribute("userList", userList);
		return "test";
	}
	
	@RequestMapping("test2")
	public String test2(Model model,HttpServletRequest req) {
		System.out.println(name +"------------------name--------------------");		
		
		return "test";
	}
}

c.UserServiceImpl.java      (实现UserService接口)

package com.study.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.study.dao.UserDao;
import com.study.pojo.User;
import com.study.service.UserService;

@Service
public class UserServiceImpl implements UserService {
	@Autowired
	private UserDao userDao;

	@Override
	public List<User> getUserList() {
		List<User> userList= userDao.getUserList();
		return userList;
	}
        //测试事务
	@Override
	public int addUser(User user) {
		System.out.println("----111----test-tx----------------");
		int j = userDao.deleteUser(58);
			
		System.out.println("---222-----test-tx----------------");
		int i = userDao.addUser(user);
		System.out.println("---333-----test-tx----------------");	
			
		return 5;
	}

	@Override
	public int deleteUser(int id) {
		int i = userDao.deleteUser(id);
		return i;
	}

	@Override
	public int updateUser(int id) {
		int i = userDao.updateUser(id);
		return i;
	}
}

d.UserDao.java

package com.study.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.study.pojo.User;

@Repository
public interface UserDao {

	public List<User> getUserList();

	public int addUser(User user);

	public int deleteUser(int id);

	public int updateUser(int id);
	
}

e.mybatis-sql-user.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">
  <mapper namespace="com.study.dao.UserDao">
  
  	<resultMap type="com.study.pojo.User" id="User" >
  		<!-- <result column="id" property="id" />
  		<result column="name" property="name" />
  		<result column="sex" property="sex" />
  		<result column="age" property="age" /> -->
  	</resultMap>
  
  	<insert id="addUser" parameterType="com.study.pojo.User">
  		<![CDATA[
  			insert into tbl_user (id,password,name,sex,age) values(#{id},'123456',#{name},#{sex},#{age})
  		]]>
  	</insert>
  	
  	<select id="getUserList" resultMap="User">
  		<![CDATA[
  			select * from tbl_user
  		]]>
  	</select>
  	
  	<update id="updateUser" parameterType="int">
  		<![CDATA[
  			update tbl_user set name=#{name},sex=#{sex},age=#{age} where id=#{id}
  		]]>
  	</update>
  	
  	<delete id="deleteUser" parameterType="int">
  		<![CDATA[
  			delete from tbl_user where id=#{id}
  		]]>
  	</delete>
  	
  </mapper>

f.WebConfig.java

package com.study.util;

import javax.servlet.ServletContext;

import org.springframework.web.context.ServletContextAware;

public class WebConfig implements ServletContextAware {

	private String beanName;
	//@Value("#{settings.webServer}")
	private String webServer;
	
	@Override
	public void setServletContext(ServletContext servletContext) {
		servletContext.setAttribute(beanName, webServer);
	}

	public String getBeanName() {
		return beanName;
	}

	public void setBeanName(String beanName) {
		this.beanName = beanName;
	}

	public String getWebServer() {
		return webServer;
	}

	public void setWebServer(String webServer) {
		this.webServer = webServer;
	}
	
}

g.JsonResult.java

package com.study.util;

public class JsonResult {
	private boolean flag;
	private Object object;
	private String message;
	
	public boolean isFlag() {
		return flag;
	}
	public void setFlag(boolean flag) {
		this.flag = flag;
	}
	public Object getObject() {
		return object;
	}
	public void setObject(Object object) {
		this.object = object;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	
}

四、jsp文件

a. user.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>user list</title>
</head>
<body>
<h1>${webServer}</h1>
	<c:forEach items="${userList}" var="user">
		<h1>${user.id}</h1>
		<h1>${user.name}</h1>
		<h1>${user.sex}</h1>
		<h1>${user.age}</h1>
	</c:forEach>
</body>
</html>

b.test.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=0.5, initial-scale=1.0">
	
	<title>my first bootstrap page</title>

	<link rel="stylesheet" type="text/css" href="${webServer}/resource/css/bootstrap.css">

	<script type="text/javascript" src="${webServer}/resource/js/jquery-3.1.1.min.js"></script>
	<script type="text/javascript" src="${webServer}/resource/js/bootstrap.js"></script>

	<style type="text/css">
		
	</style>
</head>
<body>
	<nav class="navbar navbar-inverse" role="navigation">
		<div class="container-fluid">
			<div class="navbar-header">
				<a class="navbar-brand" href="javascript:void(0);">my library</a>
			</div>
			<div class="col-md-offset-2">
				<ul class="nav navbar-nav">
					<li class="active"><a href="javascript:void(0);">中文资料</a></li>
					<li><a href="javascript:void(0);">外文资料</a></li>
					<li><a href="javascript:void(0);">网络技术资料</a></li>
					<li class="dropdown">
						<a href="javascript:void(0);" class="dropdown-toggle" data-toggle="dropdown">技术语言指导
							<span class="caret"></span>
						</a>
						<ul class="dropdown-menu">
							<li><a href="javascript:void(0);">java语言</a></li>
							<li class="divider"></li>
							<li><a href="javascript:void(0);">C语言</a></li>
							<li><a href="javascript:void(0);">C++语言</a></li>
						</ul>
					</li>
				</ul>
			</div>
			<div class="col-md-offset-10">
				<ul class="nav navbar-nav">
					<li class="disable"><a href="javascript:void(0);">欢迎:张三</a></li>
					<li class=""><a href="javascript:void(0);">2016-10-24</a></li>
				</ul>
			</div>
		</div>
	</nav>

	<div class="container-fluid">
		<div class="row">
			<div class="col-md-2">
				<ul class="nav nav-stacked" style="background-color: rgba(211, 220, 222, 0.16);;">
					<li style="background-color: rgba(134, 167, 210, 0.52);"><a href="javascript:void(0);">英文资料</a></li>
					<li><a href="javascript:void(0);">中文资料</a></li>
					<li class="disabled"><a href="javascript:void(0);">英文资料</a></li>
					<li><a href="javascript:void(0);">
						<span class="glyphicon glyphicon-fire"></span>中文资料</a></li>
					<li><a href="javascript:void(0);">
						<span class="glyphicon glyphicon-fire">英文资料</a></li>
					<li><a href="javascript:void(0);">中文资料</a></li>
					<li><a href="javascript:void(0);">英文资料</a></li>
				</ul>
			</div>
			<div class="col-md-10" style="backgroung-color:red;height:200px">
				<div id="myCarousel" class="carousel slide">
					<ol class="carousel-indicators">
						<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
						<li data-target="#myCarousel" data-slide-to="1"></li>
						<li data-target="#myCarousel" data-slide-to="2"></li>
					</ol>
					<div class="carousel-inner">
						<div class="item active">
							<img src="${webServer}/resource/img/Jellyfish.jpg" alt="First slide">
            				<div class="carousel-caption">美如画</div>
						</div>
						<div class="item">
							<img src="${webServer}/resource/img/Koala.jpg" alt="Second slide">
            				<div class="carousel-caption">美如画</div>
						</div>
						<div class="item">
							<img src="${webServer}/resource/img/Lighthouse.jpg" alt="Third slide">
            				<div class="carousel-caption">美如画</div>
						</div>
					</div>
				</div>

				<div style="margin-top:20px">
					<ol class="breadcrumb">
					    <li><a href="javascript:void(0);">Home</a></li>
					    <li><a href="javascript:void(0);">first</a></li>
					    <li class="active">second</li>
					</ol>
				</div>

				<div style="margin-top:20px">
					<table class="table table-hover">
						<caption>悬停表格布局</caption>
						<thead>
							<tr>
								<th>id</th>
								<th>姓名</th>
								<th>性别</th>
								<th>年龄</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach items="${userList}" var="user">
								<tr>
								<td>${user.id}</td>
								<td>${user.name}</td>
								<td>${user.sex}</td>
								<td>${user.age}</td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
				</div>

				<div style="margin-top:20px">					
					<button type="button" class="btn btn-lg btn-primary" data-toggle="collapse" 
						data-target="#demo">简单的可折叠组件
					</button>    
					<div id="demo" class="collapse in">
						Nihil anim keffiyeh helvetica, craft beer labore wes anderson 
					cred nesciunt sapiente ea proident. Ad vegan excepteur butcher 
					vice lomo.
					</div>
					<div class="pannel pannel-default">
						<div class="panel-heading">
							<span class="pannel-title">
								<a data-toggle="collapse" data-target="#myDemo">点击</a>
							</span>
						</div>
						<div id="myDemo" class="pannel-collapse collapse in">
							<div class="panel-body">
								Nihil anim keffiyeh helvetica, craft beer labore wes anderson 
							cred nesciunt sapiente ea proident. Ad vegan excepteur butcher 
							vice lomo.
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

	<script>

	</script>
</body>
</html>

c login.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<!-- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> -->
<title>Insert title here</title>

<script type="text/javascript" src="${webServer}/resource/js/jquery-3.1.1.min.js"></script>
</head>
<body>
<a href="http://localhost:8080/portals/user"><h1>跳转</h1></a>
<div>
	姓名: <input id="name" type="text" value="张三" placeholder="张三"/><br/>
	性别: <select id="sex">
		<option value="male">男</option>
		<option value="female">女</option>
	</select><br/>
	年龄: <input id="age" type="text" value="20" placeholder="20"/>岁<br/>
	<button id="login">提交</button>
</div>
<script>
	$("#login").click(function(){
		var user={
				"name": $("#name").val(),
				"age" : $("#age").val(),
				"sex" : $("#sex").val()
		};
		alert(user.name);
		$.ajax({
			type: 'post',
			url: "${webServer}/login",
			data : user,
			success: function(data){
				alert(data.message);
			},
			error:function(data){  
				alert("出错了!!:"+data.msg); 
			} 
		});
		return false;
	});
</script>

</body>
</html>

 

© 著作权归作者所有

上一篇: jsoup简单应用
下一篇: python3 错误解决
粉丝 1
博文 43
码字总数 25764
作品 0
西安
私信 提问
【文集】 Unity 游戏框架搭建

游戏总是需要一个框架,才能更好的开发,Unity下也不例外 Unity 游戏框架搭建 (一) 概述 Unity 游戏框架搭建 (二) 单例的模板 Unity 游戏框架搭建 (三) MonoBehaviour单例的模板 Unity 游戏框...

CatherinePlans
2017/11/05
0
0
SpringCloud实战--新闻门户网站-李熠-专题视频课程

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lynnlovemin/article/details/83580775 SpringCloud实战--新闻门户网站—149人已学习 课程介绍 本套课程从实战...

lynnlovemin
2018/05/21
0
0
【自动化测试框架】 | 基于 selenium+Python,怎样从零开始搭建一个属于自己项目的测试框架

本框架是别人项目正在使用的框架,我这边抓取后经过了一点优化后整理出来的,大致包括,自动化用例套件、数据分离、日志模板、配置分离、断言、接口自动化、持续集成、自动化报告等方面,已经...

西边人
2018/06/15
0
0
搭建你的Spring.Net+Nhibernate+Asp.Net Mvc 框架 (六)写在后面的话

如果在你的项目中,配置的没有报错,但是总是注入进来的都是null的话,可查看配置文件所在的项目是否添加了配置文件中所引用或配置了的项目。还有就是mvc中control中注入都失败了。这个最后还...

aicoder
2010/09/07
0
0
ssi环境搭建,大家是怎么处理版本兼容性的?

在java平台上搭建框架,比如搭建ssi(springmvc+spring+mybatis),搭建框架会用到很多包,大家是怎么找到互相兼容的版本的?是在网上参考其他人搭建的,还是有一个专门找兼容的方法呢?...

码农陈大浏
2017/04/17
58
1

没有更多内容

加载失败,请刷新页面

加载更多

Android双向绑定原理简述

Android双向绑定原理简述 双向绑定涉及两个部分,即将业务状态的变化传递给UI,以及将用户输入信息传递给业务模型。 首先我们来看业务状态是如何传递给UI的。开启dataBinding后,编译器为布局...

tommwq
今天
3
0
Spring系列教程八: Spring实现事务的两种方式

一、 Spring事务概念: 事务是一系列的动作,它们综合在一起才是一个完整的工作单元,这些动作必须全部完成,如果有一个失败的话,那么事务就会回滚到最开始的状态,仿佛什么都没发生过一样。...

我叫小糖主
今天
7
0
CentOS 的基本使用

1. 使用 sudo 命令, 可以以 root 身份执行命令, 必须要在 /etc/sudoers 中定义普通用户 2. 设置 阿里云 yum 镜像, 参考 https://opsx.alibaba.com/mirror # 备份mv /etc/yum.repos.d/CentO...

北漂的我
昨天
3
0
Proxmox VE技巧 移除PVE “没有有效订阅” 的弹窗提示

登陆的时候提示没有有效的订阅You do not have a valid subscription for this server. Please visit www.proxmox.com to get a list of available options. 用的是免费版的,所以每次都提示......

以谁为师
昨天
5
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部