- 浏览: 66912 次
最新评论
文章列表
在开发中经常会用到枚举,个人理解枚举有点像之前的字典表
下面是项目中一个枚举类的例子
package com.wonder.enums;
/**
* Created by Guozhijie on 2016/9/22.
*/
public enum UserTypeEnum {
/**
* 禁用
*/
LOCK((byte)0,"禁用"),
/**
* 正常
*/
ACTIVE((byte)1,"正常");
/**
* 枚举值 ...
在项目中经常会请求别人的接口,所以经常会用到httpclient工具类,下面是我写的一个简单的工具类
首先引包,因为是maven的项目,所以直接在pom.xml中新增两个依赖,
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5</version>
...
在项目中经常会用到执行定时任务,下面的两种是我在做项目的时候用到的两种
(1)spring task
在spring.xml中beans xmlns添加
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd
...
常见的一般会有下面三种情况: 1.OutOfMemoryError: Java heap space 2.OutOfMemoryError: PermGen space
3.OutOfMemoryError: unable to create new native thread.
1.java.lang.OutOfMemoryError: PermGen space
PermGen space的全称是Permanent Generation space,是指内存的永 ...
在mybatis.xml中进行配置,
<!-- 启用对事务注解的支持 -->
<tx:annotation-driven transaction-manager="transactionManager" />
<!--事务拦截通知-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
&l ...
package com.wonder.exception;
/**
* Created by Guozhijie on 2016/9/12.
*/
public class ServiceException extends RuntimeException {
protected String msg;
protected int code;
public ServiceException(int code,String msgformat,Object...args){
super(String.format(msgform ...
HandlerInterceptor 拦截
基于response为RESTfulMessage
public class LoginIntercepter implements HandlerInterceptor {
public boolean preHandle(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse, Object handler) throws java ...
package com.wonder.annos;
import com.sun.tools.javac.code.Attribute;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Created by Guozhijie on 2016/7/1.
*/
@Target(Ele ...
restful 风格处理响应
- 博客分类:
- springmvc
现在的项目处理已经越来越流行
restful 风格处理响应,里面 包含 code message,data
现在写一个建的restfulmessage
package Util;
/**
* Created by Guozhijie on 2016/8/29.
*/
public class RESTfulMessage {
public static final String SECCESS="succes";
public static final String ERROR="error";
...
开发工具为idea,首先先看下搭建好之后的项目的结构,common-config 为项目环境的配置,因为在开发当中,有本地,测试,预生产,生产,四种环境,这样的package的时候不用修改配置,直接打包就ok
首先我们先建一个object项目,
然后在项目中 建一个 Module 名称为 antique
再在下面建三个小Module
antique-api, 主要是service 接口,entity数据库对于的类,还有一个commonUtil
antique-provider 主要是serviceImpl , mapper xml
antique-app 主要 contro ...
在拦截的时候 会遇到未登录 直接 跳转 到 login.jsp
之前做项目,用到了两种方法
(1)
ajax 异步登录
如果未登录 返回一个 restfulMessage (自定义的返回类)里面定义一个code
拦截器 如果发现未登录 返回 这个 然后判断里面的code 再window.location.href="login.jsp"
(2)
这种 是 个人最近看到的 测试了 以下 ,发现 还不错的
就是 servlet 中 有一个 抽象类 HandlerExceptionResolver
在拦截的时候 如果发现 未登录 直接抛 ...
cd find / - name webapps 查找webapps路径
ps -ef |grep java 查询java项目占用进程
top kill -3 10000(端口号)若进程死掉了 占用了非常高的比例 则查询问题
kill -9 ****杀死进程
tail -f catalina.out 查看日志
cat server.xml 查看文件
rm -rf test.war 删除包
bin下面 ./startup.sh tomcat开启
conf 配置
bin catalina.sh 内存配置
logs 日志
在做web项目的时候会遇到很多的乱码问题,今天就来总结下遇到的乱码的一些情况
数据库插入乱码 解决方案
(1)
首先查看数据库的编码 是否是utf-8
(2)
表中字段的编码 是否是 utf8
(3)
jdbc 链接 的url 加 useUnicode=true&characterEncoding=utf-8
(4)tomcat 下conf文件夹下server.xml中配置 URIEncoding="UTF-8"
(5)
web.xml中加过滤器
<filter>
2 < ...
在做aop测试的时候 发现pointcut 没有效果,之后查了一下 发现了问题
如果使用了spring mvc后,如果把<aop:aspectj-autoproxy proxy-target-class="true"/>放在application.xml文件中可能会aop无效,最好把它放在dispatcher-servlet.xml文件中
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http:/ ...
自定义方法拦截器 @interface 属于annotation 注解
import java.lang.annotation.ElementType;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.Retention;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface AccessRequ ...