<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    guanxf

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

      BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      71 隨筆 :: 1 文章 :: 41 評論 :: 0 Trackbacks

    2013年10月17日 #


    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 管先飛 閱讀(256) | 評論 (0)編輯 收藏

    執(zhí)行命名:
    git pull github master --allow-unrelated-histories

    執(zhí)行結果如下:

    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 管先飛 閱讀(316) | 評論 (0)編輯 收藏

    進入“控制面板”——“用戶賬戶”-憑據(jù)管理器——windows憑據(jù)

    找到了git的用戶名密碼。修改正確后ok

    posted @ 2018-05-20 12:29 管先飛 閱讀(263) | 評論 (0)編輯 收藏

    元注解:

      元注解的作用就是負責注解其他注解。Java5.0定義了4個標準的meta-annotation類型,它們被用來提供對其它 annotation類型作說明。Java5.0定義的元注解:
        1.@Target,
        2.@Retention,
        3.@Documented,
        4.@Inherited

      這些類型和它們所支持的類在java.lang.annotation包中可以找到。下面我們看一下每個元注解的作用和相應分參數(shù)的使用說明。
    以下為一個簡單場景的應用:
     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 管先飛 閱讀(2836) | 評論 (0)編輯 收藏

    1.選擇:File->project structure->libraries

    2.左上角選擇添加,選擇添加java(還提供了添加maven項目),然后選擇所需要的目錄:

    3.idea 會提示選擇添加什么類型的文件,我們是單純的文件,所以選擇classes

       

     
    posted @ 2016-04-29 15:42 管先飛 閱讀(1698) | 評論 (0)編輯 收藏

    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;
    }
    #偽靜態(tài)規(guī)則
    #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;
    }
    #偽靜態(tài)規(guī)則
    include /alidata/server/nginx/conf/rewrite/uuxiaohua.conf;
    access_log  /alidata/log/nginx/access/uuxiaohua.log;
    }
    posted @ 2016-01-19 17:46 管先飛 閱讀(403) | 評論 (0)編輯 收藏

    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 管先飛 閱讀(6559) | 評論 (1)編輯 收藏

    spring data 系列一直是開發(fā)者追捧的熱潮,而官方并未出spring data  jdbc,國外一個開發(fā)者讓我們看到了福音,文檔如下供大家共同學習。

    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 管先飛 閱讀(4099) | 評論 (2)編輯 收藏

    Idea是目前最好的開發(fā)工具,經(jīng)收集及整理如下常用快捷鍵: 
    一、常用快捷鍵:
     

         
      1.常用操作:
           Ctrl+E,可以顯示最近編輯的文件列表
      Shift+Click可以關閉文件
      Ctrl+[或]可以跳到大括號的開頭結尾
      Ctrl+Shift+Backspace可以跳轉(zhuǎn)到上次編輯的地方
      Ctrl+F12,可以顯示當前文件的結構
      Ctrl+F7可以查詢當前元素在當前文件中的引用,然后按F3可以選擇
      Ctrl+N,可以快速打開類
      Ctrl+Shift+N,可以快速打開文件
      Alt+Q可以看到當前方法的聲明
      Ctrl+W可以選擇單詞繼而語句繼而行繼而函數(shù)
      Alt+F1可以將正在編輯的元素在各個面板中定位
      Ctrl+P,可以顯示參數(shù)信息
      Ctrl+Shift+Insert可以選擇剪貼板內(nèi)容并插入
      Alt+Insert可以生成構造器/Getter/Setter等
      Ctrl+Alt+V 可以引入變量。例如把括號內(nèi)的SQL賦成一個變量
      Ctrl+Alt+T可以把代碼包在一塊內(nèi),例如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 向下查找關鍵字出現(xiàn)位置
      SHIFT+F3 向上一個關鍵字出現(xiàn)位置
      F4 查找變量來源
      CTRL+ALT+F7 選中的字符查找工程出現(xiàn)的地方
      CTRL+SHIFT+O 彈出顯示查找內(nèi)容

      3. 自動代碼
      ALT+回車 導入包,自動修正
      CTRL+ALT+L 格式化代碼
      CTRL+ALT+I 自動縮進
      CTRL+ALT+O 優(yōu)化導入的類和包
      ALT+INSERT 生成代碼(如GET,SET方法,構造函數(shù)等)
      CTRL+E 最近更改的代碼
      CTRL+SHIFT+SPACE 自動補全代碼
      CTRL+空格 代碼提示
      CTRL+ALT+SPACE 類名或接口名提示
      CTRL+P 方法參數(shù)提示
      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 選中代碼,連續(xù)按會有其他效果
      CTRL+B 快速打開光標處的類或方法
      ALT+ ←/→ 切換代碼視圖
      CTRL+ALT ←/→ 返回上次編輯的位置
      ALT+ ↑/↓ 在方法間快速移動定位
      SHIFT+F6 重構-重命名
      CTRL+H 顯示類結構圖
      CTRL+Q 顯示注釋文檔
      ALT+1 快速打開或隱藏工程面板
      CTRL+SHIFT+UP/DOWN 代碼向上/下移動。
      CTRL+UP/DOWN 光標跳轉(zhuǎn)到第一行或最后一行下
      ESC 光標返回編輯框
      SHIFT+ESC 光標返回編輯框,關閉無用的窗口
      F1 幫助千萬別按,很卡!
      CTRL+F4 非常重要下班都用

    二、常用配置:
      1. IDEA內(nèi)存優(yōu)化
      因機器本身的配置而配置:
      \IntelliJ IDEA 8\bin\idea.exe.vmoptions
      -----------------------------------------
      -Xms64m
      -Xmx256m
      -XX:MaxPermSize=92m
      -ea
      -server
      -Dsun.awt.keepWorkingSetOnMinimize=true

    posted @ 2015-09-26 11:38 管先飛 閱讀(482) | 評論 (0)編輯 收藏

    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、 執(zhí)行腳本:
    /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 管先飛 閱讀(3565) | 評論 (0)編輯 收藏

    Java多線程技術  --作者:楊帆    文章連接:http://express.ruanko.com/ruanko-express_6/webpage/tech4.html
     
    項目經(jīng)理:楊帆

    多線程編程一直是學員們比較頭痛和心虛的地方,因為線程執(zhí)行順序的不可預知性和調(diào)試時候的困難,讓不少人在面對多線程的情況下選擇了逃避,采用單線程的方式,其實只要我們對線程有了明確的認識,再加上java內(nèi)置的對多線程的天然支持,多線程編程不再是一道難以逾越的鴻溝。

    進程、線程、并發(fā)執(zhí)行

    首先我們先來認識一下進程、線程、并發(fā)執(zhí)行的概念:

      一般來說,當運行一個應用程序的時候,就啟動了一個進程,當然有些會啟動多個進程。啟動進程的時候,操作系統(tǒng)會為進程分配資源,其中最主要的資源是內(nèi)存空間,因為程序是在內(nèi)存中運行的。

    在進程中,有些程序流程塊是可以亂序執(zhí)行的,并且這個代碼塊可以同時被多次執(zhí)行。實際上,這樣的代碼塊就是線程體。線程是進程中亂序執(zhí)行的代碼流程。當多個線程同時運行的時候,這樣的執(zhí)行模式成為并發(fā)執(zhí)行。

    下面我以一個日常生活中簡單的例子來說明進程和線程之間的區(qū)別和聯(lián)系:

    雙向多車道道路圖

    這副圖是一個雙向多車道的道路圖,假如我們把整條道路看成是一個“進程”的話,那么圖中由白色虛線分隔開來的各個車道就是進程中的各個“線程”了。

    1. 這些線程(車道)共享了進程(道路)的公共資源(土地資源)。
    2. 這些線程(車道)必須依賴于進程(道路),也就是說,線程不能脫離于進程而存在(就像離開了道路,車道也就沒有意義了)。
    3. 這些線程(車道)之間可以并發(fā)執(zhí)行(各個車道你走你的,我走我的),也可以互相同步(某些車道在交通燈亮時禁止繼續(xù)前行或轉(zhuǎn)彎,必須等待其它車道的車輛通行完畢)。
    4. 這些線程(車道)之間依靠代碼邏輯(交通燈)來控制運行,一旦代碼邏輯控制有誤(死鎖,多個線程同時競爭唯一資源),那么線程將陷入混亂,無序之中。
    5. 這些線程(車道)之間誰先運行是未知的,只有在線程剛好被分配到CPU時間片(交通燈變化)的那一刻才能知道。

    JVM與多線程

    Java編寫的程序都運行在Java虛擬機(JVM)中,在JVM的內(nèi)部,程序的多任務是通過線程來實現(xiàn)的。

    每用java命令啟動一個java應用程序,就會啟動一個JVM進程。在同一個JVM進程中,有且只有一個進程,就是它自己。在這個JVM環(huán)境中,所有程序代碼的運行都是以線程來運行的。JVM找到程序的入口點main(),然后運行main()方法,這樣就產(chǎn)生了一個線程,這個線程稱之為主線程。當main方法結束后,主線程運行完成。JVM進程也隨即退出。

    操作系統(tǒng)將進程線程進行管理,輪流(沒有固定的順序)分配每個進程很短的一段時間(不一定是均分),然后在每個進程內(nèi)部,程序代碼自己處理該進程內(nèi)部線程的時間分配,多個線程之間相互的切換去執(zhí)行,這個切換時間也是非常短的。

    Java語言對多線程的支持

    Java語言對多線程的支持通過類Thread和接口Runnable來實現(xiàn)。這里就不多說了。這里重點強調(diào)兩個地方:

    // 主線程其它代碼段
    ThreadClass subThread = new ThreadClass();
    subThread.start();
    // 主線程其它代碼段
    subThread.sleep(1000);

    有人認為以下的代碼在調(diào)用start()方法后,肯定是先啟動子線程,然后主線程繼續(xù)執(zhí)行。在調(diào)用sleep()方法后CPU什么都不做,就在那里等待休眠的時間結束。實際上這種理解是錯誤的。因為:

    1. start()方法的調(diào)用后并不是立即執(zhí)行多線程代碼,而是使得該線程變?yōu)榭蛇\行態(tài)(Runnable),什么時候運行是由操作系統(tǒng)決定的。
    2. Thread.sleep()方法調(diào)用目的是不讓當前線程獨自霸占該進程所獲取的CPU資源,以留出一定時間給其他線程執(zhí)行的機會(也就是靠內(nèi)部自己協(xié)調(diào))。

    線程的狀態(tài)切換

    前面我們提到,由于線程何時執(zhí)行是未知的,只有在CPU為線程分配到時間片時,線程才能真正執(zhí)行。在線程執(zhí)行的過程中,由可能會因為各種各樣的原因而暫停(就像前面所舉的例子一樣:汽車只有在交通燈變綠的時候才能夠通行,而且在行駛的過程中可能會出現(xiàn)塞車,等待其它車輛通行或轉(zhuǎn)彎的狀況)。

    這樣線程就有了“狀態(tài)”的概念,下面這副圖很好的反映了線程在不同情況下的狀態(tài)變化。

    線程在不同情況下的狀態(tài)變化

    • 新建狀態(tài)(New):新創(chuàng)建了一個線程對象。
    • 就緒狀態(tài)(Runnable):線程對象創(chuàng)建后,其他線程調(diào)用了該對象的start()方法。該狀態(tài)的線程位于可運行線程池中,變得可運行,等待獲取CPU的使用權。
    • 運行狀態(tài)(Running):就緒狀態(tài)的線程獲取了CPU,執(zhí)行程序代碼。
    • 阻塞狀態(tài)(Blocked):阻塞狀態(tài)是線程因為某種原因放棄CPU使用權,暫時停止運行。直到線程進入就緒狀態(tài),才有機會轉(zhuǎn)到運行狀態(tài)。阻塞的情況分三種:
      1. 等待阻塞:運行的線程執(zhí)行wait()方法,JVM會把該線程放入等待池中。
      2. 同步阻塞:運行的線程在獲取對象的同步鎖時,若該同步鎖被別的線程占用,則JVM把該線程放入鎖。
      3. 其他阻塞:運行的線程執(zhí)行sleep()或join()方法,或者發(fā)出了I/O請求時,JVM會把該線程置為阻塞狀態(tài)。當sleep()狀態(tài)超時、join()等待線程終止或者超時、或者I/O處理完畢時,線程重新轉(zhuǎn)入就緒狀態(tài)。
    • 死亡狀態(tài)(Dead):線程執(zhí)行完了或者因異常退出了run()方法,該線程結束生命周期。

    Java中線程的調(diào)度API

    Java中關于線程調(diào)度的API最主要的有下面幾個:

    1. 線程睡眠:Thread.sleep(long millis)方法
    2. 線程等待:Object類中的wait()方法
    3. 線程讓步:Thread.yield() 方法
    4. 線程加入:join()方法
    5. 線程喚醒:Object類中的notify()方法

    關于這幾個方法的詳細應用,可以參考SUN的API。這里我重點總結一下這幾個方法的區(qū)別和使用。

    sleep方法與wait方法的區(qū)別:

    1. sleep方法是靜態(tài)方法,wait方法是非靜態(tài)方法。
    2. sleep方法在時間到后會自己“醒來”,但wait不能,必須由其它線程通過notify(All)方法讓它“醒來”。
    3. sleep方法通常用在不需要等待資源情況下的阻塞,像等待線程、數(shù)據(jù)庫連接的情況一般用wait。

    sleep/wait與yeld方法的區(qū)別:調(diào)用sleep或wait方法后,線程即進入block狀態(tài),而調(diào)用yeld方法后,線程進入runnable狀態(tài)。

    wait與join方法的區(qū)別:

    1. wait方法體現(xiàn)了線程之間的互斥關系,而join方法體現(xiàn)了線程之間的同步關系。
    2. wait方法必須由其它線程來解鎖,而join方法不需要,只要被等待線程執(zhí)行完畢,當前線程自動變?yōu)榫途w。
    3. join方法的一個用途就是讓子線程在完成業(yè)務邏輯執(zhí)行之前,主線程一直等待直到所有子線程執(zhí)行完畢。

    通過上面的介紹相信同學們對java里面的多線程已經(jīng)有了基本的了解和認識。其實多線程編程并沒有大家想象中的那么難,只要在實際的學習,工作當中不斷的加以練習和使用,相信大家很快就能掌握其中的奧妙,從而編寫出賞心悅目的java程序。


    posted @ 2015-04-11 17:31 管先飛 閱讀(268) | 評論 (0)編輯 收藏

    1、多表級聯(lián)刪除:
    ---DELETE---
    DELETE from a_msg_push,a_announcement
    using a_msg_push,a_announcement
    where  a_msg_push.announcement_id=a_announcement.id and a_announcement.Create_time<'2014-11-19 23:59:59';

    2、子查詢刪除:
    -----------delete--------
    DELETE From  t_repeat  where t_repeat.id in(
    SELECT tb.id from (
    SELECT *  from t_repeat   t 
    where 
    1=1
    and 
    (t.cid,t.uid ) in (select t1.cid,t1.uid from t_repeat t1 group by t1.cid,t1.uid having count(*) > 1) 
    and 
    t.id  not in (select min(t2.id) from t_repeat t2 group by t2.cid,t2.uid having count(*)>1) 
    ) as tb )

    3、子表刪除:
    -----------delete--------
    DELETE From  t_repeat  where t_repeat.id  not in
       SELECT tb.id from(
    select  a.id from t_repeat a where a.id =(
    select   max(b.id) from t_repeat b where a.cid=b.cid and a.uid=b.uid
       )as tb
    )
    posted @ 2015-03-01 22:52 管先飛 閱讀(2554) | 評論 (0)編輯 收藏

    感謝廖雪峰為大家提供這么好的免費教程,主要目錄如下:
    Git教程

    posted @ 2014-10-20 10:59 管先飛 閱讀(239) | 評論 (0)編輯 收藏

    gooole瀏覽器內(nèi)核已經(jīng)有webkit內(nèi)核移步到Bilnk開發(fā)屬于Chromium Projects 的版本,下面為完整教程。

    目錄

    1. Blink's Mission:
    2. Participating
      1. 2.1 Discussions
      2. 2.2 Watching for new features
      3. 2.3 Committing and reviewing code
      4. 2.4 Developing Blink
      5. 2.5 How do I port Blink to my platform?
    3. Web Platform Changes: Guidelines
      1. 3.1 Scope
      2. 3.2 Policy for shipping and removing web platform API features
      3. 3.3 Trivial Changes
      4. 3.4 Vendor Prefixes
    4. Web Platform Changes: Process
      1. 4.1 Launch Process: New Features
      2. 4.2 Launch Process: Deprecation
      3. 4.3 API Owners
      4. 4.4 API Review
      5. 4.5 Feature Dashboard
      6. 4.6 Guiding Principles for Process
    5. Testing
    6. Architectural Changes
    7. Developer FAQ
    8. Subpage Listing
      友情連接:
      https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html
    posted @ 2014-10-19 21:09 管先飛 閱讀(339) | 評論 (0)編輯 收藏

    如下兩條常用sql,統(tǒng)計分類數(shù)據(jù),你能說出區(qū)別嗎?
    一、常用sql一:
    select 
    r.cid,
    r.depart_id,
    r.employ_id,
    r.create_by,
    count(DISTINCT r.form_type) as dailyReportNum
    FROM 
    report r
    where 
    1=1 
    GROUP BY 
    r.employ_id

    二、常用sql二:
    select 
    r.cid,
    r.depart_id,
    r.employ_id,
    r.create_by,
    sum(case WHEN df.form_type=1 then 1 else 0 end ) as dailyReportNum
    FROM 
    report r
    where 
    1=1 
    GROUP BY 
    r.employ_id


    posted @ 2014-09-18 17:05 管先飛 閱讀(3594) | 評論 (4)編輯 收藏

    HSSF和XSSF的區(qū)別:
    http://poi.apache.org/spreadsheet/index.html
    POI官方詳情教程:
    http://poi.apache.org/spreadsheet/quick-guide.html

    Index of Features

    posted @ 2014-09-18 12:24 管先飛 閱讀(3815) | 評論 (2)編輯 收藏

    現(xiàn)階段JAVA操作Excel的JAR主要有apache 的POI及jxl.Jxl方便快捷,POI用于對復雜Excel的操作。

    Jxl官網(wǎng):http://www.andykhan.com/jexcelapi/index.html


    一、Jxl的API

    Jxl的API主要有三個包,jxl,jxl.format,jxl.write。如果單獨的分析API,可能對于更明確的了解此API沒有太多的幫助,我們還是從Excel文件的層次來剝離此API吧。

    一個excel文件由一個工作簿組成,一個工作簿又由n個工作表組成,每個工作表又由多個單元格組成。對應于Jxl中的結構為

    讀文件(包jxl)

    寫文件(包jxl.write)

    說明

    Workbook 

    WritableWorkbook

    工作簿

    Sheet

    WritableSheet

    工作表

    Cell/Image/Hyperlink

    WritableCell/WritableImage//WritableHyperlink

    單元格/圖像/超鏈接

           單元格(此處指文本單元格,圖像及鏈接和單元格做為一個層次)分為好多種,所以在API的設計中將Cell作為一個接口而存在。 對應的jxl中的結構為:

    讀文件(包jxl)

    寫文件(包jxl.write)

    說明

    Cell

    WritableCell

    單元格

    BooleanCell

    Boolean

    布爾值單元格

    DateCell

    DateTime

    時間單元格

    ErrorCell

     

    形式錯誤的單元格

    LabelCell

    Label

    文本單元格

    NumberCell

    Number

    數(shù)字單元格

    FormualCedll

    Formual

    公式單元格

     

    Blank

    空格單元格

    BooleanFormualCell

     

    布爾公式單元格

    DateFormualCell

     

    時間公式單元格

    ErrorFormualCell

     

    錯誤公式單元格

    StringFormualCell

     

    文本公式單元格

    NumberFormualCell

     

    數(shù)字公式單元格

     

    而有的時候,我們可能將幾個單元格作為一個整體來處理,在API中對應的則是:

        jxl.Range 

     

        雖然數(shù)據(jù)是電子表格的核心,但是同時其也需要一些輔助類,比如文件格式設置,工作表設置與顯示效果,單元格設置與顯示效果等。按照其層次,則依次有以下接口或類。

    讀文件(包jxl)

    寫文件(包jxl.write)

    說明

    WorkbookSettings

    WorkbookSettings(包jxl)

    設置workbook屬性的bean

    SheetSettings

    SheetSettings(包jxl)

    設置具體sheet的屬性的bean(比如表頭表底等)

    HeaderFooter

    HeaderFooter(包jxl)

    表示表頭表底類

    HeaderFooter.Contents

    HeaderFooter.Contents(包jxl)

    具體表頭表底設置

    CellFeatures

    WritableCellFeautres

    表格內(nèi)容相關設置(驗證)

    CellReferenceHelper

     

    得到引用單元格相關屬性

    CellType

     

    表格相關類型

    CellView

    CellView(包jxl)

    表格視圖相關設置

    CellFormat

    WritableCellFormat

    表格顯示樣式設置

     

    BoldStyle

    邊框枚舉

     

    DateFormat

    時間格式

     

    DateFormats

    時間格式枚舉

     

    NumbreFormat

    數(shù)據(jù)格式

     

    NumbreFormats

    數(shù)字模式枚舉

     

    WritableFont

    字體設置

     

    WriteableFont.Fontname

    靜態(tài)字體內(nèi)部類

     

    最后,關于Jxl.format包,此包主要是一些與具體樣式有關的接口和枚舉,不進行具體描述。
    文章摘自:http://blog.csdn.net/surgent/article/details/5836580

    posted @ 2014-09-18 09:21 管先飛 閱讀(2005) | 評論 (0)編輯 收藏

     網(wǎng)絡盒子目前市面上主流的有小米盒子、樂視盒子、Uhost、天貓盒子,各種盒子的功能都差不多,現(xiàn)以小米盒子為列簡單描述一下小米盒子。
    一、小米盒子的最新功能:
    1、觀看各種大片電影、電視劇。
    2、各種手游、教育培訓。
    二、小米盒子的缺陷:
    1、用戶直觀搜索相關的視頻太困難,搜索功能太局限。
    2、網(wǎng)絡電視不支持,不過現(xiàn)在可以安裝其他視頻軟件來觀看網(wǎng)絡電視。
    3、對手機端的安卓apk支持不好。
    三、小米盒子的潛力:
    1、小米盒子的操作系統(tǒng)采用andriod操作系統(tǒng),以后可以包含手機上有的一切功能。
    2、以后在游戲、教育、影院、購物比手機更有發(fā)展?jié)摿Α?br />四、小米盒子的使用技巧:
    1、小米盒子最新miniui已經(jīng)支持root,所以可以安裝一切安卓應用(安裝方法類似手機)。
    2、小米盒子系統(tǒng)更新保持網(wǎng)絡暢通。
    4、可以將手機片源用電視播放,也可用手機玩游戲。
    簡單寫幾個小文字睡覺,希望幫電視盒子打打廣告,以后希望盒子發(fā)展得更好,豐富用戶余業(yè)觀看在客廳的娛樂體驗。
    posted @ 2014-06-15 01:34 管先飛 閱讀(2002) | 評論 (10)編輯 收藏

         摘要: package org.jeecgframework.core.util.excel;import java.awt.image.BufferedImage;import java.io.ByteArrayOutputStream;import java.io.File;import java.io.IOException;import java.lang.reflect.Field;import...  閱讀全文
    posted @ 2014-05-29 11:14 管先飛 閱讀(7872) | 評論 (0)編輯 收藏

    JSON轉(zhuǎn)換的四種各種情況:

    1. //把java 對象列表轉(zhuǎn)換為json對象數(shù)組,并轉(zhuǎn)為字符串

        JSONArray array = JSONArray.fromObject(userlist);
        String jsonstr = array.toString();

    2.//把java對象轉(zhuǎn)換成json對象,并轉(zhuǎn)化為字符串

      JSONObject object = JSONObject.fromObject(invite);
       String str=object.toString());

    3.//把JSON字符串轉(zhuǎn)換為JAVA 對象數(shù)組

      String personstr = getRequest().getParameter("persons");
      JSONArray json = JSONArray.fromObject(personstr);
      List<InvoidPerson> persons = (List<InvoidPerson>)JSONArray.toCollection(json, nvoidPerson.class);
    4.//把JSON字符串轉(zhuǎn)換為JAVA 對象

      JSONObject jsonobject = JSONObject.fromObject(str);
      PassportLendsEntity passportlends = null;
      try {
       //獲取一個json數(shù)組
       JSONArray array = jsonobject.getJSONArray("passports");
       //將json數(shù)組 轉(zhuǎn)換成 List<PassPortForLendsEntity>泛型
       List<PassPortForLendsEntity> list = new ArrayList<PassPortForLendsEntity>();
       for (int i = 0; i < array.size(); i++) {   
                JSONObject object = (JSONObject)array.get(i);  
                PassPortForLendsEntity passport = (PassPortForLendsEntity)JSONObject.toBean(object,
                  PassPortForLendsEntity.class);
                if(passport != null){
                 list.add(passport);
                }  
         }
       //轉(zhuǎn)換PassportLendsEntity 實體類
      passportlends = (PassportLendsEntity)JSONObject.toBean(jsonobject, PassportLendsEntity.class);

      str = "{\"lendperson\":\"李四\",\"lendcompany\":\"有限公司\",\"checkperson\":\"李四\",

      \"lenddate\":\"2010-07-19T00:00:00\",\"lendcounts\":4,\"
      passports\":[{\"passportid\":\"d\",\"name\":\"李豫川\",\"passporttype\":\"K\"},
      {\"passportid\":\"K9051\",\"name\":\"李平\",\"passporttype\":\"K\"},
      {\"passportid\":\"K90517\",\"name\":\"袁寒梅\",\"passporttype\":\"K\"},
      {\"passportid\":\"K905199\",\"name\":\"賀明\",\"passporttype\":\"K\"}]}";
    相關的jar包:

    posted @ 2014-04-16 01:11 管先飛 閱讀(2752) | 評論 (0)編輯 收藏


    CriteriaQuery cq = new CriteriaQuery(MsgRecordEntity.class, datagrid);
    cq.add(Restrictions.eq("cid", cid));
    Criterion c1=cq.and(Restrictions.eq("sendEid", sendEid),Restrictions.eq("pointEid", pointEid)) ;
    Criterion c2=cq.and(Restrictions.eq("sendEid",pointEid ),Restrictions.eq("pointEid", sendEid)) ;
    cq.or(c1, c2);
    cq.add(Restrictions.eq("flag",AilkConstant.FLAG_NOT_REMOVED));
    cq.addOrder("sendDate", SortDirection.desc);
    cq.add();
    posted @ 2014-04-14 10:42 管先飛 閱讀(2197) | 評論 (0)編輯 收藏

    1、修改內(nèi)聯(lián)表
    update a_locationservice al,t_kxt_executor_info t 
    set al.objid= t.id
    where al.location_id=t.end_location_id
    and  al.objtype='8' and al.objid is null
    2、修改級聯(lián)表:
    update t_kxt_executor_info_detail tid
    LEFT JOIN 
       t_kxt_common_reports crep  
    on 
     crep.id=tid.obj_id
    set tid.flag='2'
    where  (tid.obj_type='terminalPhotograph' or tid.obj_type='requestInfo' or tid.obj_type='terminalInfo')  and  crep.id is null
    posted @ 2014-02-26 11:09 管先飛 閱讀(240) | 評論 (0)編輯 收藏

         摘要: 關于Tomcat: 安裝Tomcat:sudo apt-get install tomcat7 配置tomcat:http://wiki.ubuntu.org.cn/Tomcat 啟動tomcat:my-instance/bin/startup.sh關閉tomcat:my-instance/bin/shutdown.sh關于系統(tǒng)進程:ps ax   顯示當前...  閱讀全文
    posted @ 2014-02-25 10:17 管先飛 閱讀(493) | 評論 (0)編輯 收藏

    1.UNIX很簡單。但需要有一定天賦的人才能理解這種簡單。——Dennis Ritchie
    2.軟件在能夠復用前必須先能用。——Ralph Johnson
    3.優(yōu)秀的判斷力來自經(jīng)驗,但經(jīng)驗來自于錯誤的判斷。——Fred Brooks
    4.‘理論’是你知道是這樣,但它卻不好用。‘實踐’是它很好用,但你不知道是為什么。程序員將理論和實踐結合到一起:既不好用,也不知道是為什么。——佚名
    5.當你想在你的代碼中找到一個錯誤時,這很難;當你認為你的代碼是不會有錯誤時,這就更難了。——Steve McConnell 《代碼大全》
    6.如果建筑工人蓋房子的方式跟程序員寫程序一樣,那第一只飛來的啄木鳥就將毀掉人類文明。——Gerald Weinberg
    7.項目開發(fā)的六個階段:1. 充滿熱情 2. 醒悟 3. 痛苦 4. 找出罪魁禍首 5. 懲罰無辜 6. 褒獎閑人——佚名
    8.優(yōu)秀的代碼是它自己最好的文檔。當你考慮要添加一個注釋時,問問自己,“如何能改進這段代碼,以讓它不需要注釋?”——Steve McConnell 《代碼大全》
    9.我們這個世界的一個問題是,蠢人信誓旦旦,智人滿腹狐疑。——Bertrand Russell
    10.無論在排練中演示是如何的順利(高效),當面對真正的現(xiàn)場觀眾時,出現(xiàn)錯誤的可能性跟在場觀看的人數(shù)成正比。——佚名
    11.羅馬帝國崩潰的一個主要原因是,沒有0,他們沒有有效的方法表示他們的C程序成功的終止。——Robert Firth
    12.C程序員永遠不會滅亡。他們只是cast成了void。——佚名
    13.如果debugging是一種消滅bug的過程,那編程就一定是把bug放進去的過程。——Edsger Dijkstra
    14.你要么要軟件質(zhì)量,要么要指針算法;兩者不可兼得。——(Bertrand Meyer)
    15.有兩種方法能寫出沒有錯誤的程序;但只有第三種好用。——Alan J. Perlis
    16.用代碼行數(shù)來測評軟件開發(fā)進度,就相對于用重量來計算飛機建造進度。——比爾·蓋茨
    17.最初的90%的代碼用去了最初90%的開發(fā)時間。余下的10%的代碼用掉另外90%的開發(fā)時間。——Tom Cargill
    18.程序員和上帝打賭要開發(fā)出更大更好——傻瓜都會用的軟件。而上帝卻總能創(chuàng)造出更大更傻的傻瓜。所以,上帝總能贏。——Anon

    轉(zhuǎn)自:http://www.zhishihai.net/diannaowangluo/biancheng/bianchengsixiang/145.html
    posted @ 2013-11-10 18:54 管先飛 閱讀(268) | 評論 (0)編輯 收藏

    package com.exl.test;
    import java.awt.Color;
    import java.io.File;
    import jxl.CellView;
    import jxl.Workbook;
    import jxl.format.Alignment;
    import jxl.format.Colour;
    import jxl.format.UnderlineStyle;
    import jxl.write.Label;
    import jxl.write.WritableCellFormat;
    import jxl.write.WritableFont;
    import jxl.write.WritableSheet;
    import jxl.write.WritableWorkbook;
    import com.exl.utils.ColourUtil;
    public class Test {
       public static void main(String[] args) throws Exception {
      String title="報表測試";
      String[] navTitle= {"第一行","第二行","第三行","第四行","第五行","第六行","第七行","第八行"};  
      String[][] content={
      {"1","2","第naionfdapfn三行","第四niaodnfoanfdas行","第noandfoasnjdf五行","第六sdfadsafas行","第afdadfasdfs七a行","第adfasfdasf八行"},
      {"2","2","第三行","第四行","第五行","第六行","第七行","sssssssssss第八sss行"},
      {"3","2","第三行","第四行","第五行","第六行","第七行","第八行sssssssssssss"},
      {"4","2","第三行","第四行","第sssssssssssssss五行","第ssssssssssssssssssss六行","第七行","第八行sssssssss"},
      {"5","2","第三行","第ddddddddddddddddddddddddddddddddddddddddddddddddddddddddd四行","第五行","第六行","第七行","第八行"},
      {"6","2","第三行","第四行","第五行","第六行","第七行","第八行"},
      {"7","2","第三行","第四ddddddddddddddddddddddddddddddd行","第五行","第六行","第七行","第八行"},
      {"8","2","第三行","第四行","第五行","第六行","第七行","第八行"},
      {"9","2","第三行","第ddddddddddddddddddddddddddddddd四行","第五行","第六行","第七行","第八行"},
      {"10","2","第三行","第四行","第五行","第六行","第七行","第八行"},
      {"11","2","第三行","第四行","第五行","第六dddddddddddddd行","第七行","第八行"},
      {"12","2","第三行","第四行","第五行","第六行","第七行","第八行"},
      {"13","2","第三行","第四行","第五行","dddddddddddddddddddddd第六行","第七行","第八行"},
      {"14","2","第三行","第四行","第五行","第dddddddddddddddddddddd六行","第七行","第八行"},
      };  
      String filePath="D:\\DesignSource\\tempT";
      String fileName="NewProject.xls";
      File dir=new  File(filePath);
      if(!dir.isDirectory()){
      dir.mkdirs();
      }
      
           File file = new File(filePath+"\\"+fileName);
           WritableWorkbook workbook = Workbook.createWorkbook(file);  
           WritableSheet sheet = workbook.createSheet("報表統(tǒng)計", 0);  //單元格
           /**
            * title
            */
           Label lab = null;  
           WritableFont   wf2   =   new   WritableFont(WritableFont.ARIAL,14,WritableFont.BOLD,false,UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.BLACK); // 定義格式 字體 下劃線 斜體 粗體 顏色
           WritableCellFormat wcfTitle = new WritableCellFormat(wf2);
           wcfTitle.setBackground(jxl.format.Colour.IVORY);  //象牙白
           wcfTitle.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN,jxl.format.Colour.BLACK); //BorderLineStyle邊框
           //       wcfTitle.setVerticalAlignment(VerticalAlignment.CENTRE); //設置垂直對齊
           wcfTitle.setAlignment(Alignment.CENTRE); //設置垂直對齊
           
           CellView navCellView = new CellView();  
           navCellView.setAutosize(true); //設置自動大小
           navCellView.setSize(18);
           
           lab = new Label(0,0,title,wcfTitle); //Label(col,row,str);   
           sheet.mergeCells(0,0,navTitle.length-1,0);
           sheet.setColumnView(0, navCellView); //設置col顯示樣式
           sheet.setRowView(0, 1600, false); //設置行高
           sheet.addCell(lab);  
           /**
            * status
            */
           
           
           /**
            * nav
            */
           jxl.write.WritableFont wfcNav =new jxl.write.WritableFont(WritableFont.ARIAL,12, WritableFont.BOLD,false,UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.BLACK);
            WritableCellFormat wcfN=new WritableCellFormat(wfcNav);
            
            Color color = Color.decode("#0099cc"); // 自定義的顏色
    workbook.setColourRGB(Colour.ORANGE, color.getRed(),color.getGreen(), color.getBlue());
           wcfN.setBackground(Colour.ORANGE);
           wcfN.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN,jxl.format.Colour.BLACK); //BorderLineStyle邊框
           wcfN.setAlignment(Alignment.CENTRE); //設置水平對齊
           wcfN.setWrap(false); //設置自動換行
           for(int i=0;i<navTitle.length;i++){
          lab = new Label(i,1,navTitle[i],wcfN); //Label(col,row,str);   
          sheet.addCell(lab);  
          sheet.setColumnView(i, new String(navTitle[i]).length());  
           }
           
           /**
            * 內(nèi)容
            */
           jxl.write.WritableFont wfcontent =new jxl.write.WritableFont(WritableFont.ARIAL,12, WritableFont.NO_BOLD,false,UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.GREEN);
           WritableCellFormat wcfcontent = new WritableCellFormat(wfcontent);
           wcfcontent.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN,jxl.format.Colour.BLACK); //BorderLineStyle邊框
           wcfcontent.setAlignment(Alignment.CENTRE);
           CellView cellView = new CellView();  
           cellView.setAutosize(true); //設置自動大小
           for(int i=0;i<content.length;i++){  
               for(int j=0;j<content[i].length;j++){  
              sheet.setColumnView(i, cellView);//根據(jù)內(nèi)容自動設置列寬  
              lab = new Label(j,i+2,content[i][j],wcfcontent); //Label(col,row,str);  
                   sheet.addCell(lab);  
    //               sheet.setColumnView(j, new String(content[i][j]).length());  
               }  
           }  
           
           workbook.write();  
           workbook.close();  
    }
    }
    posted @ 2013-10-17 01:18 管先飛 閱讀(40051) | 評論 (1)編輯 收藏

    主站蜘蛛池模板: 亚洲人成电影在线播放| 男女做羞羞的事视频免费观看无遮挡| 成人A毛片免费观看网站| 成人A片产无码免费视频在线观看| av永久免费网站在线观看| 中文字幕免费视频一| 毛片大全免费观看| 亚洲AV无码专区日韩| 亚洲乱码中文字幕综合| 亚洲成在人天堂在线| 亚洲一区二区三区免费视频 | 亚洲国产成人片在线观看| 亚洲国产老鸭窝一区二区三区| 亚洲欧洲日产国码二区首页| 亚洲成av人片在线天堂无| 一个人看的www在线免费视频| 无码人妻丰满熟妇区免费| 成年女人男人免费视频播放| 亚洲精品网站在线观看不卡无广告 | 蜜桃AV无码免费看永久| 黑人粗长大战亚洲女2021国产精品成人免费视频 | 日韩电影免费在线观看视频| 精品亚洲一区二区三区在线播放| 亚洲AV无码国产精品麻豆天美| 亚洲国产日韩精品| aa在线免费观看| 久久这里只有精品国产免费10| 亚洲日韩在线第一页| 亚洲欧洲综合在线| 日韩高清在线免费看| 免费人成视网站在线观看不卡| 亚洲国产另类久久久精品小说| 亚洲视频在线视频| 亚洲sss综合天堂久久久| 国产精品亚洲专区一区| 在线观看免费视频一区| 色播精品免费小视频| 午夜国产大片免费观看| 亚洲国产精品国自产拍AV| 亚洲中文无码线在线观看| 无码的免费不卡毛片视频|