SpringMVC,Mybatis,FreeMarker连接mycat示例(五)

真的梦想,不是非得高大上或者文艺范儿,它就是对更好生活的美好期望,像人在黑夜里抬头望星空一样质朴,像花儿向着太阳一样生生不息。

WEB-INF/views/test/add.ftl内容:


<html lang="en">
<head>
    <meta charset="utf-8"/>
    <title>新增信息title>
head>
<body>
<form id="addForm" method="post" action="${request.contextPath}/test/add">
    <table border="1" bordercolor="#cccccc" cellpadding="0" cellspacing="0">
        <tr>
            <td colspan="4" bgcolor="#1d98db"><font size="3">新增信息font>td>
        tr>
        <tr>
            <td>姓名:td>
            <td>
                <input type="text" name="name">
            td>
        tr>
        <tr>
            <td>用户ID:td>
            <td>
                <input type="text" name="userId">
            td>
        tr>
    table>
    <p>
        <button type="submit">保存button>  
        <button onclick="history.go(-1);return false;">返回button>
    p>
form>
body>
html>

WEB-INF/views/test/edit.ftl内容:


<html lang="en">
<head>
    <meta charset="utf-8"/>
    <title>修改信息title>
head>
<body>
<form id="editForm" method="post" action="${request.contextPath}/test/edit">
    <table border="1" bordercolor="#cccccc" cellpadding="0" cellspacing="0">
        <tr>
            <td colspan="4" bgcolor="#1d98db"><font size="3">修改信息font>td>
        tr>

        <tr>
            <td>姓名:td>
            <td>
                <input type="hidden" name="id" value="${test.id}">
                <input type="text" name="name" value="${employee.name}">
            td>
        tr>
        <tr>
            <td>用户ID:td>
            <td>
                <input type="text" name="userId" value="${test.userId}">
            td>
        tr>
    table>
    <p>
        <button type="submit">保存button>  
        <button onclick="history.go(-1);return false;">返回button>
    p>
form>
body>
html>

WEB-INF/views/test/list.ftl内容:


<html lang="en">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>列表title>
head>
<body>
<#if tests?size gt 0>
    <table border="0" bordercolor="#cccccc" cellpadding="0" cellspacing="0">
        <tr>
            <th class="al_list1">编号th>
            <th class="al_list3">名称th>
            <th class="al_list1">用户IDth>
            <th class="al_list3">操作th>
        tr>
        <#list tests as obj>
        <tr>
            <td class="al_list1">
                ${obj.id}
            td>
            <td class="al_list3">${obj.name}td>
            <td class="al_list1">${obj.userId}td>
            <td class="al_list3">
                <a href="${request.contextPath}/test/toEdit?id=${obj.id}">修改atd>
        tr>
        #list>
    table>
#if>
body>
html>

WEB-INF/views/index.ftl内容:


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>indextitle>
head>
<body>
<a href="/test/">查看数据列表a>
body>
html>

WEB-INF/web.xml内容:



<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:web="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
    listener> 
    
    <context-param>
        <param-name>contextConfigLocationparam-name>
        <param-value>classpath:spring-config.xmlparam-value>
    context-param>

    
    <servlet>
        <servlet-name>springmvcservlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
        
        <init-param>
            <param-name>contextConfigLocationparam-name>
            <param-value>classpath:spring-config-mvc.xmlparam-value>
        init-param>

        
        <load-on-startup>1load-on-startup>
    servlet>

    
    <filter>
        <filter-name>hiddenHttpMethodFilterfilter-name>
        <filter-class>org.springframework.web.filter.HiddenHttpMethodFilterfilter-class>
    filter>

    
    <filter>
        <filter-name>encodingFilterfilter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
        <init-param>
            <param-name>encodingparam-name>
            <param-value>UTF-8param-value>
        init-param>
    filter>

    <servlet-mapping>
        <servlet-name>springmvcservlet-name>
        
        <url-pattern>/url-pattern>
    servlet-mapping>
    <filter-mapping>
        <filter-name>encodingFilterfilter-name>
        <servlet-name>springmvcservlet-name>
    filter-mapping>
    <filter-mapping>
        <filter-name>hiddenHttpMethodFilterfilter-name>
        <servlet-name>springmvcservlet-name>
    filter-mapping>
web-app>

webapp/index.jsp内容:

<html>
<body>
<h2>Hello World!h2>
body>
html>

未完待续

你可能感兴趣的:(JAVA,Tomcat服务器,Mycat中间件)