maven打包可执行项目

pom.xml配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
<archive>
<manifest>
<!-- 项目主清单(main)入口类 -->
<mainClass>com.test.TestMain</mainClass>
</manifest>
</archive>
<descriptors>
<!-- 因为不是web程序,所以需要另外增加assmbly.xml文件 -->
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

阅读更多

maven引用外部jar包

从路径读取jar的方式,比较好的做法是在项目中建一个lib目录来存放jar包

1
2
3
4
5
6
7
8
9
<dependency>
<groupId>postmsg-ump</groupId>
<artifactId>postmsg-ump</artifactId>
<scope>system</scope>
<!-- 版本随便,为了好管理从1.0开始写,我这里已经迭代很多了 -->
<version>2.4</version>
<!-- basedir表示根目录,如果不在项目中则写绝对路径,如d:\\postmsg-ump-2.4.jar -->
<systemPath>${basedir}\src\lib\postmsg-ump-2.4.jar</systemPath>
</dependency>

阅读更多

SpringMvc整合Swagger UI

首先,导入主要的jar包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!-- swagger-springmvc start -->
<dependency>
<groupId>com.mangofactory</groupId>
<artifactId>swagger-springmvc</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>com.mangofactory</groupId>
<artifactId>swagger-models</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.3.11</version>
</dependency>
<!-- swagger-springmvc end -->

阅读更多

POI导出excel表

列标题属性注解类
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package excel;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.CellStyle;
/**
* @Title: ExcelAnnotation.java
* @Package excel
* @Description: 列标题属性注解
* @author Zoro
* @date 2016年12月30日 下午4:13:54
* @version V1.0
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD})
public @interface ExcelAnnotation {
// 列标题名
public String name() default "";
// 行号
public int col() default 0;
// 日期格式
public String dateFormat() default "";
/** 列标题样式 start */
// 水平对齐(默认居中)
public short alignment() default CellStyle.ALIGN_CENTER;
// 垂直对齐(默认)
public short verticalAlignment() default CellStyle.VERTICAL_CENTER;
// 填充信息模式和纯色填充单元(默认不填充)
public short fillPattern() default CellStyle.SOLID_FOREGROUND;
// 背景色填充(默认白色)
public short fillBackgroundColor() default HSSFColor.GREY_40_PERCENT.index;
// 字号(默认16)
public short fontHeighInPoints() default 16;
// 字体颜色(默认黑色)
public short fontColor() default HSSFColor.BLACK.index;
/** 列标题样式 end */
}

阅读更多

读取jar包中的文件

在jar包中读取资源文件,有时,我们的项目需要打成jar包,比如做maven父子依赖的时候,公共的项目被打成jar包放在子项目下,有一些公共的配置也被打入jar包中,读取相应文件的时候,如果按照常规web运行时的方式读取,读取到的路径是xxx.jar!xxx的形式,虽然路径是没有错,但是这种路径并不是一个目录路径,是不可读的,这时就需要用读流的方式来读取了

阅读更多

Java去除Html标签

普通的正则去除标签

1
2
3
4
// 剔出<html>的标签
String txtcontent = htmlcontent.replaceAll("</?[^>]+>", "");
// 去除字符串中的空格,回车,换行符,制表符
txtcontent = txtcontent.replaceAll("<a>\\s*|\t|\r|\n</a>", "");

阅读更多

spring4.0读取properties文件

若我们的项目配置了多环境
注入properties属性,spring4.0配置,要引入
xmlns:util=”http://www.springframework.org/schema/util"和
http://www.springframework.org/schema/util/spring-util-4.0.xsd

我的配置是

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd
">
<description>spring总配置</description>
<!-- 打开Spring的Annotation支持 -->
<context:annotation-config />
<!-- 设定Spring 去哪些包中找Annotation -->
<context:component-scan base-package="com.test" />
<!-- 使用aop -->
<aop:aspectj-autoproxy proxy-target-class="true" />
<!-- 读入配置属性文件 -->
<context:property-placeholder location="classpath:${profiles.active}/system.properties" />
<util:properties id="pro" location="classpath:${profiles.active}/system.properties"/>
<!--引入其他spring配置文件 -->
<import resource="classpath:spring/spring-datasource.xml" />
<import resource="classpath:spring/spring-mybatits.xml" />
<import resource="classpath:spring/spring-transaction.xml" />
<import resource="classpath:spring/spring-redis.xml" />
</beans>

阅读更多

Mybatis执行insert后获取主键方式

1
2
3
在hibernate中,hibernate的一级缓存会把insert后的主键绑定到对象中,我们可以直接在session.save(user);
后直接使用user.getId();的方式来取得插入后的主键,而在mybatis中,我们一般使用mapper.xml来编辑sql语句,
当我们执行insert后,返回的model中并没有帮我们把主键返回

阅读更多

Java自定义验证注解

元注解:Java5定义了4个标准的meta-annotation类型
 1、@Target:表示Annotation所修饰的对象范围
 取值(ElementType)有:
   1)CONSTRUCTOR:用于描述构造器
   2)FIELD:用于描述域
   3)LOCAL_VARIABLE:用于描述局部变量
   4)METHOD:用于描述方法
   5)PACKAGE:用于描述包
   6)PARAMETER:用于描述参数
   7)TYPE:用于描述类、接口(包括注解类型) 或enum声明
 2、@Retention:表示Annotation被保留的时间长短
   取值(RetentionPoicy)有:
   1)SOURCE:在源文件中有效(即源文件保留)
   2)CLASS:在class文件中有效(即class保留)
   3)RUNTIME:在运行时有效(即运行时保留)
 3、@Documented:用于描述其它类型的annotation应该被作为被标注的程序成员的公共API,因此可以被例如javadoc此类的工具文档化。Documented是一个标记注解,没有成员
 4、@Inherited:阐述了某个被标注的类型是被继承的。如果一个使用了@Inherited修饰的annotation类型被用于一个class,则这个annotation将被用于该class的子类

阅读更多

eclipse安装svn

在线安装:
  打开Eclipse
  Help->Software Updates->find and install(如果没有这个就用help->Software Updates->Add/Remove Software即可)

阅读更多