Skip to content

Commit 7659a01

Browse files
committed
Merge branch 'develop'
2 parents 5fdf71f + 170aac0 commit 7659a01

File tree

6 files changed

+148
-13
lines changed

6 files changed

+148
-13
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package cn.com.ttblog.ssmbootstrap_table.aop;
2+
3+
import org.apache.commons.lang3.builder.ToStringBuilder;
4+
import org.aspectj.lang.JoinPoint;
5+
import org.aspectj.lang.ProceedingJoinPoint;
6+
import org.aspectj.lang.annotation.After;
7+
import org.aspectj.lang.annotation.AfterReturning;
8+
import org.aspectj.lang.annotation.AfterThrowing;
9+
import org.aspectj.lang.annotation.Around;
10+
import org.aspectj.lang.annotation.Aspect;
11+
import org.aspectj.lang.annotation.Before;
12+
import org.aspectj.lang.annotation.Pointcut;
13+
import org.slf4j.Logger;
14+
import org.slf4j.LoggerFactory;
15+
import org.springframework.stereotype.Component;
16+
17+
@Component
18+
@Aspect
19+
public class ControllerAspect {
20+
21+
private static final Logger LOG = LoggerFactory
22+
.getLogger(ControllerAspect.class);
23+
24+
@Pointcut("execution(* cn.com.ttblog.ssmbootstrap_table.controller..*.*(..))")
25+
public void pointCut() {
26+
}
27+
28+
@After("pointCut()")
29+
public void after(JoinPoint joinPoint) {
30+
}
31+
32+
@Before("pointCut()")
33+
public void before(JoinPoint joinPoint) {
34+
// Object[] args = joinPoint.getArgs();
35+
LOG.warn("控制器切面参数 param:{}",
36+
ToStringBuilder.reflectionToString(joinPoint));
37+
Object[] arr = joinPoint.getArgs();
38+
if (arr.length > 0) {
39+
LOG.warn("method param:{}",
40+
ToStringBuilder.reflectionToString(joinPoint.getArgs()[0]));
41+
}
42+
}
43+
44+
@AfterReturning(pointcut = "pointCut()", returning = "returnVal")
45+
public void afterReturning(JoinPoint joinPoint, Object returnVal) {
46+
}
47+
48+
@Around("pointCut()")
49+
public Object around(ProceedingJoinPoint pjp) throws Throwable {
50+
Object obj = null;
51+
long startTime = System.nanoTime();
52+
long endTime;
53+
try {
54+
obj = pjp.proceed();
55+
endTime = System.nanoTime();
56+
} catch (Throwable ex) {
57+
throw ex;
58+
}
59+
LOG.warn(pjp.getSignature() + "-time consume is "
60+
+ (endTime - startTime) / 1000 / 1000 / 1000 * 0.1 + "s");
61+
return obj;
62+
}
63+
64+
@AfterThrowing(pointcut = "pointCut()", throwing = "error")
65+
public void afterThrowing(JoinPoint jp, Throwable error) {
66+
LOG.error("控制器发生错误:" + error);
67+
}
68+
}

src/main/java/cn/com/ttblog/ssmbootstrap_table/controller/JsonpController.java

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
import javax.servlet.http.HttpSession;
1212

1313
import org.apache.commons.lang3.builder.ToStringBuilder;
14+
import org.eclipse.jetty.util.log.Log;
1415
import org.slf4j.Logger;
1516
import org.slf4j.LoggerFactory;
1617
import org.springframework.stereotype.Controller;
1718
import org.springframework.ui.Model;
1819
import org.springframework.web.bind.annotation.ModelAttribute;
1920
import org.springframework.web.bind.annotation.PathVariable;
21+
import org.springframework.web.bind.annotation.RequestBody;
2022
import org.springframework.web.bind.annotation.RequestMapping;
2123
import org.springframework.web.bind.annotation.RequestMethod;
2224
import org.springframework.web.bind.annotation.RequestParam;
@@ -176,10 +178,19 @@ public User t(@PathVariable Long id, HttpServletRequest request,
176178

177179
/**
178180
* http://localhost:8080/ssmbootstrap_table/jsonp/testarr?v[]=1&v[]=2&v[]=3
179-
* var arr=["a","b","c"]; 前端jquery发送数组,需要traditional置为 true $.ajax({
180-
* url:"http://localhost:8080/ssmbootstrap_table/jsonp/testarr",
181-
* data:{"v":arr}, type:"post", traditional: true, success:function(data){
182-
* console.log(data); }, error:function(xhr){ console.log(xhr); } });
181+
* var arr=["a","b","c"]; 前端jquery发送数组,需要traditional置为 true
182+
* $.ajax({
183+
* url:"http://localhost:8080/ssmbootstrap_table/jsonp/testarr",
184+
* data:{"v":arr},
185+
* type:"post",
186+
* traditional: true,
187+
* success:function(data){
188+
* console.log(data);
189+
* },
190+
* error:function(xhr){
191+
* console.log(xhr);
192+
* }
193+
* });
183194
*
184195
* @param values
185196
* @return
@@ -190,7 +201,57 @@ public User t(@PathVariable Long id, HttpServletRequest request,
190201
logger.debug("接收到的数组参数:{}", Arrays.deepToString(values));
191202
return values;
192203
}
204+
205+
/**
206+
var d={"id":1,name:"test"};
207+
$.ajax({
208+
url:"http://localhost:8080/ssmbootstrap_table/jsonp/receivejson",
209+
data:{"json":JSON.stringify(d)},
210+
type:"post",
211+
ContentType: "application/json;charset=UTF-8",
212+
success:function(data){
213+
console.log(data);
214+
},
215+
error:function(xhr){
216+
console.log(xhr);
217+
}
218+
});
219+
get to http://localhost:8080/ssmbootstrap_table/jsonp/receivejson?json={%22id%22:1,name:%22test%22}
220+
*
221+
* @param values
222+
* @return
223+
*/
224+
@RequestMapping("/receivejson")
225+
public @ResponseBody Object receivejson(@RequestParam(value="json") String json) {
226+
logger.debug("receive json str:{}",json);
227+
JSONObject j=(JSONObject) JSONObject.parse(json);
228+
logger.debug("receive json to jsonobject:{}",j);
229+
return j;
230+
}
193231

232+
/**
233+
$.ajax({
234+
url:"http://localhost:8080/ssmbootstrap_table/jsonp/receivejsonobj",
235+
type:"post",
236+
contentType:'application/json;charset=UTF-8',
237+
data: "{id:1,name:\"test\"}",
238+
success:function(data){
239+
console.log(data);
240+
},
241+
error:function(xhr){
242+
console.log(xhr);
243+
}
244+
});
245+
*
246+
* @param values
247+
* @return
248+
*/
249+
@RequestMapping("/receivejsonobj")
250+
public @ResponseBody User receivejsonobj(@RequestBody User user) {
251+
logger.debug("receive json obj:{}",user);
252+
return user;
253+
}
254+
194255
/**
195256
* 获取session中name的值
196257
*

src/main/java/cn/com/ttblog/ssmbootstrap_table/model/Address.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import org.apache.commons.lang3.builder.ToStringBuilder;
44

5-
public class Address {
5+
import java.io.Serializable;
6+
7+
public class Address implements Serializable{
68

79
private Long userId;
810

src/main/java/cn/com/ttblog/ssmbootstrap_table/util/LongToDateTag.tld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<tag>
66
<name>l2d</name>
77
<description>convert long to date</description>
8-
<tag-class>cn.com.ttblog.jfinal_bootstrap_table.util.LongToDateTag
8+
<tag-class>cn.com.ttblog.ssmbootstrap_table.util.LongToDateTag
99
</tag-class>
1010
<body-content>empty</body-content>
1111
<attribute>

src/main/resources/spring/spring-context.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc"
66
xmlns:tx="http://www.springframework.org/schema/tx"
77
xsi:schemaLocation="http://www.springframework.org/schema/beans
8-
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
8+
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
99
http://www.springframework.org/schema/context
10-
http://www.springframework.org/schema/context/spring-context-3.2.xsd
10+
http://www.springframework.org/schema/context/spring-context-4.0.xsd
1111
http://www.springframework.org/schema/mvc
12-
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
13-
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
14-
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
12+
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
13+
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
14+
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
1515

1616
<context:component-scan base-package="cn.com.ttblog.ssmbootstrap_table">
1717
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
@@ -35,7 +35,7 @@
3535
</bean>
3636

3737
<!-- 启用aop -->
38-
<aop:aspectj-autoproxy />
38+
<aop:aspectj-autoproxy/>
3939

4040
<!-- 加载资源文件 -->
4141
<import resource="spring-mybatis.xml" />

src/main/resources/spring/spring-mvc.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
<beans xmlns="http://www.springframework.org/schema/beans"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
44
xmlns:context="http://www.springframework.org/schema/context"
5+
xmlns:aop="http://www.springframework.org/schema/aop"
56
xmlns:mvc="http://www.springframework.org/schema/mvc"
67
xsi:schemaLocation="http://www.springframework.org/schema/beans
78
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
89
http://www.springframework.org/schema/context
9-
http://www.springframework.org/schema/context/spring-context-4.0.xsd
10+
http://www.springframework.org/schema/context/spring-context-4.0.xsd
11+
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
1012
http://www.springframework.org/schema/mvc
1113
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
1214
<!-- 自动扫描该包,使SpringMVC认为包下用了@controller注解的类是控制器 -->
@@ -193,6 +195,8 @@
193195
<property name="paramName" value="lang"/>
194196
</bean>
195197

198+
<aop:aspectj-autoproxy proxy-target-class="true"/>
199+
196200
<mvc:interceptors>
197201
<!-- 国际化拦截器 -->
198202
<!-- <ref bean="localeChangeInterceptor"/> -->

0 commit comments

Comments
 (0)