guanxf

我的博客:http://blog.sina.com.cn/17learning

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  71 随笔 :: 1 文章 :: 41 评论 :: 0 Trackbacks

2020年9月7日 #


createTree(1, orgNodeTree, sameOrgNodes, 0);


@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
public class NodeTree {
private String pName;
private String name;
private int level;
private List<NodeTree> children;
}

private void createTree(int leave, int ind, Map<String, NodeTree> pIndexNodeNameMap, List<NodeVo> childNodes) {
Map<String, NodeTree> cIndexNodeNameMap = new HashMap();
//构建树
int treeNo = pIndexNodeNameMap.size();
if (treeNo == 0) {
return;
}
int group = 0;
for (int i = ind; i < childNodes.size(); i++) {
NodeVo node = childNodes.get(i);
long index = node.getId() % treeNo;
NodeTree pNode = pIndexNodeNameMap.get(index + "");
List<NodeTree> children = pNode.getChildren();
if (CollectionUtils.isEmpty(children)) {
children = new ArrayList();
}
if (children.size() > 2) {
leave++;
createTree(leave, i, cIndexNodeNameMap, childNodes);
break;
} else {
NodeTree child = new NodeTree();
child.setLevel(leave);
child.setPName(pNode.getName());
child.setName(node.getNodeName());
children.add(child);
pNode.setChildren(children);
cIndexNodeNameMap.put(group + "", child);
group++;
}
}
}


private boolean createTree(int level, List<NodeTree> parentNodes, List<NodeVo> childNodes, int beginIndex) {
//构建树
List<NodeTree> nextLevelNodes = new ArrayList<>();
for (int i = beginIndex; i < childNodes.size(); i++) {
int parentCount = 1;
for (NodeTree pNode : parentNodes) {
List<NodeTree> children = pNode.getChildren();
if (CollectionUtils.isEmpty(children)) {
children = new ArrayList();
pNode.setChildren(children);
}
if (children.size() >= 3) {
if(parentCount >= parentNodes.size()){
return createTree(++level, nextLevelNodes, childNodes, beginIndex);
}
} else {
if (beginIndex >= childNodes.size()) {
return true;
}
NodeTree child = new NodeTree();
child.setLevel(level);
child.setPName(pNode.getName());
NodeVo node = childNodes.get(beginIndex);
child.setName(node.getNodeName());
pNode.getChildren().add(child);
nextLevelNodes.add(child);
beginIndex++;
}
parentCount++;
}
}
return true;
}
posted @ 2020-09-07 09:56 管先飞 阅读(236) | 评论 (0)编辑 收藏

2018年5月20日 #

执行命名:
git pull github master --allow-unrelated-histories

执行结果如下:

E:\WorkSpace\workspaceJ2ee\abocode\jfaster>git pull github master --allow-unrelated-histories
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 3
Unpacking objects: 100% (3/3), done.
From https://github.com/abocode/jfaster
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> github/master
Merge made by the 'recursive' strategy.
 .gitattributes | 3 +++
 1 file changed, 3 insertions(+)
 create mode 100644 .gitattributes
posted @ 2018-05-20 12:30 管先飞 阅读(303) | 评论 (0)编辑 收藏

进入“控制面板”——“用户账户”-凭据管理器——windows凭据

找到了git的用户名密码。修改正确后ok

posted @ 2018-05-20 12:29 管先飞 阅读(242) | 评论 (0)编辑 收藏

2016年8月18日 #

元注解:

  元注解的作用就是负责注解其他注解。Java5.0定义了4个标准的meta-annotation类型,它们被用来提供对其它 annotation类型作说明。Java5.0定义的元注解:
    1.@Target,
    2.@Retention,
    3.@Documented,
    4.@Inherited

  这些类型和它们所支持的类在java.lang.annotation包中可以找到。下面我们看一下每个元注解的作用和相应分参数的使用说明。
以下为一个简单场景的应用:
 1.定义注解:
   
@Target(TYPE)
@Retention(RUNTIME)
public @interface Table {
/**
* (Optional) The name of the table.
* <p/>
* Defaults to the entity name.
*/
String name() default "";
}
@Target({METHOD, FIELD})
@Retention(RUNTIME)
public @interface Column {

/**
* (Optional) The name of the column. Defaults to
* the property or field name.
*/
String name() default "";
}
2、定义实体类:
  

@Table(name = "t_s_user")
public class User {
@Column(name="name")
private String name;

@Column(name="pwd")
private String pwd;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getPwd() {
return pwd;
}

public void setPwd(String pwd) {
this.pwd = pwd;
}
}

3、运行:

public static void print() {
System.out.println("table's name" + User.class.getAnnotation(Table.class).name());
Field[] fields = User.class.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
Field field = fields[i];
System.out.println("field's type:" + field.getType().getName());
System.out.println("field's columnName:" + field.getAnnotation(Column.class).name());
}
}

关于注解的详细介绍:http://www.cnblogs.com/peida/archive/2013/04/24/3036689.html
posted @ 2016-08-18 20:42 管先飞 阅读(2820) | 评论 (0)编辑 收藏

2016年4月29日 #

1.选择:File->project structure->libraries

2.左上角选择添加,选择添加java(还提供了添加maven项目),然后选择所需要的目录:

3.idea 会提示选择添加什么类型的文件,我们是单纯的文件,所以选择classes

   

 
posted @ 2016-04-29 15:42 管先飞 阅读(1681) | 评论 (0)编辑 收藏

2016年1月19日 #

nginx 反向代理到 apache
server {
        listen       80;
        server_name  app.haeee.com;
index index.html index.htm index.php;
   root /alidata/www/movie-app;
     error_page 404 500 502 503 504 http://app.haeee.com; 
location ~ .*\.(php|php5)?$
{
#fastcgi_pass  unix:/tmp/php-cgi.sock;
fastcgi_pass  127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
#伪静态规则
#include /alidata/server/nginx/conf/rewrite/phpwind.conf;
access_log  /alidata/log/nginx/access/movie-app.log;
}

nginx 反向代理到 tomcat
server {
    listen   80;
    server_name  hulasou.com www.hulasou.com;
index index.html index.htm index.jsp;
#location ~ .*\.(jsp)?$
location /{      
index index.jsp;
        proxy_pass http://localhost:8181;
}
#伪静态规则
include /alidata/server/nginx/conf/rewrite/uuxiaohua.conf;
access_log  /alidata/log/nginx/access/uuxiaohua.log;
}
posted @ 2016-01-19 17:46 管先飞 阅读(384) | 评论 (0)编辑 收藏

2016年1月14日 #

1、修改启动项:
@SpringBootApplication
@ComponentScan
@Import({DBConfiguration.class, ResourceConfiguration.class,AppConfiguration.class})
public class Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
2、修改pom文件:
    修改packaging
    <packaging>war</packaging>
  加入打包到tomcat的配置:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-legacy</artifactId>
<version>1.0.2.RELEASE</version>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>

<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>

3、如果不需要JMX在application.properties文件中加入配置项:
endpoints.jmx.uniqueNames=true
或者直接关闭:
 endpoints.jmx.enabled=false
posted @ 2016-01-14 17:21 管先飞 阅读(6543) | 评论 (1)编辑 收藏

2015年12月28日 #

spring data 系列一直是开发者追捧的热潮,而官方并未出spring data  jdbc,国外一个开发者让我们看到了福音,文档如下供大家共同学习。

Build Status Maven Central

Spring Data JDBC generic DAO implementation

The purpose of this project is to provide generic, lightweight and easy to use DAO implementation for relational databases based on JdbcTemplate from Spring framework, compatible with Spring Data umbrella of projects.

Design objectives

  • Lightweight, fast and low-overhead. Only a handful of classes, no XML, annotations, reflection
  • This is not full-blown ORM. No relationship handling, lazy loading, dirty checking, caching
  • CRUD implemented in seconds
  • For small applications where JPA is an overkill
  • Use when simplicity is needed or when future migration e.g. to JPA is considered
  • Minimalistic support for database dialect differences (e.g. transparent paging of results)

Features

Each DAO provides built-in support for:

  • Mapping to/from domain objects through RowMapper abstraction
  • Generated and user-defined primary keys
  • Extracting generated key
  • Compound (multi-column) primary keys
  • Immutable domain objects
  • Paging (requesting subset of results)
  • Sorting over several columns (database agnostic)
  • Optional support for many-to-one relationships
  • Supported databases (continuously tested):
    • MySQL
    • PostgreSQL
    • H2
    • HSQLDB
    • Derby
    • MS SQL Server (2008, 2012)
    • Oracle 10g / 11g (9i should work too)
    • ...and most likely many others
  • Easily extendable to other database dialects via SqlGenerator class.
  • Easy retrieval of records by ID

API

Compatible with Spring Data PagingAndSortingRepository abstraction, all these methods are implemented for you:

public interface PagingAndSortingRepository<T, ID extends Serializable> extends CrudRepository<T, ID> {
 T  save(T entity);
Iterable<T> save(Iterable<? extends T> entities);
 T  findOne(ID id);
boolean exists(ID id);
Iterable<T> findAll();
   long count();
   void delete(ID id);
   void delete(T entity);
   void delete(Iterable<? extends T> entities);
   void deleteAll();
Iterable<T> findAll(Sort sort);
Page<T> findAll(Pageable pageable);
Iterable<T> findAll(Iterable<ID> ids);
}

Pageable and Sort parameters are also fully supported, which means you get paging and sorting by arbitrary properties for free. For example say you have userRepository extending PagingAndSortingRepository<User, String> interface (implemented for you by the library) and you request 5th page of USERS table, 10 per page, after applying some sorting:

Page<User> page = userRepository.findAll(
new PageRequest(
5, 10, 
new Sort(
new Order(DESC, "reputation"), 
new Order(ASC, "user_name")
)
)
);

Spring Data JDBC repository library will translate this call into (PostgreSQL syntax):

SELECT *
FROM USERS
ORDER BY reputation DESC, user_name ASC
LIMIT 50 OFFSET 10

...or even (Derby syntax):

SELECT * FROM (
SELECT ROW_NUMBER() OVER () AS ROW_NUM, t.*
FROM (
SELECT * 
FROM USERS 
ORDER BY reputation DESC, user_name ASC
) AS t
) AS a 
WHERE ROW_NUM BETWEEN 51 AND 60

No matter which database you use, you'll get Page<User> object in return (you still have to provide RowMapper<User> yourself to translate from ResultSet to domain object). If you don't know Spring Data project yet, Page<T> is a wonderful abstraction, not only encapsulating List<T>, but also providing metadata such as total number of records, on which page we currently are, etc.

Reasons to use

  • You consider migration to JPA or even some NoSQL database in the future.

    Since your code will rely only on methods defined in PagingAndSortingRepository and CrudRepository from Spring Data Commons umbrella project you are free to switch from JdbcRepository implementation (from this project) to: JpaRepository, MongoRepository, GemfireRepository or GraphRepository. They all implement the same common API. Of course don't expect that switching from JDBC to JPA or MongoDB will be as simple as switching imported JAR dependencies - but at least you minimize the impact by using same DAO API.

  • You need a fast, simple JDBC wrapper library. JPA or even MyBatis is an overkill

  • You want to have full control over generated SQL if needed

  • You want to work with objects, but don't need lazy loading, relationship handling, multi-level caching, dirty checking... You need CRUD and not much more

  • You want to by DRY

  • You are already using Spring or maybe even JdbcTemplate, but still feel like there is too much manual work

  • You have very few database tables

Getting started

For more examples and working code don't forget to examine project tests.

Prerequisites

Maven coordinates:

<dependency>
<groupId>com.nurkiewicz.jdbcrepository</groupId>
<artifactId>jdbcrepository</artifactId>
<version>0.4</version>
</dependency>

This project is available under maven central repository.

Alternatively you can download source code as ZIP.


In order to start your project must have DataSource bean present and transaction management enabled. Here is a minimal MySQL configuration:

@EnableTransactionManagement
@Configuration
public class MinimalConfig {
@Bean
public PlatformTransactionManager transactionManager() {
return new DataSourceTransactionManager(dataSource());
}
@Bean
public DataSource dataSource() {
MysqlConnectionPoolDataSource ds = new MysqlConnectionPoolDataSource();
ds.setUser("user");
ds.setPassword("secret");
ds.setDatabaseName("db_name");
return ds;
}
}

Entity with auto-generated key

Say you have a following database table with auto-generated key (MySQL syntax):

CREATE TABLE COMMENTS (
id INT AUTO_INCREMENT,
user_name varchar(256),
contents varchar(1000),
created_time TIMESTAMP NOT NULL,
PRIMARY KEY (id)
);

First you need to create domain object User mapping to that table (just like in any other ORM):

public class Comment implements Persistable<Integer> {
private Integer id;
private String userName;
private String contents;
private Date createdTime;
@Override
public Integer getId() {
return id;
}
@Override
public boolean isNew() {
return id == null;
}
//getters/setters/constructors/...
}

Apart from standard Java boilerplate you should notice implementing Persistable<Integer> where Integer is the type of primary key. Persistable<T> is an interface coming from Spring Data project and it's the only requirement we place on your domain object.

Finally we are ready to create our CommentRepository DAO:

@Repository
public class CommentRepository extends JdbcRepository<Comment, Integer> {
public CommentRepository() {
super(ROW_MAPPER, ROW_UNMAPPER, "COMMENTS");
}
public static final RowMapper<Comment> ROW_MAPPER = //see below
private static final RowUnmapper<Comment> ROW_UNMAPPER = //see below
@Override
protected <S extends Comment> S postCreate(S entity, Number generatedId) {
entity.setId(generatedId.intValue());
return entity;
}
}

First of all we use @Repository annotation to mark DAO bean. It enables persistence exception translation. Also such annotated beans are discovered by CLASSPATH scanning.

As you can see we extend JdbcRepository<Comment, Integer> which is the central class of this library, providing implementations of all PagingAndSortingRepository methods. Its constructor has three required dependencies: RowMapper, RowUnmapper and table name. You may also provide ID column name, otherwise default "id" is used.

If you ever used JdbcTemplate from Spring, you should be familiar with RowMapper interface. We need to somehow extract columns from ResultSet into an object. After all we don't want to work with raw JDBC results. It's quite straightforward:

public static final RowMapper<Comment> ROW_MAPPER = new RowMapper<Comment>() {
@Override
public Comment mapRow(ResultSet rs, int rowNum) throws SQLException {
return new Comment(
rs.getInt("id"),
rs.getString("user_name"),
rs.getString("contents"),
rs.getTimestamp("created_time")
);
}
};

RowUnmapper comes from this library and it's essentially the opposite of RowMapper: takes an object and turns it into a Map. This map is later used by the library to construct SQL CREATE/UPDATE queries:

private static final RowUnmapper<Comment> ROW_UNMAPPER = new RowUnmapper<Comment>() {
@Override
public Map<String, Object> mapColumns(Comment comment) {
Map<String, Object> mapping = new LinkedHashMap<String, Object>();
mapping.put("id", comment.getId());
mapping.put("user_name", comment.getUserName());
mapping.put("contents", comment.getContents());
mapping.put("created_time", new java.sql.Timestamp(comment.getCreatedTime().getTime()));
return mapping;
}
};

If you never update your database table (just reading some reference data inserted elsewhere) you may skip RowUnmapper parameter or use MissingRowUnmapper.

Last piece of the puzzle is the postCreate() callback method which is called after an object was inserted. You can use it to retrieve generated primary key and update your domain object (or return new one if your domain objects are immutable). If you don't need it, just don't override postCreate().

Check out JdbcRepositoryGeneratedKeyTest for a working code based on this example.

By now you might have a feeling that, compared to JPA or Hibernate, there is quite a lot of manual work. However various JPA implementations and other ORM frameworks are notoriously known for introducing significant overhead and manifesting some learning curve. This tiny library intentionally leaves some responsibilities to the user in order to avoid complex mappings, reflection, annotations... all the implicitness that is not always desired.

This project is not intending to replace mature and stable ORM frameworks. Instead it tries to fill in a niche between raw JDBC and ORM where simplicity and low overhead are key features.

Entity with manually assigned key

In this example we'll see how entities with user-defined primary keys are handled. Let's start from database model:

CREATE TABLE USERS (
user_name varchar(255),
date_of_birth TIMESTAMP NOT NULL,
enabled BIT(1) NOT NULL,
PRIMARY KEY (user_name)
);

...and User domain model:

public class User implements Persistable<String> {
private transient boolean persisted;
private String userName;
private Date dateOfBirth;
private boolean enabled;
@Override
public String getId() {
return userName;
}
@Override
public boolean isNew() {
return !persisted;
}
public void setPersisted(boolean persisted) {
this.persisted = persisted;
}
//getters/setters/constructors/...
}

Notice that special persisted transient flag was added. Contract of [CrudRepository.save()](http://static.springsource.org/spring-data/data-commons/docs/current/api/org/springframework/data/repository/CrudRepository.html#save(S)) from Spring Data project requires that an entity knows whether it was already saved or not (isNew()) method - there are no separate create() and update() methods. Implementing isNew() is simple for auto-generated keys (see Comment above) but in this case we need an extra transient field. If you hate this workaround and you only insert data and never update, you'll get away with return true all the time from isNew().

And finally our DAO, UserRepository bean:

@Repository
public class UserRepository extends JdbcRepository<User, String> {
public UserRepository() {
super(ROW_MAPPER, ROW_UNMAPPER, "USERS", "user_name");
}
public static final RowMapper<User> ROW_MAPPER = //...
public static final RowUnmapper<User> ROW_UNMAPPER = //...
@Override
protected <S extends User> S postUpdate(S entity) {
entity.setPersisted(true);
return entity;
}
@Override
protected <S extends User> S postCreate(S entity, Number generatedId) {
entity.setPersisted(true);
return entity;
}
}

"USERS" and "user_name" parameters designate table name and primary key column name. I'll leave the details of mapper and unmapper (see source code). But please notice postUpdate() and postCreate() methods. They ensure that once object was persisted, persisted flag is set so that subsequent calls to save() will update existing entity rather than trying to reinsert it.

Check out JdbcRepositoryManualKeyTest for a working code based on this example.

Compound primary key

We also support compound primary keys (primary keys consisting of several columns). Take this table as an example:

CREATE TABLE BOARDING_PASS (
flight_no VARCHAR(8) NOT NULL,
seq_no INT NOT NULL,
passenger VARCHAR(1000),
seat CHAR(3),
PRIMARY KEY (flight_no, seq_no)
);

I would like you to notice the type of primary key in Persistable<T>:

public class BoardingPass implements Persistable<Object[]> {
private transient boolean persisted;
private String flightNo;
private int seqNo;
private String passenger;
private String seat;
@Override
public Object[] getId() {
return pk(flightNo, seqNo);
}
@Override
public boolean isNew() {
return !persisted;
}
//getters/setters/constructors/...
}

Unfortunately library does not support small, immutable value classes encapsulating all ID values in one object (like JPA does with @IdClass), so you have to live with Object[] array. Defining DAO class is similar to what we've already seen:

public class BoardingPassRepository extends JdbcRepository<BoardingPass, Object[]> {
public BoardingPassRepository() {
this("BOARDING_PASS");
}
public BoardingPassRepository(String tableName) {
super(MAPPER, UNMAPPER, new TableDescription(tableName, null, "flight_no", "seq_no")
);
}
public static final RowMapper<BoardingPass> ROW_MAPPER = //...
public static final RowUnmapper<BoardingPass> UNMAPPER = //...
}

Two things to notice: we extend JdbcRepository<BoardingPass, Object[]> and we provide two ID column names just as expected: "flight_no", "seq_no". We query such DAO by providing both flight_no and seq_no (necessarily in that order) values wrapped by Object[]:

BoardingPass pass = boardingPassRepository.findOne(new Object[] {"FOO-1022", 42});

No doubts, this is cumbersome in practice, so we provide tiny helper method which you can statically import:

import static com.nurkiewicz.jdbcrepository.JdbcRepository.pk;
//...
BoardingPass foundFlight = boardingPassRepository.findOne(pk("FOO-1022", 42));

Check out JdbcRepositoryCompoundPkTest for a working code based on this example.

Transactions

This library is completely orthogonal to transaction management. Every method of each repository requires running transaction and it's up to you to set it up. Typically you would place @Transactional on service layer (calling DAO beans). I don't recommend placing @Transactional over every DAO bean.

Caching

Spring Data JDBC repository library is not providing any caching abstraction or support. However adding @Cacheable layer on top of your DAOs or services using caching abstraction in Spring is quite straightforward. See also: @Cacheable overhead in Spring.

Contributions

..are always welcome. Don't hesitate to submit bug reports and pull requests.

Testing

This library is continuously tested using Travis (Build Status). Test suite consists of 60+ distinct tests each run against 8 different databases: MySQL, PostgreSQL, H2, HSQLDB and Derby + MS SQL Server and Oracle tests not run as part of CI.

When filling bug reports or submitting new features please try including supporting test cases. Each pull request is automatically tested on a separate branch.

Building

After forking the official repository building is as simple as running:

$ mvn install

You'll notice plenty of exceptions during JUnit test execution. This is normal. Some of the tests run against MySQL and PostgreSQL available only on Travis CI server. When these database servers are unavailable, whole test is simply skipped:

Results :
Tests run: 484, Failures: 0, Errors: 0, Skipped: 295

Exception stack traces come from root AbstractIntegrationTest.

Design

Library consists of only a handful of classes, highlighted in the diagram below (source):

UML diagram

JdbcRepository is the most important class that implements all PagingAndSortingRepository methods. Each user repository has to extend this class. Also each such repository must at least implement RowMapper and RowUnmapper (only if you want to modify table data).

SQL generation is delegated to SqlGenerator. PostgreSqlGenerator. and DerbySqlGenerator are provided for databases that don't work with standard generator.

Changelog

0.4.1

0.4

  • Repackaged: com.blogspot.nurkiewicz -> com.nurkiewicz

0.3.2

  • First version available in Maven central repository
  • Upgraded Spring Data Commons 1.6.1 -> 1.8.0

0.3.1

0.3

0.2

0.1

License

This project is released under version 2.0 of the Apache License (same as Spring framework).

posted @ 2015-12-28 23:48 管先飞 阅读(4066) | 评论 (2)编辑 收藏

2015年9月26日 #

Idea是目前最好的开发工具,经收集及整理如下常用快捷键: 
一、常用快捷键:
 

     
  1.常用操作:
       Ctrl+E,可以显示最近编辑的文件列表
  Shift+Click可以关闭文件
  Ctrl+[或]可以跳到大括号的开头结尾
  Ctrl+Shift+Backspace可以跳转到上次编辑的地方
  Ctrl+F12,可以显示当前文件的结构
  Ctrl+F7可以查询当前元素在当前文件中的引用,然后按F3可以选择
  Ctrl+N,可以快速打开类
  Ctrl+Shift+N,可以快速打开文件
  Alt+Q可以看到当前方法的声明
  Ctrl+W可以选择单词继而语句继而行继而函数
  Alt+F1可以将正在编辑的元素在各个面板中定位
  Ctrl+P,可以显示参数信息
  Ctrl+Shift+Insert可以选择剪贴板内容并插入
  Alt+Insert可以生成构造器/Getter/Setter等
  Ctrl+Alt+V 可以引入变量。例如把括号内的SQL赋成一个变量
  Ctrl+Alt+T可以把代码包在一块内,例如try/catch
  Alt+Up and Alt+Down可在方法间快速移动

  2. 查询快捷键
  CTRL+N 查找类
  CTRL+SHIFT+N 查找文件
  CTRL+SHIFT+ALT+N 查找类中的方法或变量
  CIRL+B 找变量的来源
  CTRL+ALT+B 找所有的子类
  CTRL+SHIFT+B 找变量的类
  CTRL+G 定位行
  CTRL+F 在当前窗口查找文本
  CTRL+SHIFT+F 在指定窗口查找文本
  CTRL+R 在 当前窗口替换文本
  CTRL+SHIFT+R 在指定窗口替换文本
  ALT+SHIFT+C 查找修改的文件
  CTRL+E 最近打开的文件
  F3 向下查找关键字出现位置
  SHIFT+F3 向上一个关键字出现位置
  F4 查找变量来源
  CTRL+ALT+F7 选中的字符查找工程出现的地方
  CTRL+SHIFT+O 弹出显示查找内容

  3. 自动代码
  ALT+回车 导入包,自动修正
  CTRL+ALT+L 格式化代码
  CTRL+ALT+I 自动缩进
  CTRL+ALT+O 优化导入的类和包
  ALT+INSERT 生成代码(如GET,SET方法,构造函数等)
  CTRL+E 最近更改的代码
  CTRL+SHIFT+SPACE 自动补全代码
  CTRL+空格 代码提示
  CTRL+ALT+SPACE 类名或接口名提示
  CTRL+P 方法参数提示
  CTRL+J 自动代码
  CTRL+ALT+T 把选中的代码放在 TRY{} IF{} ELSE{} 里

  4. 复制快捷方式
  CTRL+D 复制行
  CTRL+X 剪切,删除行
  5. 其他快捷方式
  CIRL+U 大小写切换
  CTRL+Z 倒退
  CTRL+SHIFT+Z 向前
  CTRL+ALT+F12 资源管理器打开文件夹
  ALT+F1 查找文件所在目录位置
  SHIFT+ALT+INSERT 竖编辑模式
  CTRL+/ 注释//
  CTRL+SHIFT+/ 注释/*...*/
  CTRL+W 选中代码,连续按会有其他效果
  CTRL+B 快速打开光标处的类或方法
  ALT+ ←/→ 切换代码视图
  CTRL+ALT ←/→ 返回上次编辑的位置
  ALT+ ↑/↓ 在方法间快速移动定位
  SHIFT+F6 重构-重命名
  CTRL+H 显示类结构图
  CTRL+Q 显示注释文档
  ALT+1 快速打开或隐藏工程面板
  CTRL+SHIFT+UP/DOWN 代码向上/下移动。
  CTRL+UP/DOWN 光标跳转到第一行或最后一行下
  ESC 光标返回编辑框
  SHIFT+ESC 光标返回编辑框,关闭无用的窗口
  F1 帮助千万别按,很卡!
  CTRL+F4 非常重要下班都用

二、常用配置:
  1. IDEA内存优化
  因机器本身的配置而配置:
  \IntelliJ IDEA 8\bin\idea.exe.vmoptions
  -----------------------------------------
  -Xms64m
  -Xmx256m
  -XX:MaxPermSize=92m
  -ea
  -server
  -Dsun.awt.keepWorkingSetOnMinimize=true

posted @ 2015-09-26 11:38 管先飞 阅读(463) | 评论 (0)编辑 收藏

2015年9月22日 #

1、编写脚步:update.js
     /**
 * 时间对象的格式化;
 */
Date.prototype.format = function(format) {
    /*
     * eg:format="YYYY-MM-dd hh:mm:ss";
     */
    var o = {
        "M+" :this.getMonth() + 1, // month
        "d+" :this.getDate(), // day
        "h+" :this.getHours(), // hour
        "m+" :this.getMinutes(), // minute
        "s+" :this.getSeconds(), // second
        "q+" :Math.floor((this.getMonth() + 3) / 3), // quarter
        "S" :this.getMilliseconds()
    // millisecond
    }
 
    if (/(y+)/.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + "")
                .substr(4 - RegExp.$1.length));
    }
 
    for ( var k in o) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
                    : ("00" + o[k]).substr(("" + o[k]).length));
        }
    }
    return format;
}
var date =new Date();
var createdate=date.format("yyyy-MM-dd hh:mm:ss");
date.setMinutes(date.getMinutes()+5);
var validtime=date.format("yyyy-MM-dd hh:mm:ss");
db.UserOnlineInfo.update(
{
  "uid" : "110000350"
},
{$set : {
  "uid" : "110000350", 
  "createtime" : createdate,
  "validtime" : validtime
}});
db.UserOnlineInfo.update(
{
  "uid" : "110000351"
},
{$set : {
  "uid" : "110000351", 
  "createtime" : createdate,
  "validtime" : validtime
}});

2、编写shell脚步:
 #/bin/bash
echo "update mongod begin"
cd /home/mongodb/mongodb-3.0.2/bin
./mongo  192.168.1.122:27108/YouLiao update.js;
echo "update mongod success"

3、 执行脚本:
/home/mongodb/mongodb-3.0.2/bin/mongo  192.168.1.122:27108/YouLiao /root/www/job/mongo-test/update.js

备注:
mongodb查询、删除类似

   
posted @ 2015-09-22 19:25 管先飞 阅读(3548) | 评论 (0)编辑 收藏

仅列出标题  下一页