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

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

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

<!DOCTYPE html>
<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>&nbsp;&nbsp;
        <button onclick="history.go(-1);return false;">返回</button>
    </p>
</form>
</body>
</html>

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

<!DOCTYPE html>
<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>&nbsp;&nbsp;
        <button onclick="history.go(-1);return false;">返回</button>
    </p>
</form>
</body>
</html>

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

<!DOCTYPE html>
<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">用户ID</th>
            <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}">修改</a>&nbsp;
            </td>
        </tr>
        </#list>
    </table>
</#if>
</body>
</html>

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>index</title>
</head>
<body>
<a href="/test/">查看数据列表</a>
</body>
</html>

WEB-INF/web.xml内容:

<?xml version="1.0" encoding="UTF-8"?>

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

    <!-- spring容器监听器 -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener> 
    <!-- 加载spring容器 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring-config.xml</param-value>
    </context-param>

    <!-- 配置前端控制器(总的控制器中心) -->
    <servlet>
        <servlet-name>springmvc</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <!--加载前端控制器配置文件 上下文配置位置 -->
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring-config-mvc.xml</param-value>
        </init-param>

        <!-- 随服务器启动 -->
        <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- 支持Restful风格的请求Url -->
    <filter>
        <filter-name>hiddenHttpMethodFilter</filter-name>
        <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
    </filter>

    <!-- 过滤中文乱码 -->
    <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>

    <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <!-- restful风格url -->
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <servlet-name>springmvc</servlet-name>
    </filter-mapping>
    <filter-mapping>
        <filter-name>hiddenHttpMethodFilter</filter-name>
        <servlet-name>springmvc</servlet-name>
    </filter-mapping>
</web-app>

webapp/index.jsp内容:

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

未完待续

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值