前些天發現了一個巨牛的人工智能學習網站,通俗易懂,風趣幽默,忍不住分享一下給大家。點擊跳轉到教程。
?
整體環境參見本人另一文:http://blog.csdn.net/jiangyu1013/article/details/51983360
此工程訪問入口為index.jsp頁面.
工程結構:
?
?
?
?
?
1. ? jap 頁面:
?
index.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>去確定頁面</title>
</head>
<body><a href="javascript:<jsp:forward page='WEB-INF/views/sure.jsp'/>"></a>
</body>
</html>
?
?
?
?
?
sure.jsp ?:
?
<%@ 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+"/";%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>確定頁面</title>
<script type="text/javascript" src="js/jquery-1.12.0.min.js"></script>
<script type="text/javascript" src="js/jquery.watermark.min.js"></script>
<script language="javascript">function doSubmit(){$.ajax({url:"<%=basePath%>sure/to",type:"post",data:$("#formMark").serialize(),success:function(data){if(data){window.location.href="<%=basePath%>sure/to";}else{alert(data);}},error:function(){alert("有異常!");}});
}
</script>
</head>
<body>
<div><div><span>確定頁面</span></div><form id="formMark"><table><tr><td width="15%">你想知道book表有多少條數據嗎?</td></tr></table><div><input type="button" style="margin-left:15px;" value="想" onclick="doSubmit()"/></div></form>
</div>
</body>
</html>
?
?
?
?
?
result.jsp ?:
?
?
<%@ 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+"/";%> --%>
<%-- <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> --%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>結果頁面</title>
</head>
<body>
<div><div ><span>結果頁面</span></div><table ><tr><td>book表數據總條數為:${count} 條。</td></tr></table>
</div>
</body>
</html>
?
?
?
?
?
stillResult.jsp ?:
?
?
<%@ 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+"/";%><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>結果頁面</title>
<base href="<%=basePath%>">
</head>
<body>
<div><div ><span>結果頁面</span></div><table ><tr><td>這是still頁面。</td></tr></table>
</div><pre name="code" class="html">
</body></html>
?
?
2.代碼部分:
?
SureController.java ??
?
?
package com.controller;import javax.annotation.Resource;import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;import com.service.SureServiceImpl;@Controller
@RequestMapping("/sure")
public class SureController {@Resourceprivate SureServiceImpl sureService;@RequestMapping("/to")public String getCount(ModelMap model) throws Exception {int count = sureService.getCount();model.addAttribute("count",count);return "result";}@RequestMapping(value="/still")public String still(ModelMap model) throws Exception {return "stillResult";}
}
?
?
?
?
?
ISureService.java
?
?
?
package com.service;public interface ISureService {public int getCount();
}
?
?
?
?
?
?
SureServiceImpl.java
?
?
package com.service;import javax.annotation.Resource;import org.springframework.stereotype.Service;import com.mapper.SureMapper;@Service("sureService")
public class SureServiceImpl implements ISureService {@Resourceprivate SureMapper sureMapper;public int getCount() { return sureMapper.getTheCount();}}
?
?
?
?
?
SureMapper.java
?
?
package com.mapper;public interface SureMapper {public int getTheCount();}
?
?
?
?
?
SureMapper.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.mapper.SureMapper" ><select id="getTheCount" resultType="java.lang.Integer">select count(1) from BOOK</select></mapper>
?
?
?
?
?
?
?
?
?
?
?