- 浏览: 2551737 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
mongodb(2)Setup the Velocity Jquery Groovy Service AOP
1. Velocity with Jquery
Because I use velocity here, so I need to install the latest velocity plugin for eclipse 3.7 is
http://veloeclipse.googlecode.com/svn/trunk/update/
It is said that there is conflict when using jquery and velocity together. But I do not see any issues here.
my pom.xml is as follow to see the version:
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-tools</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>2.0.0-beta-3</version>
</dependency>
One problem to get the content path from velocity file, I solve this problem with velocity tool.
<bean id="velocityViewResolver"
class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
<property name="layoutUrl" value="layout/layout.vm" />
<property name="cache" value="false" />
<property name="suffix" value=".vm" />
<property name="exposeSpringMacroHelpers" value="true" />
<property name="contentType" value="text/html;charset=UTF-8" />
<property name="toolboxConfigLocation" value="/WEB-INF/toolbox.xml"/>
</bean>
The toolbox.xml will be configurated as follow under WEB-INF, I just install one of all the tools:
<toolbox>
<tool>
<key>link</key>
<scope>request</scope>
<class>org.apache.velocity.tools.view.tools.LinkTool</class>
</tool>
</toolbox>
Velocity page will import the resources as follow:
<link rel="stylesheet" type="text/css" media="screen" href="${link.getContextPath()}/resources/css/style.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="${link.getContextPath()}/resources/js/custom.js"></script>
2. Groovy Controller and Request with JSON response
my UserController.groovy
package com.sillycat.easynosql.web;
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.HttpStatus
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus
import com.sillycat.easynosql.model.Role
import com.sillycat.easynosql.model.User
import com.sillycat.easynosql.model.dto.UserListDTO
import com.sillycat.easynosql.service.UserService
@Controller
@RequestMapping("/users")
class UserController {
@Autowired
UserService userService
@RequestMapping(value="/records")
@ResponseStatus(HttpStatus.OK)
public @ResponseBody UserListDTO getUsers() {
UserListDTO userListDTO = new UserListDTO();
userListDTO.setUsers(userService.readAll());
return userListDTO;
}
@RequestMapping(value="/get")
@ResponseStatus(HttpStatus.OK)
public @ResponseBody User get(@RequestBody User user) {
return userService.read(user);
}
@RequestMapping(value="/create", method=RequestMethod.POST)
public @ResponseBody User create(
@RequestParam("username") String username,
@RequestParam("password") String password,
@RequestParam("firstName") String firstName,
@RequestParam("lastName") String lastName,
@RequestParam("role") Integer role) {
Role newRole = new Role();
newRole.setRole(role);
User newUser = new User();
newUser.setUsername(username);
newUser.setPassword(password);
newUser.setFirstName(firstName);
newUser.setLastName(lastName);
newUser.setRole(newRole);
return userService.create(newUser);
}
@RequestMapping(value="/update", method=RequestMethod.POST)
public @ResponseBody User update(
@RequestParam("userName") String userName,
@RequestParam("firstName") String firstName,
@RequestParam("lastName") String lastName,
@RequestParam("role") Integer role) {
Role existingRole = new Role();
existingRole.setRole(role);
User existingUser = new User();
existingUser.setUsername(userName);
existingUser.setFirstName(firstName);
existingUser.setLastName(lastName);
existingUser.setRole(existingRole);
return userService.update(existingUser);
}
@RequestMapping(value="/delete", method=RequestMethod.POST)
public @ResponseBody Boolean delete(
@RequestParam("username") String username) {
User existingUser = new User();
existingUser.setUsername(username);
return userService.delete(existingUser);
}
}
The request URLs will be as follow:
urlHolder.records = "${link.getContextPath()}/users/records";
urlHolder.add = "${link.getContextPath()}/users/create";
urlHolder.edit = "${link.getContextPath()}/users/update";
urlHolder.del = "${link.getContextPath()}/users/delete";
3. AOP Configuration
AOP Log class is as follow:
package com.sillycat.easynosql.aop.log;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.log4j.Logger;
import org.springframework.aop.interceptor.CustomizableTraceInterceptor;
public class TraceInterceptor extends CustomizableTraceInterceptor {
private static final long serialVersionUID = 287162721460370957L;
protected static Logger logger4J = Logger.getLogger("aop");
@Override
protected void writeToLog(Log logger, String message, Throwable ex) {
if (ex != null) {
logger4J.debug(message, ex);
} else {
logger4J.debug(message);
}
}
@Override
protected boolean isInterceptorEnabled(MethodInvocation invocation, Log logger) {
return true;
}
}
AOP configuration for spring xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">
<!-- For parsing classes with @Aspect annotation -->
<aop:aspectj-autoproxy/>
<bean id="customizableTraceInterceptor" class="com.sillycat.easynosql.aop.log.TraceInterceptor"
p:enterMessage="Entering $[targetClassShortName].$[methodName]($[arguments])"
p:exitMessage="Leaving $[targetClassShortName].$[methodName](): $[returnValue]"/>
<aop:config>
<aop:advisor advice-ref="customizableTraceInterceptor" pointcut="execution(public * com.sillycat.easynosql.service..*(..))"/>
</aop:config>
</beans>
log4j.properties configuration:
log4j.rootLogger=ERROR,console
#Console Appender
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=[%5p] [%t %d{hh:mm:ss}] (%F:%M:%L) %m%n
log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.File=log/easynosql.log
log4j.appender.R.DatePattern = '.'yyyy-MM-dd
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d{MM-dd HH:mm:ss} [%p] %l - %m%n
log4j.logger.aop=DEBUG,console
log4j.additivity.aop=false
references:
http://krams915.blogspot.com/2012/01/spring-mvc-31-implement-crud-with_7897.html
http://krams915.blogspot.com/2012/01/spring-mvc-31-implement-crud-with_3288.html
http://krams915.blogspot.com/2012/01/spring-mvc-31-implement-crud-with_20.html
http://krams915.blogspot.com/2012/01/spring-mvc-31-implement-crud-with.html
http://www.springsource.org/spring-data
http://www.springsource.org/spring-data/mongodb
http://static.springsource.org/spring-data/data-mongodb/docs/current/reference/html/
http://code.jquery.com/jquery-1.7.2.min.js
1. Velocity with Jquery
Because I use velocity here, so I need to install the latest velocity plugin for eclipse 3.7 is
http://veloeclipse.googlecode.com/svn/trunk/update/
It is said that there is conflict when using jquery and velocity together. But I do not see any issues here.
my pom.xml is as follow to see the version:
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-tools</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>2.0.0-beta-3</version>
</dependency>
One problem to get the content path from velocity file, I solve this problem with velocity tool.
<bean id="velocityViewResolver"
class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
<property name="layoutUrl" value="layout/layout.vm" />
<property name="cache" value="false" />
<property name="suffix" value=".vm" />
<property name="exposeSpringMacroHelpers" value="true" />
<property name="contentType" value="text/html;charset=UTF-8" />
<property name="toolboxConfigLocation" value="/WEB-INF/toolbox.xml"/>
</bean>
The toolbox.xml will be configurated as follow under WEB-INF, I just install one of all the tools:
<toolbox>
<tool>
<key>link</key>
<scope>request</scope>
<class>org.apache.velocity.tools.view.tools.LinkTool</class>
</tool>
</toolbox>
Velocity page will import the resources as follow:
<link rel="stylesheet" type="text/css" media="screen" href="${link.getContextPath()}/resources/css/style.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="${link.getContextPath()}/resources/js/custom.js"></script>
2. Groovy Controller and Request with JSON response
my UserController.groovy
package com.sillycat.easynosql.web;
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.HttpStatus
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus
import com.sillycat.easynosql.model.Role
import com.sillycat.easynosql.model.User
import com.sillycat.easynosql.model.dto.UserListDTO
import com.sillycat.easynosql.service.UserService
@Controller
@RequestMapping("/users")
class UserController {
@Autowired
UserService userService
@RequestMapping(value="/records")
@ResponseStatus(HttpStatus.OK)
public @ResponseBody UserListDTO getUsers() {
UserListDTO userListDTO = new UserListDTO();
userListDTO.setUsers(userService.readAll());
return userListDTO;
}
@RequestMapping(value="/get")
@ResponseStatus(HttpStatus.OK)
public @ResponseBody User get(@RequestBody User user) {
return userService.read(user);
}
@RequestMapping(value="/create", method=RequestMethod.POST)
public @ResponseBody User create(
@RequestParam("username") String username,
@RequestParam("password") String password,
@RequestParam("firstName") String firstName,
@RequestParam("lastName") String lastName,
@RequestParam("role") Integer role) {
Role newRole = new Role();
newRole.setRole(role);
User newUser = new User();
newUser.setUsername(username);
newUser.setPassword(password);
newUser.setFirstName(firstName);
newUser.setLastName(lastName);
newUser.setRole(newRole);
return userService.create(newUser);
}
@RequestMapping(value="/update", method=RequestMethod.POST)
public @ResponseBody User update(
@RequestParam("userName") String userName,
@RequestParam("firstName") String firstName,
@RequestParam("lastName") String lastName,
@RequestParam("role") Integer role) {
Role existingRole = new Role();
existingRole.setRole(role);
User existingUser = new User();
existingUser.setUsername(userName);
existingUser.setFirstName(firstName);
existingUser.setLastName(lastName);
existingUser.setRole(existingRole);
return userService.update(existingUser);
}
@RequestMapping(value="/delete", method=RequestMethod.POST)
public @ResponseBody Boolean delete(
@RequestParam("username") String username) {
User existingUser = new User();
existingUser.setUsername(username);
return userService.delete(existingUser);
}
}
The request URLs will be as follow:
urlHolder.records = "${link.getContextPath()}/users/records";
urlHolder.add = "${link.getContextPath()}/users/create";
urlHolder.edit = "${link.getContextPath()}/users/update";
urlHolder.del = "${link.getContextPath()}/users/delete";
3. AOP Configuration
AOP Log class is as follow:
package com.sillycat.easynosql.aop.log;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.log4j.Logger;
import org.springframework.aop.interceptor.CustomizableTraceInterceptor;
public class TraceInterceptor extends CustomizableTraceInterceptor {
private static final long serialVersionUID = 287162721460370957L;
protected static Logger logger4J = Logger.getLogger("aop");
@Override
protected void writeToLog(Log logger, String message, Throwable ex) {
if (ex != null) {
logger4J.debug(message, ex);
} else {
logger4J.debug(message);
}
}
@Override
protected boolean isInterceptorEnabled(MethodInvocation invocation, Log logger) {
return true;
}
}
AOP configuration for spring xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">
<!-- For parsing classes with @Aspect annotation -->
<aop:aspectj-autoproxy/>
<bean id="customizableTraceInterceptor" class="com.sillycat.easynosql.aop.log.TraceInterceptor"
p:enterMessage="Entering $[targetClassShortName].$[methodName]($[arguments])"
p:exitMessage="Leaving $[targetClassShortName].$[methodName](): $[returnValue]"/>
<aop:config>
<aop:advisor advice-ref="customizableTraceInterceptor" pointcut="execution(public * com.sillycat.easynosql.service..*(..))"/>
</aop:config>
</beans>
log4j.properties configuration:
log4j.rootLogger=ERROR,console
#Console Appender
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=[%5p] [%t %d{hh:mm:ss}] (%F:%M:%L) %m%n
log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.File=log/easynosql.log
log4j.appender.R.DatePattern = '.'yyyy-MM-dd
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d{MM-dd HH:mm:ss} [%p] %l - %m%n
log4j.logger.aop=DEBUG,console
log4j.additivity.aop=false
references:
http://krams915.blogspot.com/2012/01/spring-mvc-31-implement-crud-with_7897.html
http://krams915.blogspot.com/2012/01/spring-mvc-31-implement-crud-with_3288.html
http://krams915.blogspot.com/2012/01/spring-mvc-31-implement-crud-with_20.html
http://krams915.blogspot.com/2012/01/spring-mvc-31-implement-crud-with.html
http://www.springsource.org/spring-data
http://www.springsource.org/spring-data/mongodb
http://static.springsource.org/spring-data/data-mongodb/docs/current/reference/html/
http://code.jquery.com/jquery-1.7.2.min.js
发表评论
-
Stop Update Here
2020-04-28 09:00 316I will stop update here, and mo ... -
NodeJS12 and Zlib
2020-04-01 07:44 475NodeJS12 and Zlib It works as ... -
Docker Swarm 2020(2)Docker Swarm and Portainer
2020-03-31 23:18 368Docker Swarm 2020(2)Docker Swar ... -
Docker Swarm 2020(1)Simply Install and Use Swarm
2020-03-31 07:58 369Docker Swarm 2020(1)Simply Inst ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 336Traefik 2020(1)Introduction and ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 431Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 436Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 374Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 455VPN Server 2020(2)Docker on Cen ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 385Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 478NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 423Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 337Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 247GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 451GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 328GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 314Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 318Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 294Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(1)Running with Component
2020-02-19 01:17 312Serverless with NodeJS and Tenc ...
相关推荐
标题中的“nodejs+express+mongodb+bootstrap+jquery+ejs写的电影demo”表明这是一个使用Node.js、Express框架、MongoDB数据库、Bootstrap前端框架、jQuery库以及EJS模板引擎开发的电影相关的应用程序示例。...
总结来说,这些笔记涵盖了从客户端应用程序开发(Delphi)、数据库管理(MongoDB)、安装部署(InnoSetup)到数据管理(SQL)的广泛知识,对于希望全面理解软件开发流程的开发者来说是非常宝贵的资源。通过深入学习...
2. **MongoDB**: MongoDB是一个NoSQL数据库,适合处理大量非结构化和半结构化数据。在风控系统中,可能需要存储用户行为、交易记录等多种异构数据,MongoDB的灵活性和高扩展性使其成为理想选择。 3. **Groovy**:...
groovy配置MongoDB所需jar包 1.gmongo-1.5.jar 2.mongo-java-driver-3.4.0-rc1.jar 3.mongodb-driver-3.4.0-rc1.jar
MongoDB: The Definitive Guide MongoDB is a powerful, flexible, and scalable generalpurpose database. It combines the ability to scale out with features such as secondary indexes, range queries, ...
MongoDB: The Definitive Guide by Kristina Chodorow and Michael Dirolf Copyright © 2010 Kristina Chodorow and Michael Dirolf. All rights reserved.
本篇将详细介绍MongoDB在Linux上的配置文件,日志配置以及服务(service)配置。 1. MongoDB配置文件: MongoDB的主要配置文件名为`mongod.conf`,通常位于 `/etc/mongodb/` 或 `/etc/mongod.conf` 目录下。这个文件...
mongodb 2
在IT行业中,SpringMVC、MongoDB和jQuery是三个非常重要的技术组件,分别在Web开发的后端、数据库管理和前端交互方面发挥着关键作用。在这个项目中,"springmvc mongodb jquery 实现用户操作",我们将深入探讨如何...
2. 创建GroovyClassLoader:使用这个类加载器可以动态加载和执行Groovy脚本。它继承自Java的ClassLoader,能解析Groovy源码并生成字节码。 3. 加载并执行Groovy脚本:通过GroovyClassLoader的`parseClass()`方法...
### 《The Little MongoDB Book》知识点总结 #### 1. 关于版权与许可 - **许可类型**:本书采用Creative Commons Attribution-NonCommercial 3.0 Unported license(简称CC BY-NC 3.0)许可协议发布。 - **使用权限...
MongoDB是一种流行的开源文档型数据库,它以其灵活性、可扩展性和高性能在现代数据存储解决方案中占据了一席之地。《MongoDB权威指南》是学习和掌握MongoDB的重要参考资料,该书涵盖了MongoDB的基础知识到高级应用,...
gmongo, mongodb驱动程序的Groovy包装器 GMongo 这个项目的目的是提供一个更加简单。易于使用和更少的冗长的API,使用Groovy编程语言来处理 mongodb 。在这里可以找到更多信息: ...
2. **MongoDB**:MongoDB是一个NoSQL数据库,它支持灵活的数据模型,对于频繁变化的数据结构,如电影和音乐信息,MongoDB提供了很好的适应性。在这个项目中,MongoDB可能会存储电影和音乐的元数据,如标题、导演、...
使用jQuery和Bootsrap完成网站前端JS脚本和样式处理; 前后端的数据请求交互通过Ajax完成; 引入了Moment.js格式化前端页面显示时间; 2、项目后端搭建: 使用NodeJs的express框架完成电影网站后端搭建; 使用mongodb...
In the last 10 years, the Internet has challenged relational databases in ways nobody could have foreseen. Having used MySQL at large and growing Internet companies during this time, I’ve seen this ...