为了账号安全,请及时绑定邮箱和手机立即绑定

广东网上投注站,舟山棋牌

2017.07.24 16:54 4683浏览

本文地址:http://www.bgel.cn/article/19431
文章摘要:广东网上投注站,舟山棋牌,澳门红宝石娱乐城,扎金花棋牌游戏官网

如果你没有看到java--最新SSM框架整合日记(上篇)请点击此处

扎金花棋牌游戏官网
8 . springMVC配置

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.bgel.cn/2001/XMLSchema-instance"
    xmlns="http://www.bgel.cn/xml/ns/javaee" xmlns:web="http://www.bgel.cn/xml/ns/javaee/web-app_3_0.xsd"
    xsi:schemaLocation="http://www.bgel.cn/xml/ns/javaee http://www.bgel.cn/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">
    <display-name>Archetype Created Web Application</display-name>

    <!-- 读取spring配置文件 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:conf/spring.xml;
            classpath:conf/spring-mybatis.xml
        </param-value>
    </context-param>
    <!-- 设计路径变量值 -->
    <context-param>
        <param-name>webAppRootKey</param-name>
        <param-value>SpringDemo.root</param-value>
    </context-param>

    <!-- Spring字符集过滤器 -->
    <filter>
        <filter-name>SpringEncodingFilter</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>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>SpringEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!-- 日志记录 -->
    <context-param>
        <!-- 日志配置文件路径 -->
        <param-name>log4jConfigLocation</param-name>
        <param-value>classpath:conf/log4j.properties</param-value>
    </context-param>
    <context-param>
        <!-- 日志页面的刷新间隔 -->
        <param-name>log4jRefreshInterval</param-name>
        <param-value>6000</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- springMVC核心配置 -->
    <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:conf/spring-mvc.xml</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    <!-- 错误跳转页面 -->
    <error-page>
        <!-- 路径不正确 -->
        <error-code>404</error-code>
        <location>/WEB-INF/errorpage/404.jsp</location>
    </error-page>
    <error-page>
        <!-- 没有访问权限,访问被禁止 -->
        <error-code>405</error-code>
        <location>/WEB-INF/errorpage/405.jsp</location>
    </error-page>
    <error-page>
        <!-- 内部错误 -->
        <error-code>500</error-code>
        <location>/WEB-INF/errorpage/500.jsp</location>
    </error-page>
</web-app>

conf/spring-mvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.bgel.cn/schema/beans"
  xmlns:p="http://www.bgel.cn/schema/p"
  xmlns:xsi="http://www.bgel.cn/2001/XMLSchema-instance"
  xmlns:context="http://www.bgel.cn/schema/context"
  xmlns:mvc="http://www.bgel.cn/schema/mvc"
  xsi:schemaLocation="
    http://www.bgel.cn/schema/beans
    http://www.bgel.cn/schema/beans/spring-beans-4.3.xsd
    http://www.bgel.cn/schema/context
    http://www.bgel.cn/schema/context/spring-context-4.3.xsd
    http://www.bgel.cn/schema/mvc
    http://www.bgel.cn/schema/mvc/spring-mvc-4.3.xsd">

    <!-- 扫描controller(controller层注入) -->
   <context:component-scan base-package="cn.SpringDemo.controller"/>

   <!-- 避免IE在ajax请求时,返回json出现下载 -->
   <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">  
    <property name="messageConverters">  
        <list>  
            <ref bean="jsonHttpMessageConverter" />  
        </list>  
    </property>  
</bean>  

<bean id="jsonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">  
    <property name="supportedMediaTypes">  
        <list>  
            <value>application/json;charset=UTF-8</value>  
        </list>  
    </property>  
</bean>  

   <!-- 对模型视图添加前后缀 -->
     <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
      p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"/>
</beans>
9 . log4j日志

conf/log4j.properties

### set log levels ###
#log4j.rootLogger = debug , stdout , D , E
log4j.rootLogger = debug , stdout , D

###  output to the console ###
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{ABSOLUTE} %5p %c{ 1 }:%L - %m%n
log4j.appender.stdout.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [%c]-[%p] %m%n

### Output to the log file ###
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = ${springmvc.root}/WEB-INF/logs/log.log
log4j.appender.D.Append = true
log4j.appender.D.Threshold = DEBUG 
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n

### Save exception information to separate file ###
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = ${springmvc.root}/WEB-INF/logs/error.log 
log4j.appender.D.Append = true
log4j.appender.D.Threshold = ERROR 
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
10 . 编写jsp和controller代码

WEB-INF/jsp/index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.bgel.cn/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>ssm搭建完成!!!</h1>
</body>
</html>

WEB-INF/jsp/allusers.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://www.bgel.cn/jsp/jstl/core"%>
<%@ taglib uri="http://www.bgel.cn/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
    <h1>ssm搭建完成!!!</h1>
    id-------------用户昵称
    <hr>
    <c:forEach items="${users}" var="user">
    ${user.id }-------------${user.nickname }
        <hr>
    </c:forEach>
</body>
</html>

cn.SpringDemo.controller/UserComtroller.java

package cn.SpringDemo.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 cn.SpringDemo.model.User;
import cn.SpringDemo.model.result.ResultDO;
import cn.SpringDemo.service.UserService;

/**
 * 用户Controller
 * @author yezi
 *
 */
@Controller
@RequestMapping("/")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 测试
     * @return
     */
    @RequestMapping("index")
    public String index(){
        return "index";
    }

    @RequestMapping("showAllUsers")
    public String showAllUsers(Model model) {
        ResultDO<List<User>> resultDO = userService.getAllUsers();
        model.addAttribute("users", resultDO.getResult());
        return "allUsers";
    }
}
11.发布运行

将项目部署到tomcat8.5.16中

访问路径localhost:8080/SpringDemo/index.do
图片描述
访问路径localhost:8080/SpringDemo/showAllUsers.do
图片描述


项目源码在这里,等本人稍微休息一会儿,正在抓紧时间上传完善中。。。
https://github.com/yezidrhome/SSMDemo

本人小小菜鸟,难免会有错误,希望大神们看到能够及时指出。????? ????

参考资料

http://www.bgel.cn/spring-framework/ Spring官网

http://www.bgel.cn/mybatis-3/zh/getting-started.html mybatis

点击查看更多内容

本文原创发布于慕课网 ,转载请注明出处,谢谢合作

8人点赞

若觉得本文不错,就分享一下吧!

评论

相关文章推荐

正在加载中
意见反馈 去赚学费 帮助中心 APP下载
官方微信
扎金花棋牌游戏官网

举报

0/150
提交
取消
网站地图 奥斯卡娱乐线路检测 每天娱乐app 新天棋牌官网 12bet登录
睡射手中文网无码 天时娱乐下载 利来电游app
乐虎游戏中心下载 非利滨国际ag真人视讯 888真人 永利皇官登录系统
天天娱乐注册 最新国际足球排名 易游pt手机客户端网址 亚搏娱乐APP下载
澳门美高梅乐城 妻子的秘密谢文苏蓝 葡京赌场官方app 龙8娱乐老虎机APP
大盛娱乐 稳定彩票平台 汀苏快三走势图 圣亚娱乐注册 九号彩票官网
圣亚娱乐在线 鼎尖娱乐网页 天游娱乐招商 丰尚娱乐 A彩娱乐
聚富彩票登陆 开心娱乐平台 玩家汇注册 娱乐平台注册 新生彩平台登录网址
如意娱乐开户 银豹娱乐 678彩票开奖网 聚富彩票网 汇丰在线评估