Skip to content

Commit

Permalink
添加了freemarker
Browse files Browse the repository at this point in the history
  • Loading branch information
xwj-vic committed Mar 14, 2017
1 parent 2072d06 commit 32a3f18
Show file tree
Hide file tree
Showing 15 changed files with 392 additions and 5 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@
<version>2.9.7</version>
</dependency>

<!--Freemarker-->
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.23</version>
</dependency>

</dependencies>
<build>
<finalName>ssmshiro</finalName>
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/web/AppAPI/apitest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package web.AppAPI;

import entity.User;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import service.ShiroUserService;

import java.util.HashMap;
import java.util.Map;

/**
* Created by xuweijie on 2017/3/14.
*/
@RequestMapping("/api")
@Controller
public class apitest {

@Autowired
private ShiroUserService shiroUserService;

@RequestMapping("/jsontest")
@ResponseBody
public Map<String, User> getjsopn() {
User user=shiroUserService.queryUser("许伟杰");
Map<String,User>map=new HashMap<String, User>();
map.put("user",user);
return map;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package web;
package web.WebController;

import entity.User;
import org.apache.shiro.SecurityUtils;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package web;
package web.WebController;

import entity.User;
import exception.CustomException;
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/web/WebController/ftlcontroller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package web.WebController;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
* Created by xuweijie on 2017/3/14.
*/
@Controller
public class ftlcontroller {
@RequestMapping(value="/welcome",method={RequestMethod.GET})
public ModelAndView getFirstPage(HttpServletRequest request) {
//welcom就是视图的名称(welcom.ftl)
ModelAndView mv = new ModelAndView("welcome");
mv.addObject("name", "My First Spring Mvc and Freemarker !");
return mv;
}
}
10 changes: 8 additions & 2 deletions src/main/resources/jdbc.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://139.199.10.50:3306/SSMTest?autoReconnect=true&useUnicode=true&characterEncoding=utf8
jdbc.url=jdbc:mysql://120.25.79.159:3306/SSMDB?autoReconnect=true&useUnicode=true&characterEncoding=utf8
jdbc.username=xuweijie
jdbc.password=xuweijie
jdbc.password=xuweijie

jdbc.driver.slave=com.mysql.jdbc.Driver
jdbc.url.slave=jdbc:mysql://139.199.10.50:3306/SSMDB?autoReconnect=true&useUnicode=true&characterEncoding=utf8
jdbc.username.slave=xuweijie
jdbc.password.slave=xuweijie
41 changes: 41 additions & 0 deletions src/main/resources/spring/spring-freemarker.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="freeMarkerConfigurer" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="/WEB-INF/ftl"/>
<property name="freemarkerSettings">
<props>
<!--设置标签类型,[]和<>,[]这种解析要快-->
<prop key="tag_syntax">auto_detect</prop>
<!--模板更新时间间隔-->
<prop key="template_update_delay">10</prop>
<prop key="locale">UTF-8</prop>
<prop key="default_encoding">UTF-8</prop>
<prop key="boolean_format">true,false</prop>
<prop key="datetime_format">yyyy-MM-dd HH:MM:SS</prop><!-- 时间格式化 -->
<prop key="date_format">yyyy-MM-dd</prop>
<prop key="number_format">#.##</prop>
<!--去掉多余空格-->
<prop key="whitespace_stripping">true</prop>
</props>
</property>
</bean>

<!-- freemarker视图解析器 -->
<bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="order" value="1"/>
<property name="suffix" value=".ftl" />
<property name="contentType" value="text/html;charset=UTF-8" />
<property name="viewClass" value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" />
<property name="allowSessionOverride" value="true" />
<property name="allowRequestOverride" value="true" />
<property name="exposeSpringMacroHelpers" value="false" />
<property name="exposeRequestAttributes" value="true" />
<property name="exposeSessionAttributes" value="true" />
<!-- 此变量值为pageContext.request, 页面使用方法:request.contextPath -->
<property name="requestContextAttribute" value="request" />
</bean>

</beans>
1 change: 1 addition & 0 deletions src/main/resources/spring/spring-web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

<!--3:配置JSP 显示ViewResolver-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="order" value="2"/>
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
Expand Down
11 changes: 11 additions & 0 deletions src/main/webapp/WEB-INF/ftl/welcome.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>freemarker页面</title>
</head>
<body>
Hello ${name}

</body>
</html>
16 changes: 15 additions & 1 deletion src/main/webapp/WEB-INF/jsp/errorpage/404.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,22 @@
<html>
<head>
<title>404</title>
<link rel="stylesheet" type="text/css" href="/styles/errorpagestyle.css">
<script type="text/javascript" src="/resources/jquery-3.1.1/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="/resources/jquery-3.1.1/jquery.particleground.min.js"></script>
<script type="text/javascript" src="/js/errorpagejs.js"></script>
</head>
<body>
<h1>这是404啦</h1>
<div id="particles">

<div class="intro">

<h1>404</h1>

<p>不好意思哦!页面好像不见了</p>

</div>

</div>
</body>
</html>
30 changes: 30 additions & 0 deletions src/main/webapp/WEB-INF/jsp/errorpage/405.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<%--
Created by IntelliJ IDEA.
User: xuweijie
Date: 2017/3/11
Time: 16:47
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>404</title>
<link rel="stylesheet" type="text/css" href="/styles/errorpagestyle.css">
<script type="text/javascript" src="/resources/jquery-3.1.1/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="/resources/jquery-3.1.1/jquery.particleground.min.js"></script>
<script type="text/javascript" src="/js/errorpagejs.js"></script>
</head>
<body>
<div id="particles">

<div class="intro">

<h1>405</h1>

<p>不好意思哦!出错了呢</p>

</div>

</div>
</body>
</html>
4 changes: 4 additions & 0 deletions src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<error-code>404</error-code>
<location>/WEB-INF/jsp/errorpage/404.jsp</location>
</error-page>
<error-page>
<error-code>405</error-code>
<location>/WEB-INF/jsp/errorpage/405.jsp</location>
</error-page>

<!--配置DispatcherServlet-->
<servlet>
Expand Down
14 changes: 14 additions & 0 deletions src/main/webapp/js/errorpagejs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Particleground demo
* @author Jonathan Nicol - @mrjnicol
*/

$(document).ready(function() {
$('#particles').particleground({
dotColor: '#5cbdaa',
lineColor: '#5cbdaa'
});
$('.intro').css({
'margin-top': -($('.intro').height() / 2)
});
});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 32a3f18

Please sign in to comment.