<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5553741655215810943</id><updated>2024-09-01T16:13:39.438-07:00</updated><category term="Spring boot"/><category term="Linux"/><category term="工作"/><category term="MQ"/><category term="AR"/><category term="JavaEE"/><category term="CAS"/><category term="Google"/><category term="Lucene"/><category term="Pentaho"/><category term="cordova"/><category term="genymotion"/><category term="生活"/><title type='text'>Louis@Cathay #Intermediate #Evolution</title><subtitle type='html'>喜歡進化金融科技架構、也愛寫程式、更愛開放源碼、愛分享技術給大家的 Louis</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://louiszspower.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://louiszspower.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Louisz</name><uri>http://www.blogger.com/profile/15227162328934605700</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuq5rOe6t7hT-kppa8Fu3eLB6RzgYqY8I7hZyMmMKyeAVUNbzRxsj7SQQA1EyynM-Ac6FjR6PmyXhcfn6PiIsBkByRyY8nSu3CWpAlXTcOcfGjpUDCpSBge2ou1j770EY/s220/IMG_20170629_210051.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>45</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5553741655215810943.post-4060768425845139856</id><published>2017-07-28T06:48:00.002-07:00</published><updated>2017-07-28T06:55:32.315-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Spring boot"/><title type='text'>Spring boot v1.5 (六) spring data jpa 基本操作</title><content type='html'>最近天氣好熱，做甚麼事都覺得很懶，想要寫個spring data jpa也是懶懶的，不過這部分卻也是滿重要的一部分，前一篇介紹&lt;a href=&quot;https://louiszspower.blogspot.tw/2017/07/spring-boot-v15-jdbctemplate.html&quot;&gt;JDBCTemplate&lt;/a&gt;，已經覺得跟以前寫SQL方式有所差異了，JPA帶來的是物件導向的設計面思考，說到JPA不得不提提&lt;a href=&quot;https://en.wikipedia.org/wiki/Object-relational_mapping&quot;&gt;ORM&lt;/a&gt;，Object-relational mapping主要想法為簡化及物件導向的設計，讓RDB更貼近Object，在設計上可以更加便利，甚至透過一些設計可以讓Table具有物件導向的特性如繼承等等，以往要使用ORM的框架，都會先以&lt;a href=&quot;https://zh.wikipedia.org/wiki/Hibernate&quot;&gt;Hibernate&lt;/a&gt;進行，不過近來慢慢地轉向JPA，主要還是在減少程式碼、增加彈性等等，大體的功能沒有差異很大，所以從Hibernate轉到JPA問題不大，JPA要介紹的東西還滿多的，所以我這裡會再分成三個章節來介紹。&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;SPRING DATA JPA基本操作&lt;/li&gt;
&lt;li&gt;JPQL &amp;amp; Named SQL &amp;amp; Native SQL&lt;/li&gt;
&lt;li&gt;Cache &amp;amp; DB Design Pattern&lt;/li&gt;
&lt;/ul&gt;
SPRING DATA JPA更加簡化的程式撰寫，只需要一個 Interface內寫一些查詢 method就可以操作JPA，因為利用 method 組合查詢條件，確實很方便也很容易理解，若是都沒有辦法符合需求當然也可以自己實作一個來用當然沒有問題。&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;學習目的&lt;/b&gt;：SPRING DATA JPA基本操作。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;學習時數&lt;/b&gt;：3.5hr&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;教學影片：&lt;/b&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe allowfullscreen=&quot;&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/8aFeaX2tFF0/0.jpg&quot; frameborder=&quot;0&quot; height=&quot;266&quot; src=&quot;https://www.youtube.com/embed/8aFeaX2tFF0?feature=player_embedded&quot; width=&quot;320&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;pom.xml 說明&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;spring-boot-starter-web:配置 Web Project所需的函式庫。
spring-boot-starter-test:配置 unit or mock test 所需的函式庫。
spring-boot-starter-actuator:配置監控spring boot所需的函式庫，後續spring cloud會使用到，所以一開就導入。&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;spring-boot-starter-jdbc:配置使用jdbc所需的函式庫。&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;postgresql:配置postgresql連接Driver所需的函式庫。&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;jasypt-spring-boot-starter:加解密所需的函式庫。&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;spring-boot-starter-data-jpa:配置Spring data jpa所需的函式庫。&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;lombok:本次的彩蛋，降低getter與setter的套件。&lt;/span&gt;&lt;/pre&gt;

&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;有使用到&lt;a href=&quot;https://louiszspower.blogspot.tw/2017/07/spring-boot-v15-jdbctemplate.html&quot;&gt;上一篇&lt;/a&gt;的加解密&lt;/span&gt;
&lt;div style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;; white-space: normal;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;b style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;程式碼說明&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;

&lt;ul style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;; white-space: normal;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;
&lt;li&gt;Example6.java&lt;/li&gt;
&lt;/span&gt;&lt;/ul&gt;

&lt;pre class=&quot;codeblock prettyprint&quot; style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot;, sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;package louisz.springboot.example6;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.PropertySource;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * Louisz Spring boot introduce ex.6
 *
 */

@SpringBootApplication
@PropertySource(name = &quot;EncryptedProperties&quot;, value = &quot;classpath:example5.properties&quot;)//針對需加解密的設定檔檔名及位置
@EntityScan(basePackages = {&quot;louisz.springboot.example6&quot;})//載入指定package的entity
@EnableJpaRepositories(basePackages = {&quot;louisz.springboot.example6&quot;})//載入指定package jpaRepositories
@EnableTransactionManagement//啟動交易模式
public class Example6 {
 /**
  * 程式執行起點
  * 
  * @param args
  */
 public static void main(String[] args) {
  SpringApplication.run(Example6.class, args);
 }

}&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;
&lt;ul style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;; white-space: normal;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;
&lt;li&gt;Member.java&lt;/li&gt;
&lt;/span&gt;&lt;/ul&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;package louisz.springboot.example6;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import lombok.Getter;
import lombok.Setter;

@Entity//Entity宣告
@Table(name = &quot;member&quot;)//指定對應Table，請記得一定要有ID欄位(名稱可以改變)作為PK喔
public class Member {
 @Id //PK
    @GeneratedValue //之後針對SEQUENCE會需要
    @Setter @Getter //lombok 減少setter及getter method撰寫
    private Long id;
    @Column(nullable = false)//不可為空值
    @Setter @Getter
    private String name;
    @Column(nullable = false)
    @Setter @Getter
    private Integer age;
}&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;
&lt;/pre&gt;
&lt;/span&gt;
&lt;ul style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;
&lt;li&gt;MemberRepository.java&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;package louisz.springboot.example6;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface MemberRepository extends JpaRepository&lt;member long=&quot;&quot;&gt;{
 /**
  * 使用ID查詢資料，並回傳Member Entity
  * @param id
  * @return
  */
 Member findById(Long id);
 /**
  * 使用ID查詢資料，並回傳Member Entity
  * @param name
  * @return
  */
 Member findByName(String name);
 /**
  * 透過JPQL，使用NAME查詢，並回傳Member Entity
  * @param name
  * @return
  */
    @Query(&quot;from Member u where u.name=:name&quot;)
    Member findMember(@Param(&quot;name&quot;) String name);    
    /**
     * 使用NAME及AGE查詢，並回傳Member Entity
     * @param name
     * @param age
     * @return
     */
    Member findByNameAndAge(String name, Integer age);
    /**
     * 使用NAME進行Count，並回傳筆數
     * @param name
     * @return
     */
    Long countByName(String name);
    //不分姓名大小寫的查詢
    /**
     * 使用NAME進行查詢且不分大小寫，並回傳List&lt;member&gt;
     * @param name
     * @return
     */
    List&lt;member&gt; findByNameIgnoreCase(String name); 
}&lt;/member&gt;&lt;/member&gt;&lt;/member&gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;ul style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;
&lt;li&gt;TestMemberRepository.java&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;package louisz.springboot.example6;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.test.context.junit4.SpringRunner;

//spring boot 1.4以後的方式
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class TestMemberRepository {

 @Autowired
 private MemberRepository memberRepository;

 @Before
 public void setUp() {
  // 先清除所有資料
  memberRepository.deleteAll();
 }

 @Test
 public void test() throws Exception {
  /*
   * 進行單元測試，先規劃相關情境
   */
  // 先確認是否清除完成
  Assert.assertEquals(0, memberRepository.findAll().size());
  // 新增一筆資料
  Member m = new Member();
  m.setId(1l);
  m.setAge(new Integer(12));
  m.setName(&quot;louisz&quot;);
  memberRepository.save(m);
  // 確認新增資料筆數
  Assert.assertEquals(1, memberRepository.findAll().size());
  // 檢查新增的資料是否正確
  Assert.assertEquals(12, memberRepository.findByName(&quot;louisz&quot;).getAge().longValue());
  // 修改姓名
  m.setName(&quot;jessie&quot;);
  memberRepository.save(m);
  // 檢查新增的資料是否正確
  Assert.assertEquals(&quot;jessie&quot;, memberRepository.findById(1l).getName());
  // 刪除新增的資料
  memberRepository.delete(memberRepository.findById(1l));
  // 確認刪除資料筆數
  Assert.assertEquals(0, memberRepository.findAll().size());
  // 再度儲存
  memberRepository.save(m);
  // 查詢姓名為jessie的筆數
  Assert.assertEquals(1, memberRepository.countByName(&quot;jessie&quot;).longValue());
  // 不分大小寫查詢姓名
  Assert.assertEquals(0, memberRepository.countByName(&quot;JESSIE&quot;).longValue());
  Assert.assertEquals(1, memberRepository.findByNameIgnoreCase(&quot;JESSIE&quot;).size());
 }

}
&lt;/span&gt;
&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;單元測試看結果，執行時請加上-Djasypt.encryptor.password=supersecretz&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;https://github.com/louisz6ster/spring_boot&quot; style=&quot;font-size: x-large;&quot;&gt;Github code&lt;/a&gt;&lt;span style=&quot;font-size: large;&quot;&gt;(louisz.springboot.example6)&lt;/span&gt;&lt;br /&gt;
參考連結：&lt;br /&gt;
&lt;a href=&quot;https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods&quot;&gt;https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://blog.didispace.com/springbootdata2/&quot;&gt;http://blog.didispace.com/springbootdata2/&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;https://projectlombok.org/&quot;&gt;https://projectlombok.org/&lt;/a&gt;&lt;br /&gt;
&lt;div&gt;
&lt;a href=&quot;https://springframework.guru/category/spring/spring-data/&quot;&gt;https://springframework.guru/category/spring/spring-data/&lt;/a&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://louiszspower.blogspot.com/feeds/4060768425845139856/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://louiszspower.blogspot.com/2017/07/spring-boot-v15-spring-data-jpa.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/4060768425845139856'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/4060768425845139856'/><link rel='alternate' type='text/html' href='http://louiszspower.blogspot.com/2017/07/spring-boot-v15-spring-data-jpa.html' title='Spring boot v1.5 (六) spring data jpa 基本操作'/><author><name>Louisz</name><uri>http://www.blogger.com/profile/15227162328934605700</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuq5rOe6t7hT-kppa8Fu3eLB6RzgYqY8I7hZyMmMKyeAVUNbzRxsj7SQQA1EyynM-Ac6FjR6PmyXhcfn6PiIsBkByRyY8nSu3CWpAlXTcOcfGjpUDCpSBge2ou1j770EY/s220/IMG_20170629_210051.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/8aFeaX2tFF0/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553741655215810943.post-6534267172436597189</id><published>2017-07-01T02:13:00.004-07:00</published><updated>2017-07-28T06:55:15.061-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Spring boot"/><title type='text'>Spring boot v1.5 (五) JDBCTemplate</title><content type='html'>&amp;nbsp; &amp;nbsp; 我個人是較推崇 JPA的，不過有些情況下，或是架構設計上，會需要純SQL的方式進行，但是像教科書介紹的方式進行，在實務上很難看到，太難用、程式太醜、修改太複雜等等都是要克服的問題，不可能期望所有開發者都是同一高等級的，JDBCTemplate某程度簡化了使用SQL的繁雜度，若是需要大量的純SQL時，JDBCTemplate絕對是首選，也會介紹JDBCTemplate如增刪修查方式、Connection Pool設定及帳密加密的方式等等。
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot;, sans-serif;&quot;&gt;預先準備項目&lt;/b&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;：請先&lt;/span&gt;&lt;a href=&quot;https://www.postgresql.org/download/&quot; style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot;, sans-serif;&quot;&gt;下載&lt;/a&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;並&lt;/span&gt;&lt;a href=&quot;http://www.postgresqltutorial.com/install-postgresql/&quot; style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot;, sans-serif;&quot;&gt;安裝&lt;/a&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt; &lt;/span&gt;&lt;a href=&quot;https://zh.wikipedia.org/wiki/PostgreSQL&quot; style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot;, sans-serif;&quot;&gt;PostgreSQL&lt;/a&gt;，並建立一個DB(louisz)及Table(users)，DDL如下:&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;。&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;CREATE DATABASE louisz
    WITH 
    OWNER = louisz
    ENCODING = &#39;UTF8&#39;
    LC_COLLATE = &#39;Chinese (Traditional)_Taiwan.950&#39;
    LC_CTYPE = &#39;Chinese (Traditional)_Taiwan.950&#39;
    TABLESPACE = pg_default
    CONNECTION LIMIT = -1;

CREATE TABLE public.users
(
    id integer NOT NULL,
    name character varying COLLATE pg_catalog.&quot;default&quot;,
    email character varying COLLATE pg_catalog.&quot;default&quot;,
    mobilenumber character varying COLLATE pg_catalog.&quot;default&quot;,
    CONSTRAINT user_pkey PRIMARY KEY (id)
)
WITH (
    OIDS = FALSE
)
TABLESPACE pg_default;
&lt;/pre&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;學習目的&lt;/b&gt;：使用自訂屬性設定檔、屬性一些進階的使用。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;學習時數&lt;/b&gt;：3.5hr&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: start;&quot;&gt;
&lt;b&gt;教學影片：&lt;/b&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe allowfullscreen=&quot;&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/oo5HnLY5olk/0.jpg&quot; frameborder=&quot;0&quot; height=&quot;266&quot; src=&quot;https://www.youtube.com/embed/oo5HnLY5olk?feature=player_embedded&quot; width=&quot;320&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;b&gt;pom.xml 說明&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;spring-boot-starter-web:配置 Web Project所需的函式庫。
spring-boot-starter-test:配置 unit or mock test 所需的函式庫。
spring-boot-starter-actuator:配置監控spring boot所需的函式庫，後續spring cloud會使用到，所以一開就導入。&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;spring-boot-starter-jdbc:配置使用jdbc所需的函式庫。&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;postgresql:配置postgresql連接Driver所需的函式庫。&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;jasypt-spring-boot-starter:加解密所需的函式庫。&lt;/span&gt;
&lt;/pre&gt;
&lt;b&gt;example5.properties JDBC設定檔說明&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;#DB設定資訊
#PostgreSQL JDBC URL
spring.datasource.url= jdbc:postgresql://localhost:5432/louisz
#DB使用者帳號
spring.datasource.username=louisz
#DB使用者密碼已經加過密的，請使用自己產生的
spring.datasource.password=ENC(xOSgfOF9jzB8jpYSB1O+4jEobziG16pA)

&lt;/pre&gt;
&lt;b&gt;產生亂碼值的指令&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;java -cp ~/.m2/repository/org/jasypt/jasypt/1.9.2/jasypt-1.9.2.jar  org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI input=&quot;contactspassword&quot; password=supersecretz algorithm=PBEWithMD5AndDES
input:需要加密的資訊
password:壓密KEY，可以自己定義
結果應該像是這樣，OUTPUT就是被加密過後的值

----ENVIRONMENT-----------------

Runtime: Oracle Corporation Java HotSpot(TM) 64-Bit Server VM 24.45-b08



----ARGUMENTS-------------------

algorithm: PBEWithMD5AndDES
input: contactspassword
password: supersecretz



----OUTPUT----------------------

XcBjfjDDjxeyFBoaEPhG14wEzc6Ja+Xx+hNPrJyQT88=

&lt;/pre&gt;
&lt;div style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;; white-space: normal;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;b style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;程式碼說明&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Example5.java&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;package louisz.springboot.example5;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.PropertySource;

/**
 * Louisz Spring boot introduce ex.5
 *
 */

@SpringBootApplication
@PropertySource(name = &quot;EncryptedProperties&quot;, value = &quot;classpath:example5.properties&quot;)//針對需加解密的設定檔檔名及位置
public class Example5 {
 /**
  * 程式執行起點
  * 
  * @param args
  */
 public static void main(String[] args) {
  SpringApplication.run(Example5.class, args);

 }

}
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;ul&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;
&lt;li&gt;UserService.java&lt;/li&gt;
&lt;/span&gt;&lt;/ul&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;package louisz.springboot.example5;

import java.util.List;

import louisz.springboot.example3.User;

public interface UserService {
 /**
  * 新增一筆User資料
  * 
  * @param User
  */
 void merge(User user);

 /**
  * 刪除傳入相同姓名的資料
  * 
  * @param name
  */
 void deleteByName(String name);

 /**
  * 查詢所有資料，並回傳List物件
  */
 List&lt;user&gt; listAll();

 /**
  * 查詢特定id資料，並回該User Object
  */
 
 User findById(Long id);
 
 /**
  * 删除所有用户
  */
 void deleteAllUsers();

 /**
  * 依據傳入的id，依據傳入的User物件，更新資料表中相同id的資料
  * 
  * @param id
  * @param user
  */
 void updateUser(Long id, User user);
}

&lt;/user&gt;&lt;/pre&gt;
&lt;ul&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;
&lt;li&gt;UserServiceImpl.java&lt;/li&gt;
&lt;/span&gt;&lt;/ul&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;package louisz.springboot.example5;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import louisz.springboot.example3.User;

@Service
public class UserServiceImpl implements UserService {

 @Autowired
 private JdbcTemplate jdbcTemplate;

 @Override
 public void merge(User user) {
  jdbcTemplate.update(&quot;insert into users(id,name,email,mobilenumber) values(?, ?,?,?)&quot;, user.getId(),
    user.getName(), user.getEmail(), user.getMobilenumber());
 }

 @Override
 public void deleteByName(String name) {
  jdbcTemplate.update(&quot;delete from users where name = ?&quot;, name);
 }

 @Override
 public List&lt;user&gt; listAll() {
  return jdbcTemplate.query(&quot;select * from users&quot;, new BeanPropertyRowMapper(User.class));
 }

 @Override
 public void deleteAllUsers() {
  jdbcTemplate.update(&quot;delete from users &quot;);
 }

 @Override
 public void updateUser(Long id, User user) {
  jdbcTemplate.update(&quot;update users set name = ? where id = ?&quot;, user.getName(), id);
 }

 @Override
 public User findById(Long id) {
  return (User)jdbcTemplate.queryForObject(
    &quot;select * from users where id = ?&quot;, new Object[] { id },
    new BeanPropertyRowMapper(User.class));
 }

}

&lt;/user&gt;&lt;/pre&gt;
&lt;ul&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;
&lt;li&gt;TestUserServiceImpl.java&lt;/li&gt;
&lt;/span&gt;&lt;/ul&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;package louisz.springboot.example5;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.test.context.junit4.SpringRunner;

import louisz.springboot.example3.User;

//spring boot 1.4以後的方式
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class TestUserServiceImpl {

 @Autowired
 private UserService userSerivce;// 注入UserService
         // interface，實際instance會呼叫UserServiceImpl物件

 @Before
 public void setUp() {
  // 先清除所有資料
  userSerivce.deleteAllUsers();
 }

 @Test
 public void test() throws Exception {
  /*
   * 進行單元測試，先規劃相關情境
   */
  User user1 = new User();
  user1.setId(1l);
  user1.setEmail(&quot;louisz6ster@gmail.com&quot;);
  user1.setName(&quot;user1&quot;);
  user1.setMobilenumber(&quot;0912345678&quot;);

  User user2 = new User();
  user2.setId(2l);
  user2.setEmail(&quot;louisz6ster@gmail.com&quot;);
  user2.setName(&quot;user2&quot;);
  user2.setMobilenumber(&quot;0912345678&quot;);

  User user3 = new User();
  user3.setId(3l);
  user3.setEmail(&quot;louisz6ster@gmail.com&quot;);
  user3.setName(&quot;user3&quot;);
  user3.setMobilenumber(&quot;0912345678&quot;);
  // 新增三個User資料
  userSerivce.merge(user1);
  userSerivce.merge(user2);
  userSerivce.merge(user3);

  // 查詢全部資料筆數是否吻合，確認新增成功
  Assert.assertEquals(3, userSerivce.listAll().size());
  // 刪除資料
  userSerivce.deleteByName(&quot;user1&quot;);
  userSerivce.deleteByName(&quot;user2&quot;);
  // 查詢全部資料筆數是否吻合，確認刪除成功
  Assert.assertEquals(1, userSerivce.listAll().size());
  
  //更新User3姓名跟email
  user3.setName(&quot;Jessie&quot;);
  userSerivce.updateUser(user3.getId(), user3);
  
  //查詢資料表中User3的資料是否更新成功
  User newUser3 = userSerivce.findById(user3.getId());
  Assert.assertEquals(user3.getName(), newUser3.getName());
  
 }

}

&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;單元測試看結果，執行時請加上-Djasypt.encryptor.password=supersecretz&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;https://github.com/louisz6ster/spring_boot&quot; style=&quot;font-size: x-large;&quot;&gt;Github code&lt;/a&gt;&lt;span style=&quot;font-size: large;&quot;&gt;(louisz.springboot.example5)&lt;/span&gt;&lt;br /&gt;
參考連結：&lt;br /&gt;
&lt;a href=&quot;http://blog.didispace.com/springbootdata1/&quot;&gt;http://blog.didispace.com/springbootdata1/&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;https://www.ricston.com/blog/encrypting-properties-in-spring-boot-with-jasypt-spring-boot/&quot;&gt;https://www.ricston.com/blog/encrypting-properties-in-spring-boot-with-jasypt-spring-boot/&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;https://github.com/ulisesbocchio/jasypt-spring-boot&quot;&gt;https://github.com/ulisesbocchio/jasypt-spring-boot&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://louiszspower.blogspot.com/feeds/6534267172436597189/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://louiszspower.blogspot.com/2017/07/spring-boot-v15-jdbctemplate.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/6534267172436597189'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/6534267172436597189'/><link rel='alternate' type='text/html' href='http://louiszspower.blogspot.com/2017/07/spring-boot-v15-jdbctemplate.html' title='Spring boot v1.5 (五) JDBCTemplate'/><author><name>Louisz</name><uri>http://www.blogger.com/profile/15227162328934605700</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuq5rOe6t7hT-kppa8Fu3eLB6RzgYqY8I7hZyMmMKyeAVUNbzRxsj7SQQA1EyynM-Ac6FjR6PmyXhcfn6PiIsBkByRyY8nSu3CWpAlXTcOcfGjpUDCpSBge2ou1j770EY/s220/IMG_20170629_210051.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/oo5HnLY5olk/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553741655215810943.post-728357600275553105</id><published>2017-06-29T08:25:00.000-07:00</published><updated>2017-06-29T08:25:57.828-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Spring boot"/><title type='text'>Spring boot v1.5 (四) swagger,properties and structing your code</title><content type='html'>在&lt;a href=&quot;https://louiszspower.blogspot.tw/2017/06/spring-boot-v15-magic-restful-and.html&quot;&gt;上一章&lt;/a&gt;有稍微讓大家看一下swagger怎麼跟spring boot無縫接軌，本章就深入一點來介紹swagger，把它定位在 API似乎有點薄弱，當作工具(Tools)我覺得倒很個很好的解釋，它主要提供的工具分別為 swagger core、swagger codegen、swagger editor、swagger ui等，以下是各自的說明：&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;swagger core：這是swagger的核心，使用Java撰寫出來的。&lt;/li&gt;
&lt;li&gt;swagger codegen：可以依據swagger(yaml格式)產生出來的api json或是url，可產生客戶端(client)相對應的程式碼。&lt;/li&gt;
&lt;li&gt;swagger editor：透過這個工具可以產生yaml，有點像是Eclipse IDE一樣，撰寫相對應的yaml，透過yaml可以產服務端(server)及客戶端(client)的程式碼，透過&lt;a href=&quot;http://editor.swagger.io/#/&quot;&gt;這裡&lt;/a&gt;可以玩玩看。&lt;/li&gt;
&lt;li&gt;swagger ui：將這工具與你的程式結合，如上章的方式，程式啟動後就會自動生成 api 前端頁面提供使用。&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;/ul&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;調整一下原本的程式碼，增加客製化的功能，並修改原本Ex3Controller、User增加REST註解，你就會發現swagger的好用。&lt;br /&gt;
&lt;ul style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;; white-space: normal;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;SwaggerConfiguration.java&lt;/span&gt;&lt;/li&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/ul&gt;
&lt;div&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;package louisz.springboot.example3;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import static springfox.documentation.builders.PathSelectors.regex;

@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
 @Bean
 public Docket usersApi() {
  return new Docket(DocumentationType.SWAGGER_2).select()
    .apis(RequestHandlerSelectors.basePackage(&quot;louisz.springboot.example3&quot;)).paths(regex(&quot;/user.*&quot;)).build()
    .apiInfo(metaData());

 }

 private ApiInfo metaData() {
  ApiInfo apiInfo = new ApiInfo(&quot;Louisz User RESTful API&quot;, &quot;Louisz User RESTful API for blog&quot;, &quot;1.0&quot;,
    &quot;Terms of service&quot;, new Contact(&quot;Louisz Cheng&quot;, &quot;#&quot;, &quot;louisz6ster@gmail.com&quot;),
    &quot;Apache License Version 2.0&quot;, &quot;https://www.apache.org/licenses/LICENSE-2.0&quot;);
  return apiInfo;
 }
}&lt;/pre&gt;
&lt;ul style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;; white-space: normal;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;Ex3Controller.java&lt;/span&gt;&lt;/li&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/ul&gt;
&lt;div&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;package louisz.springboot.example3;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

@RestController
@RequestMapping(value = &quot;/user&quot;) // 上層路徑配置
@Api(value = &quot;User Function&quot;, description = &quot;操作User的RESTful 線上文件說明&quot;) // 最上層的說明                 
public class Ex3Controller {
 // 單一儲存庫
 static Map&lt;long user=&quot;&quot;&gt; users = Collections.synchronizedMap(new HashMap&lt;long user=&quot;&quot;&gt;());

 /**
  * 取得所有User清單
  * 
  * @return
  */
 @ApiOperation(value = &quot;取得所有User清單&quot;, response = User.class)
 @ApiResponses(value = { @ApiResponse(code = 200, message = &quot;正常回覆&quot;), @ApiResponse(code = 401, message = &quot;你尚未驗證通過&quot;),
   @ApiResponse(code = 403, message = &quot;你沒有權限可以使用該功能&quot;), @ApiResponse(code = 404, message = &quot;URL錯誤&quot;) })
 @RequestMapping(value = &quot;/all&quot;, method = RequestMethod.POST)
 public List&lt;user&gt; getUserList() {
  // 取得所有User List
  return new ArrayList&lt;user&gt;(users.values());
 }

 /**
  * 新增User資料，傳入User JSON資料進行新增，成功回傳success
  * 
  * @param user
  * @return
  */
 @ApiOperation(value = &quot;新增一筆User的資料&quot;, response = Iterable.class)
 @ApiResponses(value = { @ApiResponse(code = 200, message = &quot;正常回覆&quot;), @ApiResponse(code = 401, message = &quot;你尚未驗證通過&quot;),
   @ApiResponse(code = 403, message = &quot;你沒有權限可以使用該功能&quot;), @ApiResponse(code = 404, message = &quot;URL錯誤&quot;) })
 @RequestMapping(value = &quot;/add&quot;, method = RequestMethod.POST)
 public String addUser(@ModelAttribute User user) {
  // 傳入Input JSON會自動轉換為User物件
  users.put(user.getId(), user);
  return &quot;add success&quot;;
 }

 /**
  * 傳入id進行查詢，回傳User JSON
  * 
  * @param id
  * @return
  */
 @ApiOperation(value = &quot;透過ID查詢User資料&quot;, response = User.class)
 @ApiResponses(value = { @ApiResponse(code = 200, message = &quot;正常回覆&quot;), @ApiResponse(code = 401, message = &quot;你尚未驗證通過&quot;),
   @ApiResponse(code = 403, message = &quot;你沒有權限可以使用該功能&quot;), @ApiResponse(code = 404, message = &quot;URL錯誤&quot;) })
 @RequestMapping(value = &quot;/find/{id}&quot;, method = RequestMethod.POST)
 public User findUser(@PathVariable Long id) {
  // Output User會自動轉換為JSON物件
  return users.get(id);
 }

 /**
  * 傳入id及JSON User進行資料更新
  * 
  * @param id
  * @param user
  * @return
  */
 @ApiOperation(value = &quot;更新特定User資料&quot;, response = String.class)
 @ApiResponses(value = { @ApiResponse(code = 200, message = &quot;正常回覆&quot;), @ApiResponse(code = 401, message = &quot;你尚未驗證通過&quot;),
   @ApiResponse(code = 403, message = &quot;你沒有權限可以使用該功能&quot;), @ApiResponse(code = 404, message = &quot;URL錯誤&quot;) })
 @RequestMapping(value = &quot;/update/{id}&quot;, method = RequestMethod.POST)
 public String updateUser(@PathVariable Long id, @ModelAttribute User user) {
  // 更新User資料
  User u = users.get(id);
  // System.out.println(u.getName()+&quot;=&amp;gt;&quot;+user.getMobileNumber());
  // 使用了BeanUtils
  BeanUtils.copyProperties(user, u);
  users.put(id, u);
  return &quot;update success&quot;;
 }

 /**
  * 傳入id進行資料刪除，回傳success
  * 
  * @param id
  * @return
  */
 @ApiOperation(value = &quot;刪除特定User資料&quot;, response = String.class)
 @ApiResponses(value = { @ApiResponse(code = 200, message = &quot;正常回覆&quot;), @ApiResponse(code = 401, message = &quot;你尚未驗證通過&quot;),
   @ApiResponse(code = 403, message = &quot;你沒有權限可以使用該功能&quot;), @ApiResponse(code = 404, message = &quot;URL錯誤&quot;) })
 @RequestMapping(value = &quot;/remove/{id}&quot;, method = RequestMethod.DELETE)
 public String removeUser(@PathVariable Long id) {
  // 刪除user資料
  users.remove(id);
  return &quot;delete success&quot;;
 }

}
&lt;/user&gt;&lt;/user&gt;&lt;/long&gt;&lt;/long&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;ul style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;; white-space: normal;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;User.java&lt;/span&gt;&lt;/li&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/ul&gt;
&lt;div&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;package louisz.springboot.example3;

import io.swagger.annotations.ApiModelProperty;

public class User {
 @ApiModelProperty(notes = &quot;ID&quot;, required = true)
 private Long id;
 @ApiModelProperty(notes = &quot;使用者姓名&quot;, required = true)
 private String name;
 @ApiModelProperty(notes = &quot;使用者emai&quot;, required = true)
 private String email;
 @ApiModelProperty(notes = &quot;使用者手機號碼&quot;)
 private String mobileNumber;

 public Long getId() {
  return id;
 }

 public void setId(Long id) {
  this.id = id;
 }

 public String getName() {
  return name;
 }

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

 public String getEmail() {
  return email;
 }

 public void setEmail(String email) {
  this.email = email;
 }

 public String getMobileNumber() {
  return mobileNumber;
 }

 public void setMobileNumber(String mobileNumber) {
  this.mobileNumber = mobileNumber;
 }

}&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
執行並連結到&lt;a href=&quot;http://localhost:8090/swagger-ui.html&quot;&gt;http://localhost:8090/swagger-ui.html&lt;/a&gt;，結果如圖&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilgSsXJsN_jMD1AhmHN46aMD0gKLjpnUNobX_ZFBl-66lafbNF_gSSCybkFuzztjIL7k0_FXqL3ESBLJFSbmuh7q-E_lGtMaWcW69nMuSzb4k_8g1thIKrVean0blC-9rHGmrv8hAgK0Q/s1600/Image+2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;753&quot; data-original-width=&quot;981&quot; height=&quot;245&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilgSsXJsN_jMD1AhmHN46aMD0gKLjpnUNobX_ZFBl-66lafbNF_gSSCybkFuzztjIL7k0_FXqL3ESBLJFSbmuh7q-E_lGtMaWcW69nMuSzb4k_8g1thIKrVean0blC-9rHGmrv8hAgK0Q/s320/Image+2.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; 補充完swagger，進入本章的兩個主題，自訂屬性(application.properties)及專案結構定義，之前有提到application.properties(&lt;a href=&quot;https://louiszspower.blogspot.tw/2017/06/spring-boot-v15-logging.html&quot;&gt;這裡&lt;/a&gt;)，spring boot似乎一些主要的設定資訊都是透過這裡，一 般來說大部分專案都會使用到自己所需的設定資訊都會放在檔案中，可以透過File或是&lt;a href=&quot;http://commons.apache.org/proper/commons-configuration/&quot;&gt;Apache Common Configuration&lt;/a&gt;或是其他方式進行，在spring boot當中已經把這機制放進去了，所以可以將所需的資訊放在application.properties或是resources下的其他自訂檔案中。&lt;br /&gt;
&amp;nbsp; &amp;nbsp; 在專案的開發中，分類一向都是很難決定的，因為伴隨著越來越多code，系統或專案結構就變得很重要，以下的分類方式提供給大家參考，當然有些情形是依據當下或是特定的規定進行，不過大致上這樣的分類應該可以應付大部分的專案才是，主要以Layer的概念去切割，如view、controller、model等，然後再細分下去如model.entities、model.facade、controller.service、controller.integrate等，當然也有些基本的如commons、utils，參考結構如下：&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;company(公司名稱).system(系統別).layer.patterns(design pattern)
company.project(專案).layer.functions(功能)
company.commons(通用)
company.utils(工具)
company.system.commons
company.system.utils
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;學習目的&lt;/b&gt;：使用自訂屬性設定檔、屬性一些進階的使用。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;學習時數&lt;/b&gt;：1.5 hr&lt;/span&gt;&lt;/div&gt;
&lt;b&gt;教學影片：&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/u3FJHG1Mzv8/0.jpg&quot; src=&quot;https://www.youtube.com/embed/u3FJHG1Mzv8?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;br /&gt;
&lt;ul style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;; white-space: normal;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;ExampleProperties.java&lt;/span&gt;&lt;/li&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/ul&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;package louisz.springboot.example4;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

@Component // DI之後介紹
@PropertySource(&quot;classpath:example4.properties&quot;) //設定自訂的設定檔檔名及路徑
@ConfigurationProperties(&quot;app&quot;) //prefix
public class ExampleProperties {
 //@Value(&quot;${app.name}&quot;) 也可以採用這種方式，這樣name可以不用相同，但是不建議
 //，因為後續不好維護
 private String name;
 
 private String version;
 
 private String nameversion;
 
 private String stringvalue;
 private int intvalue;
 private long longvalue;
 private int tenvalue;
 private int twentyvalue;
 
 
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public String getVersion() {
  return version;
 }
 public void setVersion(String version) {
  this.version = version;
 }
 public String getNameversion() {
  return nameversion;
 }
 public void setNameversion(String nameversion) {
  this.nameversion = nameversion;
 }
 public String getStringvalue() {
  return stringvalue;
 }
 public void setStringvalue(String stringvalue) {
  this.stringvalue = stringvalue;
 }
 public int getIntvalue() {
  return intvalue;
 }
 public void setIntvalue(int intvalue) {
  this.intvalue = intvalue;
 }
 public long getLongvalue() {
  return longvalue;
 }
 public void setLongvalue(long longvalue) {
  this.longvalue = longvalue;
 }
 public int getTenvalue() {
  return tenvalue;
 }
 public void setTenvalue(int tenvalue) {
  this.tenvalue = tenvalue;
 }
 public int getTwentyvalue() {
  return twentyvalue;
 }
 public void setTwentyvalue(int twentyvalue) {
  this.twentyvalue = twentyvalue;
 }

 
}

&lt;/pre&gt;
&lt;ul style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;; white-space: normal;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;TestExampleProperties.java&lt;/span&gt;&lt;/li&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/ul&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;package louisz.springboot.example4;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.test.context.junit4.SpringRunner;


//spring boot 1.4以後的方式
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)
public class TestExampleProperties {
 @Autowired
 private ExampleProperties exampleProperties;//注入
 
 @Test
 public void getHello() throws Exception {
  //驗證是否符合預期
  Assert.assertEquals(exampleProperties.getName(), &quot;example4&quot;);
  Assert.assertEquals(exampleProperties.getVersion(), &quot;1&quot;);
  Assert.assertEquals(exampleProperties.getNameversion(), &quot;example4_1&quot;);
  System.out.println(exampleProperties.getIntvalue());
  System.out.println(exampleProperties.getTwentyvalue());
 }
 
}

&lt;/pre&gt;
&lt;a href=&quot;https://github.com/louisz6ster/spring_boot&quot; style=&quot;font-size: x-large;&quot;&gt;Github code&lt;/a&gt;&lt;span style=&quot;font-size: large;&quot;&gt;(louisz.springboot.example4)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
參考連結：&lt;br /&gt;
&lt;a href=&quot;https://springframework.guru/using-logback-spring-boot/&quot;&gt;http://blog.didispace.com/springbootproperties/&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://louiszspower.blogspot.com/feeds/728357600275553105/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://louiszspower.blogspot.com/2017/06/spring-boot-v15-swaggerproperties-and.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/728357600275553105'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/728357600275553105'/><link rel='alternate' type='text/html' href='http://louiszspower.blogspot.com/2017/06/spring-boot-v15-swaggerproperties-and.html' title='Spring boot v1.5 (四) swagger,properties and structing your code'/><author><name>Louisz</name><uri>http://www.blogger.com/profile/15227162328934605700</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuq5rOe6t7hT-kppa8Fu3eLB6RzgYqY8I7hZyMmMKyeAVUNbzRxsj7SQQA1EyynM-Ac6FjR6PmyXhcfn6PiIsBkByRyY8nSu3CWpAlXTcOcfGjpUDCpSBge2ou1j770EY/s220/IMG_20170629_210051.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilgSsXJsN_jMD1AhmHN46aMD0gKLjpnUNobX_ZFBl-66lafbNF_gSSCybkFuzztjIL7k0_FXqL3ESBLJFSbmuh7q-E_lGtMaWcW69nMuSzb4k_8g1thIKrVean0blC-9rHGmrv8hAgK0Q/s72-c/Image+2.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553741655215810943.post-8055715857400751542</id><published>2017-06-25T05:23:00.000-07:00</published><updated>2017-06-27T01:05:34.257-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Spring boot"/><title type='text'>Spring boot v1.5 (三) magic RESTful and some swagger</title><content type='html'>&amp;nbsp; &amp;nbsp; 會用Magic來形容Spring boot的RESTful，一方面是微服務的架構，另一方面則是透過Spring boot真得很容易完成，本篇開始也就會一些專案的經驗帶進來。&lt;br /&gt;
&amp;nbsp; &amp;nbsp; 簡單介紹一下REST(Representational State Transfer)，具象狀態的傳輸，Wiki是這樣說明的，其實它的出現，主要是因為原本的Web Service太過複雜太謹慎了，SOAP跟XML-RPC不容易讓人一下子就了解，在這惟快不破的時代，時間就是金錢，所以REST的出現，讓原本比較難的Web Service變得簡單易懂，而且也容易上手，有些要點可以參&lt;a href=&quot;https://zh.wikipedia.org/wiki/REST&quot;&gt;這裡&lt;/a&gt;都有說明可以看看，對於微服務來說，無狀態很重要，未來架構設計也應該朝向無狀態，不然很難處理日益暴漲的量，符合REST設計風格的Web API稱為RESTful API，這就是我們常說的RESTful，比Web Service多了幾種操作方式，分別為get、post、put、delete、patch及head等(當然還有其他的)，差別在&lt;a href=&quot;https://data-sci.info/2015/10/24/%E5%B8%B8%E8%A6%8B%E7%9A%84http-method%E7%9A%84%E4%B8%8D%E5%90%8C%E6%80%A7%E8%B3%AA%E5%88%86%E6%9E%90%EF%BC%9Agetpost%E5%92%8C%E5%85%B6%E4%BB%964%E7%A8%AEmethod%E7%9A%84%E5%B7%AE%E5%88%A5/&quot;&gt;這裡&lt;/a&gt;可以參考看看，Web Service有wsdl，那RESTful有嗎？答案就是Swagger，已經可以算是RESTful的標準了，Spring boot整合swagger也是很無縫地喔。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;學習目的&lt;/b&gt;：建立一個REST的Controller，並包含了單元測試(Mockito)，以及Swagger的設定。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;學習時數&lt;/b&gt;：2.5 hr&lt;/span&gt;&lt;/div&gt;
&lt;b&gt;教學影片：&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe allowfullscreen=&quot;&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/Fr1gAL2VA0s/0.jpg&quot; frameborder=&quot;0&quot; height=&quot;266&quot; src=&quot;https://www.youtube.com/embed/Fr1gAL2VA0s?feature=player_embedded&quot; width=&quot;320&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;pom.xml 說明&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;spring-boot-starter-web:配置 Web Project所需的函式庫
spring-boot-starter-test:配置 unit or mock test 所需的函式庫
spring-boot-starter-actuator:配置監控spring boot所需的函式庫&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;
&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;springfox-swagger2:配置swagger 2 api所需的函式庫&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;springfox-swagger-ui:配置swagger ui所需的函式庫&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;b style=&quot;font-family: &amp;quot;times new roman&amp;quot;; white-space: normal;&quot;&gt;程式碼說明&lt;/b&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;b style=&quot;font-family: &amp;quot;times new roman&amp;quot;; white-space: normal;&quot;&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;ul style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;; white-space: normal;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;Example3.java&lt;/span&gt;&lt;/li&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/ul&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;; white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;

&lt;br /&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;package louisz.springboot.example3;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * Louisz Spring boot introduce ex.3
 *
 */

@SpringBootApplication
public class Example3 {
 /**
  * 程式執行起點
  * 
  * @param args
  */
 public static void main(String[] args) {
  SpringApplication.run(Example3.class, args);

 }

}
&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;; white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;ul style=&quot;font-family: &amp;quot;times new roman&amp;quot;; font-weight: normal; white-space: normal;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;; white-space: normal;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;Ex3Controller.java&lt;/span&gt;&lt;/li&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/ul&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;; white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;

&lt;br /&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;package louisz.springboot.example3;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = &quot;/user&quot;) // 上層路徑配置
public class Ex3Controller {
 //單一儲存庫
 static Map&lt;long user=&quot;&quot;&gt; users = Collections.synchronizedMap(new HashMap&lt;long user=&quot;&quot;&gt;());

 /**
  * 取得所有User清單
  * 
  * @return
  */
 @RequestMapping(value = &quot;/all&quot;, method = RequestMethod.POST)
 public List&lt;user&gt; getUserList() {
  // 取得所有User List
  return new ArrayList&lt;user&gt;(users.values());
 }

 /**
  * 新增User資料，傳入User JSON資料進行新增，成功回傳success
  * 
  * @param user
  * @return
  */
 @RequestMapping(value = &quot;/add&quot;, method = RequestMethod.POST)
 public String addUser(@ModelAttribute User user) {
  // 傳入Input JSON會自動轉換為User物件
  users.put(user.getId(), user);
  return &quot;add success&quot;;
 }

 /**
  * 傳入id進行查詢，回傳User JSON
  * 
  * @param id
  * @return
  */
 @RequestMapping(value = &quot;/find/{id}&quot;, method = RequestMethod.POST)
 public User findUser(@PathVariable Long id) {
  // Output User會自動轉換為JSON物件
  return users.get(id);
 }

 /**
  * 傳入id及JSON User進行資料更新
  * 
  * @param id
  * @param user
  * @return
  */
 @RequestMapping(value = &quot;/update/{id}&quot;, method = RequestMethod.POST)
 public String updateUser(@PathVariable Long id, @ModelAttribute User user) {
  // 更新User資料
  User u = users.get(id);
//  System.out.println(u.getName()+&quot;=&amp;gt;&quot;+user.getMobileNumber());
  // 使用了BeanUtils
  BeanUtils.copyProperties(user, u);
  users.put(id, u);
  return &quot;update success&quot;;
 }

 /**
  * 傳入id進行資料刪除，回傳success
  * 
  * @param id
  * @return
  */
 @RequestMapping(value = &quot;/remove/{id}&quot;, method = RequestMethod.DELETE)
 public String removeUser(@PathVariable Long id) {
  //刪除user資料
  users.remove(id);
  return &quot;delete success&quot;;
 }

}


}
&lt;/user&gt;&lt;/user&gt;&lt;/long&gt;&lt;/long&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;; white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;

&lt;br /&gt;
&lt;div style=&quot;font-family: &amp;quot;times new roman&amp;quot;; font-weight: bold; white-space: normal;&quot;&gt;
&lt;ul style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;; white-space: normal;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;User.java&lt;/span&gt;&lt;/li&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/ul&gt;
&lt;/div&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;package louisz.springboot.example3;

public class User {
 private Long id;
 private String name;
 private String email;
 private String mobileNumber;
 public Long getId() {
  return id;
 }
 public void setId(Long id) {
  this.id = id;
 }
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public String getEmail() {
  return email;
 }
 public void setEmail(String email) {
  this.email = email;
 }
 public String getMobileNumber() {
  return mobileNumber;
 }
 public void setMobileNumber(String mobileNumber) {
  this.mobileNumber = mobileNumber;
 }

}
&lt;/pre&gt;
&lt;ul style=&quot;font-family: &amp;quot;times new roman&amp;quot;; white-space: normal;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;; white-space: normal;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;SwaggerConfiguration.java&lt;/span&gt;&lt;/li&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/ul&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;package louisz.springboot.example3;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import static springfox.documentation.builders.PathSelectors.regex;

@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
 @Bean
 public Docket usersApi() {
  return new Docket(DocumentationType.SWAGGER_2).select()
    .apis(RequestHandlerSelectors.basePackage(&quot;louisz.springboot.example3&quot;)).paths(regex(&quot;/user.*&quot;))
    .build();

 }
}

&lt;/pre&gt;
&lt;br /&gt;
&lt;ul style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;; white-space: normal;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;TestEx3Controller.java(單元測試，請注意註解部分說明)&lt;/span&gt;&lt;/li&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/ul&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;package louisz.springboot.example3;

//這邊要注意import的方式採用static
import static org.hamcrest.Matchers.equalTo;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.RequestBuilder;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

//spring boot 1.4以後的方式
@RunWith(SpringRunner.class)
@WebMvcTest(Ex3Controller.class)
public class TestEx3Controller {
 @Autowired
 private MockMvc mvc;

 /**
  * 單元測試測試前前置設定
  * 
  * @throws Exception
  */
 @Before
 public void setUp() throws Exception {
  mvc = MockMvcBuilders.standaloneSetup(new Ex3Controller()).build();
 }

 /**
  * 測試範例三的RestController各項method
  * 
  * @throws Exception
  */
 @Test
 public void testEx3Controller() throws Exception {
  /*
   * 撰寫單元測試的時候，先想清楚要測試的流程，例如本範例為測試新增修改刪除功能，
   * 你可以一個一個method測試，你也可以使用先新增一筆，然後進行修改，再查詢後刪 除等，把單元測試想做一個情境會比較好進行撰寫。
   */

  RequestBuilder request = null;
  // 我這裡設定使用post進行查詢
  // 1.測試是否回覆200的訊息，並且確認是否尚無資料
  request = post(&quot;/users/all/&quot;);
  mvc.perform(request).andExpect(status().isOk()).andExpect(content().string(equalTo(&quot;[]&quot;)));
  // 2.新增一筆資料，新增成功後須回覆success的資訊
  request = post(&quot;/users/add/&quot;).param(&quot;id&quot;, &quot;1&quot;).param(&quot;name&quot;, &quot;Louisz&quot;).param(&quot;email&quot;, &quot;louisz6ster@gmail.com&quot;)
    .param(&quot;mobileNumber&quot;, &quot;0912345678&quot;);
  mvc.perform(request).andExpect(content().string(equalTo(&quot;success&quot;)));
  // 3.再進行查詢，因為只有一筆不用特別指定，確認回覆的資訊是否與預期相同
  request = post(&quot;/users/all/&quot;);
  mvc.perform(request).andExpect(status().isOk()).andExpect(content().string(equalTo(
    &quot;[{\&quot;id\&quot;:1,\&quot;name\&quot;:\&quot;Louisz\&quot;,\&quot;email\&quot;:\&quot;louisz6ster@gmail.com\&quot;,\&quot;mobileNumber\&quot;:\&quot;0912345678\&quot;}]&quot;)));
  // 4.修改原有資訊資料，修改成功後須回覆success的資訊
  request = post(&quot;/users/update/1&quot;).param(&quot;name&quot;, &quot;Jessie&quot;).param(&quot;email&quot;, &quot;louisz6ster@gmail.com&quot;)
    .param(&quot;mobileNumber&quot;, &quot;0923456789&quot;);
  mvc.perform(request).andExpect(content().string(equalTo(&quot;success&quot;)));
  // 5.使用指定查詢進行該資料比對，確認修改的資訊是否正確
  request = post(&quot;/users/find/1&quot;);
  mvc.perform(request).andExpect(content().string(equalTo(
    &quot;{\&quot;id\&quot;:1,\&quot;name\&quot;:\&quot;Jessie\&quot;,\&quot;email\&quot;:\&quot;louisz6ster@gmail.com\&quot;,\&quot;mobileNumber\&quot;:\&quot;0923456789\&quot;}&quot;)));

  // 6.刪除指定的資料，刪除成功後須回覆success
  request = delete(&quot;/users/remove/1&quot;);
  mvc.perform(request).andExpect(content().string(equalTo(&quot;success&quot;)));

  // 7.最後再查詢一次全部資料，須回覆空值，表示單元測試完成
  request = post(&quot;/users/all/&quot;);
  mvc.perform(request).andExpect(status().isOk()).andExpect(content().string(equalTo(&quot;[]&quot;)));
 }
}

&lt;/pre&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;&lt;b&gt;先進行單元測試，然後執行程式使用 POSTMAN 測試&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;測試網址&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: large; white-space: normal;&quot;&gt;&lt;a href=&quot;http://localhost:8090/user&quot;&gt;http://localhost:8090/user&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;Swagger-ui網址&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: large; white-space: normal;&quot;&gt;&lt;a href=&quot;http://localhost:8090/swagger-ui.html&quot;&gt;http://localhost:8090/swagger-ui.html&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;Swagger-api網址&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: large; white-space: normal;&quot;&gt;&lt;a href=&quot;http://localhost:8090/v2/api-docs&quot;&gt;http://localhost:8090/v2/api-docs&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;a href=&quot;https://github.com/louisz6ster/spring_boot&quot; style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;; font-size: x-large; white-space: normal;&quot;&gt;Github code&lt;/a&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;; font-size: large; white-space: normal;&quot;&gt;(louisz.springboot.example3)&lt;/span&gt;



&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;; font-size: large; white-space: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;; font-size: large; white-space: normal;&quot;&gt;swagger待續....&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;; font-size: large; white-space: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
參考連結：&lt;br /&gt;
&lt;a href=&quot;https://springframework.guru/spring-boot-restful-api-documentation-with-swagger-2/&quot;&gt;https://springframework.guru/spring-boot-restful-api-documentation-with-swagger-2/&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://blog.didispace.com/springbootswagger2/&quot;&gt;http://blog.didispace.com/springbootswagger2/&lt;/a&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;; font-size: large; white-space: normal;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;https://zh.wikipedia.org/wiki/REST&quot;&gt;https://zh.wikipedia.org/wiki/REST&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;https://data-sci.info/2015/10/24/%E5%B8%B8%E8%A6%8B%E7%9A%84http-method%E7%9A%84%E4%B8%8D%E5%90%8C%E6%80%A7%E8%B3%AA%E5%88%86%E6%9E%90%EF%BC%9Agetpost%E5%92%8C%E5%85%B6%E4%BB%964%E7%A8%AEmethod%E7%9A%84%E5%B7%AE%E5%88%A5/&quot;&gt;https://data-sci.info/2015/10/24/%E5%B8%B8%E8%A6%8B%E7%9A%84http-method%E7%9A%84%E4%B8%8D%E5%90%8C%E6%80%A7%E8%B3%AA%E5%88%86%E6%9E%90%EF%BC%9Agetpost%E5%92%8C%E5%85%B6%E4%BB%964%E7%A8%AEmethod%E7%9A%84%E5%B7%AE%E5%88%A5/&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://louiszspower.blogspot.com/feeds/8055715857400751542/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://louiszspower.blogspot.com/2017/06/spring-boot-v15-magic-restful-and.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/8055715857400751542'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/8055715857400751542'/><link rel='alternate' type='text/html' href='http://louiszspower.blogspot.com/2017/06/spring-boot-v15-magic-restful-and.html' title='Spring boot v1.5 (三) magic RESTful and some swagger'/><author><name>Louisz</name><uri>http://www.blogger.com/profile/15227162328934605700</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuq5rOe6t7hT-kppa8Fu3eLB6RzgYqY8I7hZyMmMKyeAVUNbzRxsj7SQQA1EyynM-Ac6FjR6PmyXhcfn6PiIsBkByRyY8nSu3CWpAlXTcOcfGjpUDCpSBge2ou1j770EY/s220/IMG_20170629_210051.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/Fr1gAL2VA0s/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553741655215810943.post-2700913092867342843</id><published>2017-06-20T07:48:00.000-07:00</published><updated>2017-06-25T00:21:23.832-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Spring boot"/><title type='text'>Spring boot v1.5 (二) logging</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;本篇主要介紹Logging的機制，Spring boot預設為logback framework，在開始之前先給大家熱身一下，每次執行Spring boot程式在Console上都會看到Spring的Banner如下&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdNp_g8zxjXY7FzGD-AGYMaRTXWx-7zHRXwNwgIVJCutJ4EoSPCeH_FQBHXGcpI30SFAuA69bZxJAPMJYMiitvm0M0ogTF0uzEnRWie-ZW14Ub_CoG-Ip8NcJaaMxxCaT9NjDQ9Q_5mhs/s1600/Image+1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;139&quot; data-original-width=&quot;357&quot; height=&quot;124&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdNp_g8zxjXY7FzGD-AGYMaRTXWx-7zHRXwNwgIVJCutJ4EoSPCeH_FQBHXGcpI30SFAuA69bZxJAPMJYMiitvm0M0ogTF0uzEnRWie-ZW14Ub_CoG-Ip8NcJaaMxxCaT9NjDQ9Q_5mhs/s320/Image+1.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;這Banner可以自訂喔，可以在google輸入ascii generator關鍵字，就可以找到很多產生這Banner文件，我使用的是&lt;a href=&quot;http://www.network-science.de/ascii/&quot;&gt;這個&lt;/a&gt;，然後在/src/main/resources目錄中增加一個banner.txt檔案，然後把產生出來的Code複製到banner.txt的檔案上，也可以透過簡單的設定加上一些顏色&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;banner.txt&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;${AnsiColor.BRIGHT_BLUE}


 _        _______          _________ _______  _______ 
( \      (  ___  )|\     /|\__   __/(  ____ \/ ___   )
| (      | (   ) || )   ( |   ) (   | (    \/\/   )  |
| |      | |   | || |   | |   | |   | (_____     /   )
| |      | |   | || |   | |   | |   (_____  )   /   / 
| |      | |   | || |   | |   | |         ) |  /   /  
| (____/\| (___) || (___) |___) (___/\____) | /   (_/\
(_______/(_______)(_______)\_______/\_______)(_______/
                                                      
${AnsiColor.BRIGHT_GREEN}
Application Version: ${application.version}${application.formatted-version}
Spring Boot Version: ${spring-boot.version}${spring-boot.formatted-version}&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;有點跑掉不過執行結果如下：&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-C5D7O35dQyXWH_prtdR5uXuGIcFj1mzni53IjVefH2dECGkPKVM6QCFFg8bvpEZvmfD8WMw9YKT7RjcIcOpRweb3X8LD4sG2aAWFnPHC2gQxm8TNCxWlXEdUHlrJZhbcqJKM8Wo5t6c/s1600/Image+3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;237&quot; data-original-width=&quot;634&quot; height=&quot;119&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-C5D7O35dQyXWH_prtdR5uXuGIcFj1mzni53IjVefH2dECGkPKVM6QCFFg8bvpEZvmfD8WMw9YKT7RjcIcOpRweb3X8LD4sG2aAWFnPHC2gQxm8TNCxWlXEdUHlrJZhbcqJKM8Wo5t6c/s320/Image+3.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
這個banner.txt後續也會有一些實質的幫助喔。&lt;br /&gt;
&lt;br /&gt;
Logging在程式開發中是一個基本、必要且非常重要的一項工作，先跟大家說明之後相關範例說明都有 log 可以查看相當方便，也可以習慣這樣的方式，不要甚麼都是System.out，在一個專案或是系統建置成功與否，logging機制相當重要，然後上線後的維運、遇到問題更是仰賴的根本，只要能知道原因就能解決，想要知道原因就一定要很清楚logging的處理方式。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;ol&gt;&lt;ul&gt;
&lt;/ul&gt;
&lt;/ol&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;學習目的&lt;/b&gt;：使用logback進行log。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;學習時數&lt;/b&gt;：1.5 hr&lt;/span&gt;&lt;/div&gt;
&lt;b&gt;教學影片：&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe allowfullscreen=&quot;&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i9.ytimg.com/vi/KrN3pc8UBaA/default.jpg?sqp=COzppMoF&amp;amp;rs=AOn4CLCGtJDZRhVltdXPym1zptbKRHfjWw&quot; frameborder=&quot;0&quot; height=&quot;266&quot; src=&quot;https://www.youtube.com/embed/KrN3pc8UBaA?feature=player_embedded&quot; width=&quot;320&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;b&gt;pom.xml 說明(logback為預設值，不用額外設定，同Spring boot v1.5(一))&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;spring-boot-starter-web:配置 Web Project所需的函式庫
spring-boot-starter-test:配置 unit or mock test 所需的函式庫
spring-boot-starter-actuator:配置監控spring boot所需的函式庫，後續spring cloud會使用到，所以一開就導入&lt;/span&gt;
&lt;/pre&gt;
&lt;b style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;application.properties說明&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;#應用程式名稱
spring.application.name=Louisz Spring boot

#程式啟動 listener port or server.port = 0 自動
server.port = 8090

#選擇需要紀錄的package
logging.level.org.springframework.web=DEBUG
logging.level.louisz.springboot.example2=DEBUG

#將log記錄到指定的檔案中
logging.file=louisz.log

#顯示可以有色彩的屬性
spring.output.ansi.enabled= always

#建議使用logback設定檔案
logging.config=src/main/resources/logback-spring.xml
&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;b&gt;在 /src/main/resources/ 下增加 logback-spring.xml設定檔，簡易內容如下：&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;gt;
&amp;lt;configuration&amp;gt;
    &amp;lt;!-- 使用預設值得base.xml --&amp;gt;
    &amp;lt;include resource=&quot;org/springframework/boot/logging/logback/base.xml&quot;/&amp;gt;
    &amp;lt;!-- 選擇要記錄的package，並設定只要大於等於debug等級，就記錄下來 --&amp;gt;
    &amp;lt;logger name=&quot;org.springframework.web&quot; level=&quot;DEBUG&quot;/&amp;gt;
&amp;lt;/configuration&amp;gt;
&lt;/pre&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;run example2
&lt;/pre&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;測試以下幾個網址，是否有log下來相關資訊&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: large; white-space: normal;&quot;&gt;&lt;a href=&quot;http://localhost:8090/log_debug&quot;&gt;http://localhost:8090/log_debug&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: large; white-space: normal;&quot;&gt;&lt;a href=&quot;http://localhost:8090/log_info&quot;&gt;http://localhost:8090/log_info&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;b&gt;進階版的 logback 設定&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;
&amp;lt;!-- &amp;lt;configuration&amp;gt;
    使用logback的基本設定
    &amp;lt;include resource=&quot;org/springframework/boot/logging/logback/base.xml&quot;/&amp;gt;
    指定特定目錄進行log，等級設為WARN，分別記錄在Console及檔案 
    &amp;lt;logger name=&quot;louisz.springboot.example1&quot; level=&quot;WARN&quot; additivity=&quot;false&quot;&amp;gt;
        &amp;lt;appender-ref ref=&quot;CONSOLE&quot;/&amp;gt;
        &amp;lt;appender-ref ref=&quot;FILE&quot;/&amp;gt;
    &amp;lt;/logger&amp;gt;
    指定特定目錄進行log，等級設為DEBUG，分別記錄在Console及檔案 
    &amp;lt;logger name=&quot;louisz.springboot.example2&quot; level=&quot;DEBUG&quot; additivity=&quot;true&quot;&amp;gt;
        &amp;lt;appender-ref ref=&quot;CONSOLE&quot;/&amp;gt;
        &amp;lt;appender-ref ref=&quot;FILE&quot;/&amp;gt;
    &amp;lt;/logger&amp;gt;
 &amp;lt;/configuration&amp;gt; --&amp;gt;
 &amp;lt;!-- 全部進行Debug level紀錄，並且每30秒監控設定檔是否有異動 --&amp;gt;
&amp;lt;configuration debug=&quot;true&quot; scan=&quot;true&quot; scanPeriod=&quot;30 seconds&quot;&amp;gt;
     &amp;lt;!-- 記錄檔存放路徑 --&amp;gt;
    &amp;lt;property name=&quot;LOG_PATH&quot; value=&quot;logs&quot; /&amp;gt;
    &amp;lt;!-- 歷史記錄檔存放路徑 --&amp;gt;
    &amp;lt;property name=&quot;LOG_ARCHIVE&quot; value=&quot;${LOG_PATH}/archive&quot; /&amp;gt;
    &amp;lt;!-- 檔名規則 --&amp;gt;
    &amp;lt;timestamp key=&quot;timestamp-by-second&quot; datePattern=&quot;yyyyMMdd&#39;T&#39;HHmmss&quot;/&amp;gt;
    &amp;lt;appender name=&quot;Console-Appender&quot; class=&quot;ch.qos.logback.core.ConsoleAppender&quot;&amp;gt;
        &amp;lt;layout&amp;gt;
            &amp;lt;!-- 紀錄存放格式 --&amp;gt;
            &amp;lt;pattern&amp;gt;%d %-5level [%thread] %logger{0} : %msg%n&amp;lt;/pattern&amp;gt;
        &amp;lt;/layout&amp;gt;
    &amp;lt;/appender&amp;gt;
    &amp;lt;!-- 歷史記錄檔搬移規則及存放路徑 --&amp;gt;
    &amp;lt;appender name=&quot;File-Appender&quot; class=&quot;ch.qos.logback.core.FileAppender&quot;&amp;gt;
        &amp;lt;file&amp;gt;${LOG_PATH}/logfile-${timestamp-by-second}.log&amp;lt;/file&amp;gt;
        &amp;lt;encoder&amp;gt;
            &amp;lt;pattern&amp;gt;%d %-5level [%thread] %logger{0} : %msg%n&amp;lt;/pattern&amp;gt;
            &amp;lt;!-- 套用格式規則置頂 --&amp;gt;
            &amp;lt;outputPatternAsHeader&amp;gt;true&amp;lt;/outputPatternAsHeader&amp;gt;
        &amp;lt;/encoder&amp;gt;
    &amp;lt;/appender&amp;gt;
    &amp;lt;!-- 記錄檔異動規則 --&amp;gt;
    &amp;lt;appender name=&quot;RollingFile-Appender&quot; class=&quot;ch.qos.logback.core.rolling.RollingFileAppender&quot;&amp;gt;
        &amp;lt;file&amp;gt;${LOG_PATH}/rollingfile.log&amp;lt;/file&amp;gt;
        &amp;lt;rollingPolicy class=&quot;ch.qos.logback.core.rolling.TimeBasedRollingPolicy&quot;&amp;gt;
            &amp;lt;fileNamePattern&amp;gt;${LOG_ARCHIVE}/rollingfile.log%d{yyyy-MM-dd}.log&amp;lt;/fileNamePattern&amp;gt;
            &amp;lt;maxHistory&amp;gt;30&amp;lt;/maxHistory&amp;gt;
            &amp;lt;totalSizeCap&amp;gt;1KB&amp;lt;/totalSizeCap&amp;gt;
        &amp;lt;/rollingPolicy&amp;gt;
        &amp;lt;encoder&amp;gt;
            &amp;lt;pattern&amp;gt;%d %-5level [%thread] %logger{0} : %msg%n&amp;lt;/pattern&amp;gt;
        &amp;lt;/encoder&amp;gt;
    &amp;lt;/appender&amp;gt;
    &amp;lt;!-- 非同步方式進行紀錄 --&amp;gt;
    &amp;lt;appender name=&quot;Async-Appender&quot; class=&quot;ch.qos.logback.classic.AsyncAppender&quot;&amp;gt;
        &amp;lt;!-- 套用至RollingFile-Appender --&amp;gt;
        &amp;lt;appender-ref ref=&quot;RollingFile-Appender&quot; /&amp;gt;
    &amp;lt;/appender&amp;gt;
  &amp;lt;!-- 紀錄套用package、level等 --&amp;gt;
    &amp;lt;logger name=&quot;louisz.springboot.example2&quot;  level=&quot;debug&quot; additivity=&quot;false&quot;&amp;gt;
        &amp;lt;appender-ref ref=&quot;Console-Appender&quot; /&amp;gt;
        &amp;lt;appender-ref ref=&quot;File-Appender&quot; /&amp;gt;
        &amp;lt;appender-ref ref=&quot;Async-Appender&quot; /&amp;gt;
    &amp;lt;/logger&amp;gt;
    &amp;lt;root&amp;gt;
        &amp;lt;appender-ref ref=&quot;Console-Appender&quot; /&amp;gt;
    &amp;lt;/root&amp;gt;
&amp;lt;/configuration&amp;gt;
&lt;/span&gt;
&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;b style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;程式碼說明&lt;/b&gt;&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;Example2.java&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;package louisz.springboot.example2;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * Louisz Spring boot introduce ex.2
 *
 */

@SpringBootApplication
public class Example2 {
 /**
  * 程式執行起點
  * 
  * @param args
  */
 public static void main(String[] args) {
  SpringApplication.run(Example2.class, args);

 }

}
&lt;/span&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;Ex2Controller.java&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;package louisz.springboot.example2;

//採用的是slf4j外框
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Ex2Controller {
 //請注意不要用static，才能使用this.getClass
  private final Logger logger = LoggerFactory.getLogger(this.getClass()); 
 
  //log level 設定為debug
 @RequestMapping(&quot;/log_debug&quot;)
    public String debug() {
  logger.debug(&quot;This is debug msg.&quot;);  
        return &quot;debug level&quot;;
    } 
  //log level 設定為info
 @RequestMapping(&quot;/log_info&quot;)
    public String info() {
  logger.info(&quot;This is info msg.&quot;);  
        return &quot;info level&quot;;
    } 
  //log level 設定為error
 @RequestMapping(&quot;/log_error&quot;)
    public String error() {
  logger.debug(&quot;This is error msg.&quot;);  
        return &quot;error level&quot;;
    } 
 
}

&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;a href=&quot;https://github.com/louisz6ster/spring_boot&quot;&gt;Github code&lt;/a&gt;(louisz.springboot.example2)

&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
參考連結：&lt;br /&gt;
&lt;a href=&quot;https://springframework.guru/using-logback-spring-boot/&quot;&gt;https://springframework.guru/using-logback-spring-boot/&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;https://springframework.guru/logback-configuration-using-xml/&quot;&gt;https://springframework.guru/logback-configuration-using-xml/&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://blog.didispace.com/spring-boot-banner/&quot;&gt;http://blog.didispace.com/spring-boot-banner/&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://louiszspower.blogspot.com/feeds/2700913092867342843/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://louiszspower.blogspot.com/2017/06/spring-boot-v15-logging.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/2700913092867342843'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/2700913092867342843'/><link rel='alternate' type='text/html' href='http://louiszspower.blogspot.com/2017/06/spring-boot-v15-logging.html' title='Spring boot v1.5 (二) logging'/><author><name>Louisz</name><uri>http://www.blogger.com/profile/15227162328934605700</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuq5rOe6t7hT-kppa8Fu3eLB6RzgYqY8I7hZyMmMKyeAVUNbzRxsj7SQQA1EyynM-Ac6FjR6PmyXhcfn6PiIsBkByRyY8nSu3CWpAlXTcOcfGjpUDCpSBge2ou1j770EY/s220/IMG_20170629_210051.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdNp_g8zxjXY7FzGD-AGYMaRTXWx-7zHRXwNwgIVJCutJ4EoSPCeH_FQBHXGcpI30SFAuA69bZxJAPMJYMiitvm0M0ogTF0uzEnRWie-ZW14Ub_CoG-Ip8NcJaaMxxCaT9NjDQ9Q_5mhs/s72-c/Image+1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553741655215810943.post-4791930490101030982</id><published>2017-06-16T09:23:00.001-07:00</published><updated>2017-06-25T00:23:10.345-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Spring boot"/><title type='text'>Spring boot v1.5 (一) introduce</title><content type='html'>&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;在&lt;b&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Microservices&quot;&gt;微服務(microservice)&lt;/a&gt;&lt;/b&gt;當道的時代，快速已經成為王道的代名詞，然而實現他概念的架構不得不提到&lt;a href=&quot;https://projects.spring.io/spring-boot/&quot;&gt;Spring boot&lt;/a&gt;和&lt;a href=&quot;http://projects.spring.io/spring-cloud/&quot;&gt;Spring Cloud&lt;/a&gt;，當然還有DevOps、Container(Moby(Docker))等等(本系列會帶到這些觀念，但是會另外在其他章節來說明，我認為的微服務是怎樣的東西)，所以本系列看標題也可以知道都是Spring boot的介紹跟我遇到的一些問題及想法，希望看的人可以快速進入Spring boot，開發真的不難，難的是改變。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;本系列文章大致分為&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;介紹說明本次學習目的及學習預計完成時間&lt;/span&gt;&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;說明學習目的&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;預計完成時數&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;影片&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;程式碼及設定檔相關分析說明&lt;/span&gt;&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;pom.xml說明&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;.properties or yml設定檔說明&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;程式碼說明&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;其他&lt;/span&gt;&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;遭遇到的問題&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;參考連結&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;Code Example Github連結&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ol&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;學習目的&lt;/b&gt;：快速完成一隻Spring boot程式，並加入改 listener port及監控機制。&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;學習時數&lt;/b&gt;：1.5 hr&lt;/span&gt;&lt;/div&gt;
&lt;b&gt;教學影片：&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe allowfullscreen=&quot;&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i9.ytimg.com/vi/tsPe9_FEc2c/default.jpg?sqp=CLCKkMoF&amp;amp;rs=AOn4CLCaEhln3GP-GdsI0m8OD1mOxmiozg&quot; frameborder=&quot;0&quot; height=&quot;266&quot; src=&quot;https://www.youtube.com/embed/tsPe9_FEc2c?feature=player_embedded&quot; width=&quot;320&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;pom.xml 說明&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;spring-boot-starter-web:配置 Web Project所需的函式庫
spring-boot-starter-test:配置 unit or mock test 所需的函式庫
spring-boot-starter-actuator:配置監控spring boot所需的函式庫，後續spring cloud會使用到，所以一開就導入&lt;/span&gt;
&lt;/pre&gt;
&lt;b style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;; white-space: normal;&quot;&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;; white-space: normal;&quot;&gt;程式碼說明&lt;/b&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;Example1.java&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;
&lt;/span&gt;
&lt;br /&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;package louisz.springboot.introduce;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * Louisz Spring boot introduce ex.1
 *
 */

@SpringBootApplication
public class Example1 {
 /**
  * 程式執行起點
  * 
  * @param args
  */
 public static void main(String[] args) {
  SpringApplication.run(Example1.class, args);

 }

}

&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;Ex1Controller.java&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;package louisz.springboot.introduce;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * Louisz Spring boot introduce ex.1
 *
 */

@SpringBootApplication
public class Example1 {
 /**
  * 程式執行起點
  * 
  * @param args
  */
 public static void main(String[] args) {
  SpringApplication.run(Example1.class, args);

 }

}
&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;&lt;b&gt;執行時請加上-Dserver.port=8090，就可以啟動時選擇要Listener Port&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;測試以下幾個網址是否正常&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: large; white-space: normal;&quot;&gt;&lt;a href=&quot;http://localhost:8090/&quot;&gt;http://localhost:8090/&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: large; white-space: normal;&quot;&gt;&lt;a href=&quot;http://localhost:8090/health&quot;&gt;http://localhost:8090/health&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: large; white-space: normal;&quot;&gt;&lt;a href=&quot;http://localhost:8090/info&quot;&gt;http://localhost:8090/info&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://draft.blogger.com/goog_57151164&quot;&gt;
&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: large; white-space: normal;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://github.com/louisz6ster/spring_boot&quot;&gt;Github code&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: large;&quot;&gt;(louisz.springboot.example1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: large; white-space: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;其他：&lt;/b&gt;&lt;/span&gt;&lt;b style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;, sans-serif;&quot;&gt;MockTest&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;TestEx1Controller.java&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;codeblock prettyprint&quot;&gt;package louisz.springboot.introduce;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

import static org.hamcrest.Matchers.equalTo;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@RunWith(SpringRunner.class)
@WebMvcTest(Ex1Controller.class)
public class TestEx1Controller {
 @Autowired
    private MockMvc mvc;
 
    @MockBean
    private Ex1Controller service;
    
    @Before
    public void setUp() throws Exception{
     mvc = MockMvcBuilders.standaloneSetup(new Ex1Controller()).build();
    }
    
    @Test
    public void testHello() throws Exception{
     mvc.perform(MockMvcRequestBuilders.get(&quot;/&quot;).accept(MediaType.APPLICATION_JSON))
 .andExpect(status().isOk())
 .andExpect(content().string(equalTo(&quot;This is Louisz Spring Boot!!&quot;)));
    }
    
}

&lt;/pre&gt;
&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://louiszspower.blogspot.com/feeds/4791930490101030982/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://louiszspower.blogspot.com/2017/06/spring-boot-v15.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/4791930490101030982'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/4791930490101030982'/><link rel='alternate' type='text/html' href='http://louiszspower.blogspot.com/2017/06/spring-boot-v15.html' title='Spring boot v1.5 (一) introduce'/><author><name>Louisz</name><uri>http://www.blogger.com/profile/15227162328934605700</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuq5rOe6t7hT-kppa8Fu3eLB6RzgYqY8I7hZyMmMKyeAVUNbzRxsj7SQQA1EyynM-Ac6FjR6PmyXhcfn6PiIsBkByRyY8nSu3CWpAlXTcOcfGjpUDCpSBge2ou1j770EY/s220/IMG_20170629_210051.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/tsPe9_FEc2c/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553741655215810943.post-1746821675564146022</id><published>2014-06-01T04:46:00.001-07:00</published><updated>2014-06-01T04:50:30.667-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="cordova"/><category scheme="http://www.blogger.com/atom/ns#" term="genymotion"/><title type='text'>Cordova遇見Genymotion(一)：起手式</title><content type='html'>隨著行動裝置的盛行，行動裝置的開發越來越重要了，大致上可分為Native、Web及Hybird的方式開發，而每種方式都有它的優缺點，Native及Web我就不多說了，大家可以上網查一下，今天我要介紹的是&lt;a href=&quot;http://cordova.apache.org/&quot;&gt;Cordova&lt;/a&gt;前身是Phonegap，Hybird的方式，混合了Native及Web的優點，但是可能現在還算是起步中，仍有些地方不足以讓大家使用，不過我想中庸之道始終會是王道。&lt;br /&gt;
&lt;br /&gt;
另外就是我使用的模擬器不是用Android的，而是用&lt;a href=&quot;http://www.genymotion.com/&quot;&gt;Genymotion&lt;/a&gt;，用意則是效能及速度，而且也滿簡單的說。&lt;br /&gt;
&lt;br /&gt;
接下來會有幾篇都是介紹Cordova的文章，這次先介紹環境的安裝及設定。&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;安裝Cordova，可以參考&lt;a href=&quot;http://cordova.apache.org/docs/en/2.9.0/guide_cli_index.md.html&quot;&gt;這裡&lt;/a&gt;，以下步驟為我安裝的部分可以參考一下囉。&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;下載&lt;a href=&quot;http://node.js/&quot;&gt;node.js&lt;/a&gt;並安裝，安裝完後可以執行npm --version確認安裝是否成功及版本&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1jf9PP9-QcCBdmvmkDyry91vk9XfZO2JEEOmNFoFTD1Bi9s-H6vAS9cHlp4zF30u3ZdfMbIM5Y1ZSZntxjbIc0ShPf9bWDq03TMbuHdZFuApWIhChNe2iFJAcUUBbrjcR5tpIzNAZGeE/s1600/blog002.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1jf9PP9-QcCBdmvmkDyry91vk9XfZO2JEEOmNFoFTD1Bi9s-H6vAS9cHlp4zF30u3ZdfMbIM5Y1ZSZntxjbIc0ShPf9bWDq03TMbuHdZFuApWIhChNe2iFJAcUUBbrjcR5tpIzNAZGeE/s1600/blog002.png&quot; height=&quot;206&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;下載並安裝cordova，執行npm install -g cordova，確認是否安裝成功及版本可下cordova --version。&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgXV8PfYvIi2EvOyCIlE_n9B6qjBFVlG7oVlBRzYolQ48gABJgXLN3h9c568S_3lSFWhInAKMsdofqd3n461qK-UmjGNIzPq9-rDr5uxxbeaCP0r5y8wfQcKjYVAjDVCyCmXRX7t5Ks5M/s1600/blog005.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgXV8PfYvIi2EvOyCIlE_n9B6qjBFVlG7oVlBRzYolQ48gABJgXLN3h9c568S_3lSFWhInAKMsdofqd3n461qK-UmjGNIzPq9-rDr5uxxbeaCP0r5y8wfQcKjYVAjDVCyCmXRX7t5Ks5M/s1600/blog005.png&quot; height=&quot;206&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZcZd0W9zwTow7I5Kh4EeeaOk25Ewu48X7kQn0TUrH8K-_v85n78njILRQ5LfeHjjEItHicEeHrMW8pXyJtJi_jxdq5tAuH98wqAGuXBvXGfOgSffRsmW4XySa53NSmB43YtTe8N35mek/s1600/blog007.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZcZd0W9zwTow7I5Kh4EeeaOk25Ewu48X7kQn0TUrH8K-_v85n78njILRQ5LfeHjjEItHicEeHrMW8pXyJtJi_jxdq5tAuH98wqAGuXBvXGfOgSffRsmW4XySa53NSmB43YtTe8N35mek/s1600/blog007.png&quot; height=&quot;206&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;ul&gt;
&lt;li&gt;下載&lt;a href=&quot;http://www.genymotion.com/&quot;&gt;Genymotion&lt;/a&gt;，並安裝Genymotion，安裝完畢後需要進行Virtual Device下載，現在需要帳號登入才可以選擇裝置，所以申請Genymotion帳號及密碼後，就可以下載你所需的Virtual Device。&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6KR52d54AV_znnKoE-Xv9iOPwJcpYjq_pCF8Y3fmx5zIWaWj7yjq0FIPjUa9KmOA7_Jn199OOccwOtFADMYNn6rKVsSXfoHelxQwOm1iLwtpYmM2YCnLUNmkllt0Q74iqGa3G5U03LoU/s1600/Snap12.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6KR52d54AV_znnKoE-Xv9iOPwJcpYjq_pCF8Y3fmx5zIWaWj7yjq0FIPjUa9KmOA7_Jn199OOccwOtFADMYNn6rKVsSXfoHelxQwOm1iLwtpYmM2YCnLUNmkllt0Q74iqGa3G5U03LoU/s1600/Snap12.png&quot; height=&quot;244&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmQ30sfifjipH-_Q5stoytWTNIC0tBPgTPzTFnq7P_NcTboGjQvd670DakUsDNdz0xMkmyWP-RlfSMgI5XY9DdRS8AOLCqsNImBmKc1-f0Wl4YTsfufJQoD2CyoXuspi89Mx8keuftjPk/s1600/Snap13.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmQ30sfifjipH-_Q5stoytWTNIC0tBPgTPzTFnq7P_NcTboGjQvd670DakUsDNdz0xMkmyWP-RlfSMgI5XY9DdRS8AOLCqsNImBmKc1-f0Wl4YTsfufJQoD2CyoXuspi89Mx8keuftjPk/s1600/Snap13.png&quot; height=&quot;244&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixOtC-tzPdIgFiMYe7nXrI4AEgBu3UUYXRBuH-t6xjKl2BedsiklOolWkFnSEUIHCeAcOVZI8JSB1-Brdxjz4KK7IIzZeZ3cVWvaeH3ynIRo6z01G3VnvgM_zugzpkCFAjYREQMRAXT3g/s1600/Snap14.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixOtC-tzPdIgFiMYe7nXrI4AEgBu3UUYXRBuH-t6xjKl2BedsiklOolWkFnSEUIHCeAcOVZI8JSB1-Brdxjz4KK7IIzZeZ3cVWvaeH3ynIRo6z01G3VnvgM_zugzpkCFAjYREQMRAXT3g/s1600/Snap14.png&quot; height=&quot;244&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1r4APpRkM-NTS1Ycuqc3y4RL8sW_H1N9jS6sAGPmo9e19tRJzUjonumrZJ2neyclvqTMg35UjPQVDVH4nuqtELt540hnS1jJglzFqvPX-H_X1cQTDIU-XvfizhHOgHWniKPEHRhWVeMc/s1600/Snap15.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1r4APpRkM-NTS1Ycuqc3y4RL8sW_H1N9jS6sAGPmo9e19tRJzUjonumrZJ2neyclvqTMg35UjPQVDVH4nuqtELt540hnS1jJglzFqvPX-H_X1cQTDIU-XvfizhHOgHWniKPEHRhWVeMc/s1600/Snap15.png&quot; height=&quot;244&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGFLUmGsQs37hMjssBBv6AMbaTgnRBAKVEyhP88mKhiU4A8s-_n63VX-5O39VpFQNjBNdDsGtUdvmD-_ilwC4HpK2sORDlrnL_o8QD2iYp728-efDQsgom0ulNdDTTeb8KJMMcBclaYhk/s1600/Snap16.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGFLUmGsQs37hMjssBBv6AMbaTgnRBAKVEyhP88mKhiU4A8s-_n63VX-5O39VpFQNjBNdDsGtUdvmD-_ilwC4HpK2sORDlrnL_o8QD2iYp728-efDQsgom0ulNdDTTeb8KJMMcBclaYhk/s1600/Snap16.png&quot; height=&quot;244&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgce9D_alhNL7oGnrJr2DcBQbk5Oh8OAqam3-Z-qpsQ0TUGlz-xbQBFS5WHddEBPae6ZF0z8XhWRpS_cS4gh4WwoFc4vtFX_Kc5uJwsRo6z_vYVHO3ilyD-febsnqKyhiHWOZW54z8w_0Q/s1600/Snap17.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgce9D_alhNL7oGnrJr2DcBQbk5Oh8OAqam3-Z-qpsQ0TUGlz-xbQBFS5WHddEBPae6ZF0z8XhWRpS_cS4gh4WwoFc4vtFX_Kc5uJwsRo6z_vYVHO3ilyD-febsnqKyhiHWOZW54z8w_0Q/s1600/Snap17.png&quot; height=&quot;107&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVzvpiBacLtPn9G88Nmhxy8CXJhcMypx3lwR8S_npflOwpsHe-bOBAkuMSnpyzxcGVh3q8oxA1syWQl_Znz0pCGwlOIr519VIDWUcpCpnsj-F9iokX3wFAw73UK_tHpdua6CEb2mqZl7M/s1600/Snap18.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVzvpiBacLtPn9G88Nmhxy8CXJhcMypx3lwR8S_npflOwpsHe-bOBAkuMSnpyzxcGVh3q8oxA1syWQl_Znz0pCGwlOIr519VIDWUcpCpnsj-F9iokX3wFAw73UK_tHpdua6CEb2mqZl7M/s1600/Snap18.png&quot; height=&quot;246&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiX5WZN9TP4eYo4LSPlwYaDKCnngK-ATN0uL4HYgfK-vNwXHlObWjPm78FmTPmNDamj-hoMJsZfbGlwz4urECjQ1-3Hx5yOPDo1MT7aB2jKhkQ0qXZPdaot0Hl_s2bPOfmm8egJzj0uPJM/s1600/Snap19.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiX5WZN9TP4eYo4LSPlwYaDKCnngK-ATN0uL4HYgfK-vNwXHlObWjPm78FmTPmNDamj-hoMJsZfbGlwz4urECjQ1-3Hx5yOPDo1MT7aB2jKhkQ0qXZPdaot0Hl_s2bPOfmm8egJzj0uPJM/s1600/Snap19.png&quot; height=&quot;246&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjeJe_ZplAUp8xAflMVbTljE7uAZyIaHPFZ8qSdDZaBowOyNnZprNW4uJVRnSNPU_1P7IMTvBgJiY1_JcCM8k2nowz4f-WjaSGWqOrI_YduKL2kxPYkzOKW6MdbMcJ8Y6HzJ-Z5QKJlKuc/s1600/Snap20.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjeJe_ZplAUp8xAflMVbTljE7uAZyIaHPFZ8qSdDZaBowOyNnZprNW4uJVRnSNPU_1P7IMTvBgJiY1_JcCM8k2nowz4f-WjaSGWqOrI_YduKL2kxPYkzOKW6MdbMcJ8Y6HzJ-Z5QKJlKuc/s1600/Snap20.png&quot; height=&quot;246&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_2ZXVYRjFgQUjxbxhyARh3emkFvpLzsR1dI4-HVniRt7uZBvwhyphenhyphenc4wqpiw1F5GWtznZzYmLTw6_17ZFNOMJz94Blxh4ILq1InLlbvflNKbkjSiM48xDPffWiPXG5sHfJ8pXUMOXHbIME/s1600/Snap21.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_2ZXVYRjFgQUjxbxhyARh3emkFvpLzsR1dI4-HVniRt7uZBvwhyphenhyphenc4wqpiw1F5GWtznZzYmLTw6_17ZFNOMJz94Blxh4ILq1InLlbvflNKbkjSiM48xDPffWiPXG5sHfJ8pXUMOXHbIME/s1600/Snap21.png&quot; height=&quot;246&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0s5LVt342NVvQfiQQ7PCWPZjMR-zx3LXv_Lbr1_Vrf0DTaYAln3mj7cF6DyOCAZEE0uFR_8zL7YdZtDTHLlJNaYofd-vmXtW0iENBOALUOhyTU75as83c9E0rzy4hgE5ctsVyyickrfw/s1600/Snap22.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0s5LVt342NVvQfiQQ7PCWPZjMR-zx3LXv_Lbr1_Vrf0DTaYAln3mj7cF6DyOCAZEE0uFR_8zL7YdZtDTHLlJNaYofd-vmXtW0iENBOALUOhyTU75as83c9E0rzy4hgE5ctsVyyickrfw/s1600/Snap22.png&quot; height=&quot;144&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjghxq5GR0_j4dnrbdI67t_OqAcSrpgUlcIR0HQKfXcpGKj4qLuYeZa3MNbJIxlRsIc6P4hsOEWjbpDRAgab9Ccp4SYIeuyWa9EJwxo2N_7qp5k2nl5IA6b66HnP-InknBaabueDKujn3I/s1600/Snap23.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjghxq5GR0_j4dnrbdI67t_OqAcSrpgUlcIR0HQKfXcpGKj4qLuYeZa3MNbJIxlRsIc6P4hsOEWjbpDRAgab9Ccp4SYIeuyWa9EJwxo2N_7qp5k2nl5IA6b66HnP-InknBaabueDKujn3I/s1600/Snap23.png&quot; height=&quot;246&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfH4hkPr1UxrAj5kfgwxJOtvm05LIii-YU6mQwWtu6Qr8RrDAqxzY_juFdSFy5kr4q2yjJSQSyZjz9x-cB4EHUpPgZsgiL-_YqhNPTj0iTHxBxt5uYQspIEiCU4qCgAXlGtMD23ZudwLE/s1600/Snap24.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfH4hkPr1UxrAj5kfgwxJOtvm05LIii-YU6mQwWtu6Qr8RrDAqxzY_juFdSFy5kr4q2yjJSQSyZjz9x-cB4EHUpPgZsgiL-_YqhNPTj0iTHxBxt5uYQspIEiCU4qCgAXlGtMD23ZudwLE/s1600/Snap24.png&quot; height=&quot;244&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigIWRJAZnrJSfAVFSF9LAQ9L9uHCjDdNulb8lhmdkZmbxKBMn33utV6lVd5czfCAl-ZcAl0MK1FMfVXchOxTULZYPAiO-jMpiNFU1KQ1mQe-k4j0tzw6GasLcmTos9orSECME56yDiSzc/s1600/Snap26.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigIWRJAZnrJSfAVFSF9LAQ9L9uHCjDdNulb8lhmdkZmbxKBMn33utV6lVd5czfCAl-ZcAl0MK1FMfVXchOxTULZYPAiO-jMpiNFU1KQ1mQe-k4j0tzw6GasLcmTos9orSECME56yDiSzc/s1600/Snap26.png&quot; height=&quot;248&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnXF_r22pV2ETNzEYZ43p1aJGmFhFV9_OSrB42SUf4UrTj4nXWB8mPdQ25AWe3w17RnwshBe2kouCbxcRud3zFd2Wt81GsuV099RbPGrfT7dI7Pi3h4McL5tdO8iBygLD4_Ev6SPr5VNk/s1600/Snap11.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnXF_r22pV2ETNzEYZ43p1aJGmFhFV9_OSrB42SUf4UrTj4nXWB8mPdQ25AWe3w17RnwshBe2kouCbxcRud3zFd2Wt81GsuV099RbPGrfT7dI7Pi3h4McL5tdO8iBygLD4_Ev6SPr5VNk/s1600/Snap11.png&quot; height=&quot;244&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: 新細明體, serif; text-indent: -24pt;&quot;&gt;我這裡是用&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;text-indent: -24pt;&quot;&gt;Netbeans&lt;/span&gt;&lt;span style=&quot;font-family: 新細明體, serif; text-indent: -24pt;&quot;&gt;進行開發，所以先下載&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;text-indent: -24pt;&quot;&gt;&lt;a href=&quot;https://netbeans.org/downloads/&quot;&gt;Netbeans 8&lt;/a&gt;&lt;/span&gt;&lt;span style=&quot;font-family: 新細明體, serif; text-indent: -24pt;&quot;&gt;，並安裝&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;text-indent: -24pt;&quot;&gt;Netbeans&lt;/span&gt;&lt;span style=&quot;font-family: 新細明體, serif; text-indent: -24pt;&quot;&gt;。安裝完後啟動&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;text-indent: -24pt;&quot;&gt;Netbeans&lt;/span&gt;&lt;span style=&quot;font-family: 新細明體, serif; text-indent: -24pt;&quot;&gt;。接下來因為要設定&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;text-indent: -24pt;&quot;&gt;Android SDK&lt;/span&gt;&lt;span style=&quot;font-family: 新細明體, serif; text-indent: -24pt;&quot;&gt;，所以先下載&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;text-indent: -24pt;&quot;&gt;Android SDK&lt;/span&gt;&lt;span style=&quot;font-family: 新細明體, serif; text-indent: -24pt;&quot;&gt;，並安裝後，在&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;text-indent: -24pt;&quot;&gt;Netbeans&lt;/span&gt;&lt;span style=&quot;font-family: 新細明體, serif; text-indent: -24pt;&quot;&gt;中設定&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;text-indent: -24pt;&quot;&gt;Android SDK&lt;/span&gt;&lt;span style=&quot;font-family: 新細明體, serif; text-indent: -24pt;&quot;&gt;位置。&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFh_fQf8K6po7UhQV8Bfz2OiVoOiBUl4ams0xrCSg6siT70vUYWyIKhcJ4BsR-df5Z5cTrSwOHkAj8cDCdHYloMRam1cZqMnnMeeXs9x2UskCem4mKPE0jtIfZrcrmHA8ul4vfBz_kn9Q/s1600/Snap35.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFh_fQf8K6po7UhQV8Bfz2OiVoOiBUl4ams0xrCSg6siT70vUYWyIKhcJ4BsR-df5Z5cTrSwOHkAj8cDCdHYloMRam1cZqMnnMeeXs9x2UskCem4mKPE0jtIfZrcrmHA8ul4vfBz_kn9Q/s1600/Snap35.png&quot; height=&quot;273&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;ul&gt;&lt;/ul&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;li&gt;進行所有安裝測試囉，先開啟一個新的Cordova專案。&lt;/li&gt;
&lt;br /&gt;
&lt;div style=&quot;text-indent: -32px;&quot;&gt;
&lt;span style=&quot;font-family: 新細明體, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzQE1H_B8USgJEI-xgg2sEJsXh906LSaJdjU5RsYqPb-9_4KXF9LS7mOrEiKOdP7a1wIzkmtrA3jSrnGG7youzXS72h7KCMpC83Z_QjNkkxeY9t5yIU-ELcvspmt00m2xmfzjtJW_ZwPw/s1600/Snap27.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzQE1H_B8USgJEI-xgg2sEJsXh906LSaJdjU5RsYqPb-9_4KXF9LS7mOrEiKOdP7a1wIzkmtrA3jSrnGG7youzXS72h7KCMpC83Z_QjNkkxeY9t5yIU-ELcvspmt00m2xmfzjtJW_ZwPw/s1600/Snap27.png&quot; height=&quot;219&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicIIPVWzpzpBxaQcd2Q7cngtTHLFcgsP6Szzj_Zvu2dJcXCFcCwL7SfC9GGieMvlBLb_SPZ_FP9KfRuTwMNkzg4NOM3-WWObPxo2xEF9UzwgkivSE_Ak9HKTAaIiSgo4y9_djmsgHaSnM/s1600/Snap28.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicIIPVWzpzpBxaQcd2Q7cngtTHLFcgsP6Szzj_Zvu2dJcXCFcCwL7SfC9GGieMvlBLb_SPZ_FP9KfRuTwMNkzg4NOM3-WWObPxo2xEF9UzwgkivSE_Ak9HKTAaIiSgo4y9_djmsgHaSnM/s1600/Snap28.png&quot; height=&quot;212&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTiHh2YLSMrigAi4leLYLhXhJKAGUREok72yqnrdJKgTOeS-qJDqsHsEuQVZIQj8PUP8-udutPMmNstvx_mKXwDcWvGk2nRkl2Bn19Rlwhl6eWQDC7pjo6q7i4dIMQ7yhVpjaf6EwJSi0/s1600/Snap29.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTiHh2YLSMrigAi4leLYLhXhJKAGUREok72yqnrdJKgTOeS-qJDqsHsEuQVZIQj8PUP8-udutPMmNstvx_mKXwDcWvGk2nRkl2Bn19Rlwhl6eWQDC7pjo6q7i4dIMQ7yhVpjaf6EwJSi0/s1600/Snap29.png&quot; height=&quot;212&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7ObpCO9tYbVwLH84TF-ExtTV6C10i1zSZve7EuKBE5yAFS-SYz4R6JE5J15vn7WEAYUKmaRqXIo5zh4Y4i7Pk-r8jZj5rUKhSyxNQ2pOMZsUNq1zMttqCpbigp4fLoX8yGdl3BzJiyCo/s1600/Snap30.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7ObpCO9tYbVwLH84TF-ExtTV6C10i1zSZve7EuKBE5yAFS-SYz4R6JE5J15vn7WEAYUKmaRqXIo5zh4Y4i7Pk-r8jZj5rUKhSyxNQ2pOMZsUNq1zMttqCpbigp4fLoX8yGdl3BzJiyCo/s1600/Snap30.png&quot; height=&quot;212&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_8WAw354-gVnq9zS11vVG-YFjoi4V71w1ug_R0f5qCb4UeFSNKNfjOj8JMeWwo9-cM5BiDYhbxYVYQs9ibSGqK_fF7b83eYYF8D7hMh2aW4A-8EdQE_zYbL5usjVrjmwOMwgmqg2UuoM/s1600/Snap31.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_8WAw354-gVnq9zS11vVG-YFjoi4V71w1ug_R0f5qCb4UeFSNKNfjOj8JMeWwo9-cM5BiDYhbxYVYQs9ibSGqK_fF7b83eYYF8D7hMh2aW4A-8EdQE_zYbL5usjVrjmwOMwgmqg2UuoM/s1600/Snap31.png&quot; height=&quot;212&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1BckHYtzKdW3eb49Zpf_sgSDovF6W1Ci5OULniiqP54g7FfYdD6iosu06rvCetwk98Co4NnP0uTGoCQXxQwlSIQj8gIcgFlI6E5eDTCqWCVGKETzXYBe96b1Mq-p-ps8Nm247cBPBu4g/s1600/Snap32.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1BckHYtzKdW3eb49Zpf_sgSDovF6W1Ci5OULniiqP54g7FfYdD6iosu06rvCetwk98Co4NnP0uTGoCQXxQwlSIQj8gIcgFlI6E5eDTCqWCVGKETzXYBe96b1Mq-p-ps8Nm247cBPBu4g/s1600/Snap32.png&quot; height=&quot;212&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;不需要做任何事情，直接編譯專案成功後，先啟動Genymotion的Virtual Device，透過以下指令，把編譯出來的APK安裝上去，有出現會後一個畫面就是表示成功囉。&lt;/li&gt;
&lt;/ul&gt;
Genymotion\tools\adb install -r xxx.apk&lt;br /&gt;
※若是遇到device not found可以試試，adb connect xxx.xxx.xxx.xxx(可以看看模擬器左上角的IP)，在執行安裝指令。&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8oqIkGADjwLmT7syA6IXUEFB-PobLxCwMBGwE3Cus0xbXhhfhLGAMQiC6i4QNHSJyBU98O-A9OZaWW2ErtoheX9ObJBn9jetaLJFLlrxJ8EHX2ESe9g2yY5Im3FPtM7WXYiip9tt0lZ8/s1600/Snap38.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8oqIkGADjwLmT7syA6IXUEFB-PobLxCwMBGwE3Cus0xbXhhfhLGAMQiC6i4QNHSJyBU98O-A9OZaWW2ErtoheX9ObJBn9jetaLJFLlrxJ8EHX2ESe9g2yY5Im3FPtM7WXYiip9tt0lZ8/s1600/Snap38.png&quot; height=&quot;179&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiX1K0PkPpXsJ4FKBo3hCFYqMiYyqxsgR2Ab4LvxTznC3wvSyokdSacRABAWtPgJi-uQNSFrtNstuNfc8EB0iZqFJnDsECzY2dasILWXHVpwlkX-gGnEPJTgpxo4RzxG3q3oVl8PPjFa_8/s1600/Snap40.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiX1K0PkPpXsJ4FKBo3hCFYqMiYyqxsgR2Ab4LvxTznC3wvSyokdSacRABAWtPgJi-uQNSFrtNstuNfc8EB0iZqFJnDsECzY2dasILWXHVpwlkX-gGnEPJTgpxo4RzxG3q3oVl8PPjFa_8/s1600/Snap40.png&quot; height=&quot;179&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ4yuU2ZhqbbYOrcyAti6_IYQf6k-_M_zrEC8ggilhgpq9LMzIYVXC6Muw0QKkE_ve_eC-58ckxc_7eAyJ2NzGCamlyq8tdQHqQxHdHqICWoLi9HrK8ZA8TmmlZeihNyk9uJ2DQ0wtTR4/s1600/Snap41.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ4yuU2ZhqbbYOrcyAti6_IYQf6k-_M_zrEC8ggilhgpq9LMzIYVXC6Muw0QKkE_ve_eC-58ckxc_7eAyJ2NzGCamlyq8tdQHqQxHdHqICWoLi9HrK8ZA8TmmlZeihNyk9uJ2DQ0wtTR4/s1600/Snap41.png&quot; height=&quot;179&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuKtd2Uj1glhb49I4uzvfAaT6mxk4c_OqrgOTN-tuPCWXdGJu-OPeEGKDdk4KZ2QW9VDPIqDrAltS5Eho-6uRf8qsy_pLojEvhizc7SOpJs4tS83DFQNXf01qjf6s9iAjLIJgim2Y3bpw/s1600/Snap42.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuKtd2Uj1glhb49I4uzvfAaT6mxk4c_OqrgOTN-tuPCWXdGJu-OPeEGKDdk4KZ2QW9VDPIqDrAltS5Eho-6uRf8qsy_pLojEvhizc7SOpJs4tS83DFQNXf01qjf6s9iAjLIJgim2Y3bpw/s1600/Snap42.png&quot; height=&quot;179&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-RqEYri1bOgg31mV-OkrFrx5Si8m9ue9J_nhuKn-xP5RVe62HodPOhJ1ZEhCtt-PtcJXSiEnLBmCgfKhq8_JQuGhlJbm2N5dbXNj6V7OKKDxxFTnWtt6OG9slMygFKqpi8n89ZDcyMaI/s1600/Snap43.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-RqEYri1bOgg31mV-OkrFrx5Si8m9ue9J_nhuKn-xP5RVe62HodPOhJ1ZEhCtt-PtcJXSiEnLBmCgfKhq8_JQuGhlJbm2N5dbXNj6V7OKKDxxFTnWtt6OG9slMygFKqpi8n89ZDcyMaI/s1600/Snap43.png&quot; height=&quot;179&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimRnOpcwlnSAYYv5DnRV5AUkIO105YE2c9rm8UG_AtF_daBZdYIQrg9uCBd4lv7ymVpSu3XHX47FQau7JXLstTw58jH-6in2zyfub8nWVm4eDGgocnVTeyNLT6daU5RPIiENXcv-tPJjM/s1600/Snap45.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimRnOpcwlnSAYYv5DnRV5AUkIO105YE2c9rm8UG_AtF_daBZdYIQrg9uCBd4lv7ymVpSu3XHX47FQau7JXLstTw58jH-6in2zyfub8nWVm4eDGgocnVTeyNLT6daU5RPIiENXcv-tPJjM/s1600/Snap45.png&quot; height=&quot;179&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitKbaZZVnT4jrA8KoBwONSltBstDNW89ZU8O7J2b_zT3zuw-R90xLaUykQ2A5aq5PBBo2Nvf4KkHrL52NdYT_HJQtZ5KucLsCFC9nnVqiRxm8UUa13iBuePb9HpmPqAWENN0LLbcMAfMk/s1600/Snap47.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitKbaZZVnT4jrA8KoBwONSltBstDNW89ZU8O7J2b_zT3zuw-R90xLaUykQ2A5aq5PBBo2Nvf4KkHrL52NdYT_HJQtZ5KucLsCFC9nnVqiRxm8UUa13iBuePb9HpmPqAWENN0LLbcMAfMk/s1600/Snap47.png&quot; height=&quot;179&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyo-6_W7wWHVATU1pzPeOCzlUXGVXYxIe_yYohQp-kDpzAYs_i5TZ4rpY5mM8BLCnETF5WBQ-Kgaar_pi25xcm7DrR1DkNJ3VBeg0-UnCvLoGQAwaz4cs95InKHc5x1Qk-8lbjy0NrzGA/s1600/Snap46.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyo-6_W7wWHVATU1pzPeOCzlUXGVXYxIe_yYohQp-kDpzAYs_i5TZ4rpY5mM8BLCnETF5WBQ-Kgaar_pi25xcm7DrR1DkNJ3VBeg0-UnCvLoGQAwaz4cs95InKHc5x1Qk-8lbjy0NrzGA/s1600/Snap46.png&quot; height=&quot;179&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
)&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://louiszspower.blogspot.com/feeds/1746821675564146022/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://louiszspower.blogspot.com/2014/06/cordovagenymotion.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/1746821675564146022'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/1746821675564146022'/><link rel='alternate' type='text/html' href='http://louiszspower.blogspot.com/2014/06/cordovagenymotion.html' title='Cordova遇見Genymotion(一)：起手式'/><author><name>Louisz</name><uri>http://www.blogger.com/profile/15227162328934605700</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuq5rOe6t7hT-kppa8Fu3eLB6RzgYqY8I7hZyMmMKyeAVUNbzRxsj7SQQA1EyynM-Ac6FjR6PmyXhcfn6PiIsBkByRyY8nSu3CWpAlXTcOcfGjpUDCpSBge2ou1j770EY/s220/IMG_20170629_210051.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1jf9PP9-QcCBdmvmkDyry91vk9XfZO2JEEOmNFoFTD1Bi9s-H6vAS9cHlp4zF30u3ZdfMbIM5Y1ZSZntxjbIc0ShPf9bWDq03TMbuHdZFuApWIhChNe2iFJAcUUBbrjcR5tpIzNAZGeE/s72-c/blog002.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553741655215810943.post-4226639194695228592</id><published>2013-07-06T22:36:00.000-07:00</published><updated>2013-07-06T22:38:08.376-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Lucene"/><title type='text'>Lucene(一)：Lucene4.3.1、Tika、IKAnalyzer中文分詞</title><content type='html'>&lt;a href=&quot;http://lucene.apache.org/core/&quot;&gt;Lucene&lt;/a&gt;是一個很強大的搜尋引擎(&lt;a href=&quot;https://zh.wikipedia.org/zh-tw/Lucene&quot;&gt;Lucene wiki&lt;/a&gt;)，重點是Open Source，還有很多子專案很好用喔，這次來介紹一下&lt;a href=&quot;http://tika.apache.org/&quot;&gt;Tika&lt;/a&gt;這個子專案，它是一個文件擷取內容及文件metadata的函式庫，支援的檔案格式可以參考一下&lt;a href=&quot;http://tika.apache.org/1.4/formats.html&quot;&gt;這裡&lt;/a&gt;，加上Lucene Core及中文IKAnalyzer就可以組合文件的中文全文檢索喔。&lt;br /&gt;
&lt;br /&gt;
先下載&lt;br /&gt;
&lt;a href=&quot;http://www.apache.org/dyn/closer.cgi/lucene/java/4.3.1&quot;&gt;Lucene 4.3.1&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.apache.org/dyn/closer.cgi/tika/tika-1.4-src.zip&quot;&gt;Tika&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;https://ik-analyzer.googlecode.com/files/IK%20Analyzer%202012FF_hf1.zip&quot;&gt;IKAnalyzer&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Lucene 4.3.1&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;下載後解壓縮，分別複製以下的jar&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;lucene-queryparser-4.3.1.jar&lt;/li&gt;
&lt;li&gt;lucene-queries-4.3.1.jar&lt;/li&gt;
&lt;li&gt;lucene-core-4.3.1.jar&lt;/li&gt;
&lt;li&gt;lucene-analyzers-common-4.3.1.jar&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;div&gt;
Tika 1.4&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;請下載Source檔案，另外請在下載&lt;a href=&quot;http://ftp.tc.edu.tw/pub/Apache/maven/maven-3/3.0.5/binaries/apache-maven-3.0.5-bin.zip&quot;&gt;maven&lt;/a&gt;，因為Tika建議重新編譯一份出來，編譯方式參&lt;a href=&quot;http://tika.apache.org/1.4/gettingstarted.html&quot;&gt;這裡&lt;/a&gt;，分別複製以下的jar&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;tika-xmp-1.4.jar&lt;/li&gt;
&lt;li&gt;tika-server-1.4.jar&lt;/li&gt;
&lt;li&gt;tika-parsers-1.4.jar&lt;/li&gt;
&lt;li&gt;tika-core-1.4.jar&lt;/li&gt;
&lt;li&gt;tika-bundle-1.4.jar&lt;/li&gt;
&lt;li&gt;tika-app-1.4.jar&lt;/li&gt;
&lt;li&gt;original-tika-app-1.4.jar&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
IKAnalyzer&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;下載後解壓縮，複製以下的jar&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;IKAnalyzer2012FF_ul.jar&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
TvDocumentVo.java：儲存 Tika解析文件內容vo。&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
public class TvDocumentVo {&amp;nbsp;&lt;/blockquote&gt;
&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp;private Metadata metadata;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; private String content;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; public Metadata getMetadata() {&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return metadata;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; }&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; public void setMetadata(Metadata metadata) {&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.metadata = metadata;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; }&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; public String getContent() {&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return content;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; }&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; public void setContent(String content) {&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.content = content;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; }&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
}&lt;/blockquote&gt;
&lt;/blockquote&gt;
&lt;div&gt;
TvDocmentExtract.jar：使用Tika將解析出來的文件內容轉成List。P.S這裡需要調整當檔案數量及大小過大時。&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
public class TvDocmentExtract {&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; public List&lt;tvdocumentvo&gt; parseAllFilesInDirectory(File directory) throws IOException, SAXException, TikaException {&lt;/tvdocumentvo&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; List&lt;tvdocumentvo&gt; result = new ArrayList&lt;tvdocumentvo&gt;();&lt;/tvdocumentvo&gt;&lt;/tvdocumentvo&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for (File file : directory.listFiles()) {&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (file.isDirectory()) {&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; parseAllFilesInDirectory(file);&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } else {&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Parser parser = new AutoDetectParser();&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Metadata metadata = new Metadata();&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ParseContext parseContext = new ParseContext();&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ContentHandler handler = new BodyContentHandler(100*100*1024);//若是檔案過大可以放大這裡的參數&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; parser.parse(new FileInputStream(file), handler, metadata, parseContext);&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TvDocumentVo vo = new TvDocumentVo();&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; metadata.set(&quot;filename&quot;,file.getAbsolutePath());//增加檔案絕對路徑屬性&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; vo.setMetadata(metadata);&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; vo.setContent(handler.toString());&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; result.add(vo);&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return result;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; }&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
}&lt;/blockquote&gt;
&lt;/blockquote&gt;
&lt;div&gt;
TvIndexManagement.java：建立索引&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
public class TvIndexManagement {&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; public static void main(String[] arg) throws ParseException, IOException{&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TvIndexManagement tim = new TvIndexManagement();&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; tim.createIndex(&quot;D:\\index&quot;, &quot;D:\\document&quot;);//參數一為建立索引目錄，參數二為要進行文件擷取目錄&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; }&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; public void createIndex(String indexDir,String filesPath){&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.ikanalyzerIndex(indexDir, filesPath);&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; }&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; public RAMDirectory readfsIndexToRam(String indexDir) throws IOException{&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Directory fsDir = FSDirectory.open(new File(indexDir));&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;IOContext ioContext = new IOContext(Context.DEFAULT);&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return new RAMDirectory(fsDir, ioContext);&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; }&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; private void ikanalyzerIndex(String indexDir,String filesPath){&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Analyzer analyzer = new IKAnalyzer(true);//可參IKAnalyzer說明&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; try {&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Directory index = FSDirectory.open(new File(indexDir));&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; IOContext ioContext = new IOContext(Context.DEFAULT);&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Directory index = new RAMDirectory(fsDir, ioContext);&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_43,analyzer);&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; IndexWriter w = new IndexWriter(index, config);&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; config.setMaxBufferedDocs(1000);//純粹測試效能調教&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; config.setRAMBufferSizeMB(40);//純粹測試效能調教&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;TvDocmentExtract tde = new TvDocmentExtract();&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; try {&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; List&lt;tvdocumentvo&gt; lists=tde.parseAllFilesInDirectory(new File(filesPath));&lt;/tvdocumentvo&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for(TvDocumentVo vo :lists){&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.addDocument(w,vo.getMetadata().get(&quot;filename&quot;),vo.getContent());&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; w.close();&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } catch (SAXException ex) {&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Logger.getLogger(TvIndexManagement.class.getName()).log(Level.SEVERE, null, ex);&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } catch (TikaException ex) {&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Logger.getLogger(TvIndexManagement.class.getName()).log(Level.SEVERE, null, ex);&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } catch (IOException ex) {&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Logger.getLogger(TvIndexManagement.class.getName()).log(Level.SEVERE, null, ex);&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; }&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; private void addDocument(IndexWriter writer,String filename,String content) throws IOException{&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Document doc = new Document();&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //System.out.println(filename);&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; doc.add(new TextField(&quot;filename&quot;, filename, Field.Store.YES));&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;doc.add(new TextField(&quot;content&quot;, content, Field.Store.YES));&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;writer.addDocument(doc);&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; } &amp;nbsp; &amp;nbsp;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
}&lt;/blockquote&gt;
&lt;/blockquote&gt;
&lt;div&gt;
全文檢索範例程式碼&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; String querystr = &quot;合法&quot;;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Directory index = FSDirectory.open(new File(&quot;D:\\index&quot;));&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Analyzer analyzer = new IKAnalyzer(true);&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; QueryParser qp = new QueryParser(Version.LUCENE_43, &quot;content&quot;, analyzer);&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; qp.setDefaultOperator(QueryParser.Operator.AND);&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Query q = qp.parse(querystr);&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int hitsPerPage = 10;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; IndexReader reader = DirectoryReader.open(index);&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; IndexSearcher searcher = new IndexSearcher(reader);&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TopScoreDocCollector collector = TopScoreDocCollector.create(hitsPerPage, true);&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; searcher.search(q, collector);&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ScoreDoc[] hits = collector.topDocs().scoreDocs;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; collector.getTotalHits();&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;System.out.println(&quot;Found &quot; + hits.length + &quot; hits ==&amp;gt;&quot; + collector.getTotalHits());&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for (int i = 0; i &amp;lt; hits.length; ++i) {&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int docId = hits[i].doc;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Document d = searcher.doc(docId);&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println((i + 1) + &quot;. &quot; + d.get(&quot;filename&quot;));&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; reader.close();&lt;/blockquote&gt;
&lt;/blockquote&gt;
&lt;div&gt;
目前正在試試看，不使用Hadoop方式加快建立索引時間，基本上會用Queue方式進行，下次再介紹囉。&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://louiszspower.blogspot.com/feeds/4226639194695228592/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://louiszspower.blogspot.com/2013/07/lucenelucene431tikaikanalyzer.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/4226639194695228592'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/4226639194695228592'/><link rel='alternate' type='text/html' href='http://louiszspower.blogspot.com/2013/07/lucenelucene431tikaikanalyzer.html' title='Lucene(一)：Lucene4.3.1、Tika、IKAnalyzer中文分詞'/><author><name>Louisz</name><uri>http://www.blogger.com/profile/15227162328934605700</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuq5rOe6t7hT-kppa8Fu3eLB6RzgYqY8I7hZyMmMKyeAVUNbzRxsj7SQQA1EyynM-Ac6FjR6PmyXhcfn6PiIsBkByRyY8nSu3CWpAlXTcOcfGjpUDCpSBge2ou1j770EY/s220/IMG_20170629_210051.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553741655215810943.post-8582442217259419500</id><published>2013-06-30T04:28:00.000-07:00</published><updated>2013-06-30T05:07:21.334-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaEE"/><category scheme="http://www.blogger.com/atom/ns#" term="工作"/><title type='text'>Java EE(一)：Glassfish JAAS JDBC Realm 設定 &amp;  SSO補充</title><content type='html'>甚麼是JAAS可以參考一下&lt;a href=&quot;http://www.javaworld.com.tw/jute/post/view?bid=5&amp;amp;id=34202&amp;amp;sty=3&quot;&gt;JWorld@TW&lt;/a&gt;及&lt;a href=&quot;http://www.oracle.com/technetwork/java/javase/jaas/index.html&quot;&gt;Oracle Jaas&lt;/a&gt;，在進行專案開發時，基本上人員權限一定是考量進去的，這次來介紹一下如何在Glassfish專案中設定 jdbc realm的方式進行。&lt;br /&gt;
&lt;br /&gt;
既然是jdbc當然要先規劃一下db schema，有三個資料表要建立，user(人員資料表)、role(角色群組表)、userrolemapping(人員角色對應表)，user資料表內要有帳號(username)及密碼(password)，role資料表角色代號(role_code)，userrolemapping資料表帳號(username)及角色代號(role_code)對應，這裡我會建議設計一個view比較方便：&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;SELECT user.username, user.password, role.role_code&lt;br /&gt;
&amp;nbsp; &amp;nbsp;FROM user, role, userrolemapping&lt;br /&gt;
&amp;nbsp; WHERE user.username = userrolemapping.username AND role.role_code= userrolemapping.role_code;&lt;br /&gt;
&lt;br /&gt;
若是JPA當然就用Id囉，&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;SELECT user.username, user.password, role.role_code&lt;br /&gt;
&amp;nbsp; &amp;nbsp;FROM user, role, userrolemapping&lt;br /&gt;
&amp;nbsp; WHERE user.id= userrolemapping.user_id AND role.id= userrolemapping.role_id;&lt;br /&gt;
&lt;br /&gt;
啟動Glassfis並進入admin console&lt;br /&gt;
&lt;a href=&quot;http://localhost:4848/&quot;&gt;http://localhost:4848&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;選擇資源(Resources)--JDBC-- JDBC Connection Pool，按下新增&lt;/li&gt;
&lt;/ul&gt;
Pool Name：test&lt;br /&gt;
資源類型：javax.sql.DataSource&lt;br /&gt;
資料庫驅動程式供應商：這裡使用Postgresql，就選Postgresql Driver。&lt;br /&gt;
&lt;br /&gt;
按下Next&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmsph9f1YlKfxDYelwjmaIePcTLFneN19N4k9jMhIFgqFMCH9pbPNjaenjGfHElIOCz6ccoKfeDanaFtcaqAqO-pdrkHuyuqkI6MDls6lXRQBR-_vr4o77dYCvRCfq6lBgRZpRQ8wrsiI/s1117/Snap32.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmsph9f1YlKfxDYelwjmaIePcTLFneN19N4k9jMhIFgqFMCH9pbPNjaenjGfHElIOCz6ccoKfeDanaFtcaqAqO-pdrkHuyuqkI6MDls6lXRQBR-_vr4o77dYCvRCfq6lBgRZpRQ8wrsiI/s1117/Snap32.png&quot; height=&quot;95&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKdLBSYf-yxm8pgBbA2gGuL7CgexF4TpqIvCF2rkANl0Qn7LlqgtBL3rggEriLmX7uSqkHmmxGwL40ysszyDXQ2rURP7wjj6Ieaou-CFiUAV-yQ2jsLJV84nOwZ2HZrIGcBA4kxZpBowo/s1350/Snap33.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKdLBSYf-yxm8pgBbA2gGuL7CgexF4TpqIvCF2rkANl0Qn7LlqgtBL3rggEriLmX7uSqkHmmxGwL40ysszyDXQ2rURP7wjj6Ieaou-CFiUAV-yQ2jsLJV84nOwZ2HZrIGcBA4kxZpBowo/s1350/Snap33.png&quot; height=&quot;161&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&amp;nbsp;輸入以下特性，並按下確定。&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEia8d3ALuObSI_BSKLECxWvpZgrjYYVbQS5M5wUtt5IlBQOlRC85f_gnv9pt6HEiThg0eIDlYaWh1xedAFEWtjY_WBmYAx4eKFTHdFoOP-B50ldoXzK2tIkPBUm7OAc1AlrxUj6Ffz8QAw/s1093/Snap36.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEia8d3ALuObSI_BSKLECxWvpZgrjYYVbQS5M5wUtt5IlBQOlRC85f_gnv9pt6HEiThg0eIDlYaWh1xedAFEWtjY_WBmYAx4eKFTHdFoOP-B50ldoXzK2tIkPBUm7OAc1AlrxUj6Ffz8QAw/s1093/Snap36.png&quot; height=&quot;74&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&amp;nbsp;可以測試是否設定正確，按下Ping進行測試。&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheCetbS2cavW2g5TIOYScdT_O_iNP6qh9DgpiLhMFmWo7_7aqB4rHppe8TRAMrQDdCRUbDRiXfxE6SjPh1xl9Kh-det8NZfvDdT_gexoQBAzYZTRQ86tVeLlp3HQrFG52dgWZ1Vr8gH1o/s1350/Snap37.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheCetbS2cavW2g5TIOYScdT_O_iNP6qh9DgpiLhMFmWo7_7aqB4rHppe8TRAMrQDdCRUbDRiXfxE6SjPh1xl9Kh-det8NZfvDdT_gexoQBAzYZTRQ86tVeLlp3HQrFG52dgWZ1Vr8gH1o/s1350/Snap37.png&quot; height=&quot;151&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;新增JDBC資源，資源--JDBC--JDBC資源，按下新增&lt;/li&gt;
&lt;/ul&gt;
JNDI名稱：jdbc/test&lt;br /&gt;
池名稱：剛剛建立的Pool名稱即可。&lt;br /&gt;
輸入完畢後按下確定。&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLNcDGiaPJ-98sUpqNk4v2z7kG9I8IIX49V9F49PSFC53llmvb6C7jummQgBoA9oAP1JDzjO1IbJsOpEmjcuq1HhQ9B9dWdUAxGB6fVRw3ECXkvQ8CeVHb3MUqLod0qV8yu3mhtUi-NSM/s1350/Snap39.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLNcDGiaPJ-98sUpqNk4v2z7kG9I8IIX49V9F49PSFC53llmvb6C7jummQgBoA9oAP1JDzjO1IbJsOpEmjcuq1HhQ9B9dWdUAxGB6fVRw3ECXkvQ8CeVHb3MUqLod0qV8yu3mhtUi-NSM/s1350/Snap39.png&quot; height=&quot;151&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggQGm023f8st0uxMfVwX0f-7lgyx7DX-Rr2lyYVMOdjTMSsNWhmOnqQsxspR6lsSCD2g9-13hw4p4SbrN4PLQxaOmyOnZlRxEN-himbg05SJIVQLB4q4TjajEgrcdHHhsQw8mHxPMZR5k/s1350/Snap40.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggQGm023f8st0uxMfVwX0f-7lgyx7DX-Rr2lyYVMOdjTMSsNWhmOnqQsxspR6lsSCD2g9-13hw4p4SbrN4PLQxaOmyOnZlRxEN-himbg05SJIVQLB4q4TjajEgrcdHHhsQw8mHxPMZR5k/s1350/Snap40.png&quot; height=&quot;151&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;新增JDBCRealm，配置--server-config--安全性--範圍，按下新建，選擇JDBCRealm，&lt;/li&gt;
&lt;/ul&gt;
名稱：testAuth。&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;JAAS環境：jdbcRealm，這要注意就是jdbcRealm大小寫要一模一樣。&lt;/span&gt;&lt;br /&gt;
JNDI：jdbc/test，剛剛設定的JDBC名稱。主要用於連接資料庫使用。&lt;br /&gt;
使用表格名稱：view table名稱。&lt;br /&gt;
使用者名稱欄：username&lt;br /&gt;
密碼欄：password&lt;br /&gt;
群組表格：view table名稱。&lt;br /&gt;
群組名稱欄：role&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;摘要演算法：MD5，這裡要注意一下，Default為SHA-256，並注意資料表中密碼欄位請以MD5方式儲存，參考程式如下：&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; public String encoderByMd5(String str) throws UnsupportedEncodingException { &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;java.security.MessageDigest md5 = java.security.MessageDigest.getInstance(&quot;MD5&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return new String(org.apache.commons.codec.binary.Hex.encodeHex(md5.digest(str.getBytes())));&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
並按下儲存。&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqAzCjhkpDyFUb8KbGSqL1kq7Gf8Cf8fSFNY034krrlyEnfb3QU8_6kWpe0x4P8wEYHsV6s7zxiRqRetkTaXIOG3oSwh8x_L5FJVpY5o6FQbW362XU3GzrtN4vmSOtcHapIz3pjApBNNg/s1350/Snap41.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqAzCjhkpDyFUb8KbGSqL1kq7Gf8Cf8fSFNY034krrlyEnfb3QU8_6kWpe0x4P8wEYHsV6s7zxiRqRetkTaXIOG3oSwh8x_L5FJVpY5o6FQbW362XU3GzrtN4vmSOtcHapIz3pjApBNNg/s1350/Snap41.png&quot; height=&quot;150&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCrjqtUUAWjNAHNABGyUYOiv6fNSntVebMCkLlD8dheZMzNMwPLqGeMV6Nn_PaExK6uxJpMdQNADMLpHUWocQ9esaLdqn-64w1Vhkg9lDYViRByMEQVxIk0e7cH404HzIFuswgShimI2Y/s592/Snap42.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCrjqtUUAWjNAHNABGyUYOiv6fNSntVebMCkLlD8dheZMzNMwPLqGeMV6Nn_PaExK6uxJpMdQNADMLpHUWocQ9esaLdqn-64w1Vhkg9lDYViRByMEQVxIk0e7cH404HzIFuswgShimI2Y/s592/Snap42.png&quot; height=&quot;214&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;進行Application web.xml檔案設定，Netbeans中打開web.xml(也可以直接修改啦)，點選Security--Login Configuration，勾選選Form的選項&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
Form Login Page：輸入登入頁的路徑，請注意該頁面有幾個必要欄位，如下&lt;br /&gt;
&lt;br /&gt;
Form Action：j_security_check&lt;br /&gt;
Form Input：j_username及j_password&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Form Error Page：輸入登入失敗對應的路徑頁面。&lt;/div&gt;
&lt;div&gt;
Security Role：新增與role一樣的角色。&lt;/div&gt;
&lt;div&gt;
儲存檔案，重新啟動Glassfish，並Deploy Application，開啟Browser輸入Application網址，這時候應該不管輸入哪個網址都會redirect到Login的頁面囉。&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsdOA771awVovLA43ynvsFyxCwekmqvOtGYGCrRGhW-xlmKf-CzkWkhyTmwkE6ouSRWEkiDugh0sXsZTS7PmScHzqJWskcTT0fXHDWepw4qd07aB7QADw-Q3pZvIJsjZEoJTabEQcJVd4/s1366/Snap44.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsdOA771awVovLA43ynvsFyxCwekmqvOtGYGCrRGhW-xlmKf-CzkWkhyTmwkE6ouSRWEkiDugh0sXsZTS7PmScHzqJWskcTT0fXHDWepw4qd07aB7QADw-Q3pZvIJsjZEoJTabEQcJVd4/s1366/Snap44.png&quot; height=&quot;170&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
SSO補充：&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
有時候會有多組Application需要access同一Realm做到SSO的情形，就可以在配置--server-config--虛擬伺服器--選擇你要SSO的Server，通常與Realm同一台，將&lt;span style=&quot;color: red;&quot;&gt;SSO選項選擇已啟用&lt;/span&gt;，然後在其他特性中增加兩組特性。&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;sso-max-inactive-seconds：300&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;sso-reap-interval-seconds：60&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
按下儲存，重新啟動Glassfish，就可以兩組或兩組以上Application使用同一個realm，而且只要登入其中一組Application的Login頁面後，進入其他Application時就不用在登入了。&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_uTbkPDYGkYN_0o_pJpL1xUgOZFSEydn42SxlAVRKq1l8qBok7r-CeRIpJ90m5AaaDJSBHKJ1k4XBmySBVSvnlQXyPBSsC_6b-9NJkPJ8PCfMBWHNaT-REPjR2bveETgq18zjl3hBHbs/s1350/Snap47.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_uTbkPDYGkYN_0o_pJpL1xUgOZFSEydn42SxlAVRKq1l8qBok7r-CeRIpJ90m5AaaDJSBHKJ1k4XBmySBVSvnlQXyPBSsC_6b-9NJkPJ8PCfMBWHNaT-REPjR2bveETgq18zjl3hBHbs/s1350/Snap47.png&quot; height=&quot;151&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWrV-8M1Vu9MCvhgALdf-pSa7q2Dw4ACNqBc0QltrfnwRDd41drTBQ_Z0sD3SqyPmvep_qy9vYS6YNYbrIx29dRrM5egsFwdXAegQ7iHKGzonhBe247KSiV0AtX3ZiA1eL4UOqTz7GdpM/s1350/Snap48.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWrV-8M1Vu9MCvhgALdf-pSa7q2Dw4ACNqBc0QltrfnwRDd41drTBQ_Z0sD3SqyPmvep_qy9vYS6YNYbrIx29dRrM5egsFwdXAegQ7iHKGzonhBe247KSiV0AtX3ZiA1eL4UOqTz7GdpM/s1350/Snap48.png&quot; height=&quot;151&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://louiszspower.blogspot.com/feeds/8582442217259419500/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://louiszspower.blogspot.com/2013/06/java-eeglassfish-jaas-jdbc-realm-sso.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/8582442217259419500'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/8582442217259419500'/><link rel='alternate' type='text/html' href='http://louiszspower.blogspot.com/2013/06/java-eeglassfish-jaas-jdbc-realm-sso.html' title='Java EE(一)：Glassfish JAAS JDBC Realm 設定 &amp;  SSO補充'/><author><name>Louisz</name><uri>http://www.blogger.com/profile/15227162328934605700</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuq5rOe6t7hT-kppa8Fu3eLB6RzgYqY8I7hZyMmMKyeAVUNbzRxsj7SQQA1EyynM-Ac6FjR6PmyXhcfn6PiIsBkByRyY8nSu3CWpAlXTcOcfGjpUDCpSBge2ou1j770EY/s220/IMG_20170629_210051.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmsph9f1YlKfxDYelwjmaIePcTLFneN19N4k9jMhIFgqFMCH9pbPNjaenjGfHElIOCz6ccoKfeDanaFtcaqAqO-pdrkHuyuqkI6MDls6lXRQBR-_vr4o77dYCvRCfq6lBgRZpRQ8wrsiI/s72-c/Snap32.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553741655215810943.post-6373312230605056470</id><published>2013-06-22T01:55:00.000-07:00</published><updated>2013-06-22T02:01:57.070-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaEE"/><category scheme="http://www.blogger.com/atom/ns#" term="工作"/><title type='text'>我愛Java EE</title><content type='html'>Java EE 7千呼萬喚始出來，可以看看以下的連結喔&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.oracle.com/technetwork/java/javaee/overview/index.html&quot;&gt;Java EE 7 at Glance&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://m.h-online.com/developer/features/Java-EE-7-at-a-glance-1889207.html&quot;&gt;Developer Java EE 7&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.ithome.com.tw/itadm/article.php?c=80915&quot;&gt;Java EE 7支援HTML 5&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
目前Java EE是我開發專案的最愛，真的真的很方便，又快速，但是在台灣使用的人目前還是算少的，我現在公司主流還是&amp;nbsp;&lt;a href=&quot;http://struts.apache.org/development/2.x/&quot;&gt;Struts 2&lt;/a&gt;，我很努力很努力要引入Java EE，希望會有所成效咧。&lt;br /&gt;
&lt;br /&gt;
我不太想花時間介紹 Java EE的架構，想知道的可以Google一下應該就會知道了，我這裡會介紹用Netbeans + Java EE開發專案的方式，當中也會帶一下我的想法，我個人是以實作Prototype以Live Demo方式推專案，或許會有人說這不是很浪費時間嗎？而且又不是一定會是給你做，其實我的想法是如下：&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;成功率較高：可以讓客戶看到東西，客戶會比較有感覺。&lt;/li&gt;
&lt;li&gt;教育訓練 ：藉由Prototype可以訓練開發人員。&lt;/li&gt;
&lt;li&gt;累積經驗：在客戶的回饋跟訓練過程中，可以調整專案開發的方式，也可以開發相關模組。&lt;/li&gt;
&lt;/ol&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;&lt;ol&gt;
&lt;/ol&gt;
我一直說很快，那到底是如何快呢...就來做做看囉&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;先下載 Netbeans，現在是&lt;a href=&quot;https://netbeans.org/downloads/7.3/&quot;&gt;Netbeans 7.3&lt;/a&gt;(Netbeans7.3.1先不建議安裝)選擇All的那個下載囉，安裝Netbeans基本上都是Next就可以了。&lt;/li&gt;
&lt;li&gt;安裝後就可以啟動Netbeans，到 File-- New Project -- Java Web(左)-- Web Application(右)按下Next&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjiaE4CqV1ii67xTSIrThCEbj3EyBOKlAr7gjDIyA-ghoTfVsqHPqLk3-Oo284NxUASiU0c44h8cJJ4ymTY9cBqMwHWoFBR3VwJ2bX-XifasBpDgeiW1B7Ii0lV4vsXG0A4c6v9zWwFehE/s1600/Snap2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjiaE4CqV1ii67xTSIrThCEbj3EyBOKlAr7gjDIyA-ghoTfVsqHPqLk3-Oo284NxUASiU0c44h8cJJ4ymTY9cBqMwHWoFBR3VwJ2bX-XifasBpDgeiW1B7Ii0lV4vsXG0A4c6v9zWwFehE/s1600/Snap2.png&quot; height=&quot;179&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDkxVPMEPPwS-40Dg3psmzXWJtKEFBw1cQsMGAggjKz72CbQl7nX3E2LN54Z6Ph9qv7NbQdrNdrytVPJp8GT-onjqfT4Q0yPET1EQn5ka-L0rRpknh8OMorLYohNDqYnXT3zhkHBKMR_g/s1600/Snap3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDkxVPMEPPwS-40Dg3psmzXWJtKEFBw1cQsMGAggjKz72CbQl7nX3E2LN54Z6Ph9qv7NbQdrNdrytVPJp8GT-onjqfT4Q0yPET1EQn5ka-L0rRpknh8OMorLYohNDqYnXT3zhkHBKMR_g/s1600/Snap3.png&quot; height=&quot;219&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;Project Name輸入FirstJavaEE，按下Next&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh183Jxk7YlScIQEO9s7ZvrY6JWeE_dBplZpMBPmT56Bey1JxLZOQobcpRf05JeT4q3qYKv1TyXnNfDfTGuZ_lSo46wyGK0-XeagezU4BVN_WXs3TDPve-0P9PH2YNSJdkRXzw5-qW09YA/s1600/Snap6.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh183Jxk7YlScIQEO9s7ZvrY6JWeE_dBplZpMBPmT56Bey1JxLZOQobcpRf05JeT4q3qYKv1TyXnNfDfTGuZ_lSo46wyGK0-XeagezU4BVN_WXs3TDPve-0P9PH2YNSJdkRXzw5-qW09YA/s1600/Snap6.png&quot; height=&quot;217&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;接下來就要設定對應的Server、Java EE版本及Web的路徑了，這裡要注意的是因為是安裝Netbeans 7.3.1，所以預設安裝應該是Glassfish 4，在Java EE Version中可以選擇 Java EE 7或是6，我們這裡先用Java EE 6，之後我會在介紹Java EE 7，至於Context Path就以專案名稱就可以了，按下Next。&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkQjYNDg4tdXa38iNDi0ub38LkaKELs4-9Dsz3IkTyWh3IfYtN5s0fOBQghpB6abPzWzOADEq_AhOfmxIPsctuB1c-1ll3B2LFFwO2ShNidbPGoO8QYHYboxJyLNZ1F73HteD0ELfAz9w/s1600/Snap7.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkQjYNDg4tdXa38iNDi0ub38LkaKELs4-9Dsz3IkTyWh3IfYtN5s0fOBQghpB6abPzWzOADEq_AhOfmxIPsctuB1c-1ll3B2LFFwO2ShNidbPGoO8QYHYboxJyLNZ1F73HteD0ELfAz9w/s1600/Snap7.png&quot; height=&quot;217&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;選擇Framework，JavaServer Faces當然是首選囉，勾選後會出現JSF的設定選項，可以都不設定就按Next，因為JSF的實作很多可以使用，我大部分都使用&lt;a href=&quot;http://primefaces.org/&quot;&gt;Primefaces&lt;/a&gt;，所以選擇Component頁簽勾選Primefaces，所以需要按下More選擇Primefaces Library，另外要注意因為使用Primefaces若是有檔案上傳需求，要把fileupload的jar放進專案中，有需要者可以點選下載，按下Finish，基本上就完成了一個JavaEE專案的設定了。&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFTdtsNJw-T1VNm5Spc2GJdofDVgXpIDXc0Ec1sX1SDRCathptOFpbQPC_Um7NWynN9LZezwORlfXk6U5nzKuRfxZ0CRnyMcLrYDhyphenhyphenh84BxOlSpebHX5ZixOBhDQjlALDwYgezH2r7dbk/s1600/Snap10.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFTdtsNJw-T1VNm5Spc2GJdofDVgXpIDXc0Ec1sX1SDRCathptOFpbQPC_Um7NWynN9LZezwORlfXk6U5nzKuRfxZ0CRnyMcLrYDhyphenhyphenh84BxOlSpebHX5ZixOBhDQjlALDwYgezH2r7dbk/s1600/Snap10.png&quot; height=&quot;217&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjORrDybql9oGbIOioB_meKQtYZI87yM1CsRu0GX77YoJ3Da0J_KRYtvkIJqtlB8-FIVtcKLnDmMQYbpmhGG5l_IZKNgajd-IfWWQrULhHEVZg33uEyAuU_MG6IHB036e0OvMdvEZNbt5o/s1600/Snap9.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjORrDybql9oGbIOioB_meKQtYZI87yM1CsRu0GX77YoJ3Da0J_KRYtvkIJqtlB8-FIVtcKLnDmMQYbpmhGG5l_IZKNgajd-IfWWQrULhHEVZg33uEyAuU_MG6IHB036e0OvMdvEZNbt5o/s1600/Snap9.png&quot; height=&quot;165&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;Deploy專案並開啟瀏覽器測試一下囉。&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgg0J-s5BTTVPj_AkjARz4eZ2iCPxpf_vQmLSgP1sspt6QbCppu9MWR7IX6Zfgic_9W2KReM6hcrVsfPOa2Wyo0GIwcT7lfJwYNkl3doBlMeGjgAvHbHcl6W0e7ok9j6qPxwVlWDmbN6fU/s1600/Snap12.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgg0J-s5BTTVPj_AkjARz4eZ2iCPxpf_vQmLSgP1sspt6QbCppu9MWR7IX6Zfgic_9W2KReM6hcrVsfPOa2Wyo0GIwcT7lfJwYNkl3doBlMeGjgAvHbHcl6W0e7ok9j6qPxwVlWDmbN6fU/s1600/Snap12.png&quot; height=&quot;179&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipnpslukYvxrhybeQOLuOYpCjcoo0B5plS1-1wP1OPnwtaIbG2YcBTKHmiM-OsQEUL_bpVmYBSFNPgmtq3pUozm2zgAxGyHkCDtfap6dXC5xAltnjvY6ECNdMx24PRXcC2g_eQR4JIhgA/s1600/Snap13.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipnpslukYvxrhybeQOLuOYpCjcoo0B5plS1-1wP1OPnwtaIbG2YcBTKHmiM-OsQEUL_bpVmYBSFNPgmtq3pUozm2zgAxGyHkCDtfap6dXC5xAltnjvY6ECNdMx24PRXcC2g_eQR4JIhgA/s1600/Snap13.png&quot; height=&quot;165&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVoz7sBkJo8EmZ4_A0cbxWAbbrM3quvrHbYelg4Lrb30KToDvQGEgs1Pb6nMPsOSc1Mw7KdPdturE7ifqEj_Tef0HpeeEN2iWuCdG9i3tV87aDs_h915kIxxxsN_70xof5cm79xb3o6hs/s1600/Snap14.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVoz7sBkJo8EmZ4_A0cbxWAbbrM3quvrHbYelg4Lrb30KToDvQGEgs1Pb6nMPsOSc1Mw7KdPdturE7ifqEj_Tef0HpeeEN2iWuCdG9i3tV87aDs_h915kIxxxsN_70xof5cm79xb3o6hs/s1600/Snap14.png&quot; height=&quot;169&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwHTbYHNOL_aCuaPnZSeOHxRCYGTgnqAxNth64hchDMat6vIzb7bQJq2Wv2_pFsBDCxF_uHg77EyaEyuFH_3v-iFrTtNRqA-6EqBoFXCEgKSJVY_n4mTr0IHrY3WckXzuehouU7Wml0Oo/s1600/Snap15.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwHTbYHNOL_aCuaPnZSeOHxRCYGTgnqAxNth64hchDMat6vIzb7bQJq2Wv2_pFsBDCxF_uHg77EyaEyuFH_3v-iFrTtNRqA-6EqBoFXCEgKSJVY_n4mTr0IHrY3WckXzuehouU7Wml0Oo/s1600/Snap15.png&quot; height=&quot;169&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;當然這樣還是不夠囉，進行CRUD頁面製作囉，先Create JPA(Model)，ProjectName按下滑鼠右鍵，選擇 New -- Entities Classes from database，於Data Source選擇jdbc/sample，然後再選擇Customer(左)將其Add過去，並按下Next，然後輸入Package，這裡先輸入sample.test，就一直Next下去直到Finish，它會產生對應資料表的Entities。&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwmFa0sod2pnpnL3csn_aPEKMVz5njio3Z-HPLlrtf-PxJjlLhPdmtlL3aZk0GbRoO5B6-dYTfhQGfq-XOUfiwyLwFZUMSKkqATD0XwHlstGe7Sw1zeaSRG2PBk2yYwPBFQwIKWrQQfyo/s1600/Snap18.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwmFa0sod2pnpnL3csn_aPEKMVz5njio3Z-HPLlrtf-PxJjlLhPdmtlL3aZk0GbRoO5B6-dYTfhQGfq-XOUfiwyLwFZUMSKkqATD0XwHlstGe7Sw1zeaSRG2PBk2yYwPBFQwIKWrQQfyo/s1600/Snap18.png&quot; height=&quot;226&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdq0XessnjOD6Tf_bUEtoxgM1PdNyO5meEl-GlRrxTFA5w2SfkTbM7Mn2bSlsHfLz5x5O37u1i0aMjuLndEqp0vTBSiJl4-8xSLrawbsNroAw-BZ6RVSCs4nsJlWyiX6YvEszvHJd87eU/s1600/Snap20.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdq0XessnjOD6Tf_bUEtoxgM1PdNyO5meEl-GlRrxTFA5w2SfkTbM7Mn2bSlsHfLz5x5O37u1i0aMjuLndEqp0vTBSiJl4-8xSLrawbsNroAw-BZ6RVSCs4nsJlWyiX6YvEszvHJd87eU/s1600/Snap20.png&quot; height=&quot;213&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwg7mBAbhGWHZILWOVcYdcoE7NLPOFw8YCXiQrYQKaPtsnUnQINXJ6ZS_sYooUFi_j5Uu8w42lODgCn5eiZgF3scGif8P0Bld5Dot9wz0iczqv3tyzsfBB6HptMH8LvxKwNGQBPqVOfvI/s1600/Snap21.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwg7mBAbhGWHZILWOVcYdcoE7NLPOFw8YCXiQrYQKaPtsnUnQINXJ6ZS_sYooUFi_j5Uu8w42lODgCn5eiZgF3scGif8P0Bld5Dot9wz0iczqv3tyzsfBB6HptMH8LvxKwNGQBPqVOfvI/s1600/Snap21.png&quot; height=&quot;213&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhAk0h01Ib6knldpXTmqXcvqN4Rq6z_7gLXbZIo1KtbZKMXYUVKxbOzEODMEnDvjPCWXu2Ysg_agtW0uhFaCs7DC3sqjSYVehGUnIoP24IERsk1-zOX7QIp3oRYAOa_y67-Mc0wIYx3H0/s1600/Snap22.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhAk0h01Ib6knldpXTmqXcvqN4Rq6z_7gLXbZIo1KtbZKMXYUVKxbOzEODMEnDvjPCWXu2Ysg_agtW0uhFaCs7DC3sqjSYVehGUnIoP24IERsk1-zOX7QIp3oRYAOa_y67-Mc0wIYx3H0/s1600/Snap22.png&quot; height=&quot;165&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;接下來就create JSF(View &amp;amp; Controllor)，rojectName按下滑鼠右鍵，選擇 New -- JSF Pages from Entities，把所有的Entities(左) Add All，然後按下Next及Finish。&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4eRIo9Peb3Nfb04qUg0ImVHEIVv8DroLylxiMc3lZufoGHpMcYaYHvx5wADrF2aMVDwAovVjU6dKpCQBKmc95ZIKm7YMhvuNa3IsFRrOruClEJMF6sg0sbCD4DDjOhOaic7x96pM4Ors/s1600/Snap23.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4eRIo9Peb3Nfb04qUg0ImVHEIVv8DroLylxiMc3lZufoGHpMcYaYHvx5wADrF2aMVDwAovVjU6dKpCQBKmc95ZIKm7YMhvuNa3IsFRrOruClEJMF6sg0sbCD4DDjOhOaic7x96pM4Ors/s1600/Snap23.png&quot; height=&quot;170&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieeuZoUDyohiUIBFHS3TkeVk99sNakL1lFrmR4h_ij_B4QH5L7cvpxUhwL5PZP2PuPO6xZE-5W42Dz8gANITx2E8rmGu9sXmBvQ9W4UGD1F-VeiP_ap1aqRd7CgGVg7dEuE4zgjBYb7Zw/s1600/Snap24.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieeuZoUDyohiUIBFHS3TkeVk99sNakL1lFrmR4h_ij_B4QH5L7cvpxUhwL5PZP2PuPO6xZE-5W42Dz8gANITx2E8rmGu9sXmBvQ9W4UGD1F-VeiP_ap1aqRd7CgGVg7dEuE4zgjBYb7Zw/s1600/Snap24.png&quot; height=&quot;194&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-ts1EV9vu-724sXYO00yhaY35o4fJYfRbSyPNKvXG_yMEeplmUgMWCp1KTpAHIFFpX0MVvfdLZuDZ2KQKOdhReufd7vdGc5ZiYELC4Lg6iDecFhPOeEOimPdtqP1xhT7rrIEsVGpsDIg/s1600/Snap25.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-ts1EV9vu-724sXYO00yhaY35o4fJYfRbSyPNKvXG_yMEeplmUgMWCp1KTpAHIFFpX0MVvfdLZuDZ2KQKOdhReufd7vdGc5ZiYELC4Lg6iDecFhPOeEOimPdtqP1xhT7rrIEsVGpsDIg/s1600/Snap25.png&quot; height=&quot;198&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;進行測試，在customer目錄中的List.xhtml按下滑鼠右鍵Run File，有出現最後的畫面就是OK了，可以試試看可不可以增刪修囉，另外就是可以把元件改成Primefaces會更漂亮喔，下次再來介紹Primefaces。&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZElRpI9Lu-Pzvc65xSmGLBdl2PCXdCOIzrlL-EWh9u_E6_Lrm9z2kXtYhXLLX8LA2bJcWVr1hyphenhyphenMQrgoONOvrnFp9Uag45kUEeBMZqc96lTUBtiFf9lhAYcA8dlg5c75OgF8bbtisvW04/s1600/Snap28.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZElRpI9Lu-Pzvc65xSmGLBdl2PCXdCOIzrlL-EWh9u_E6_Lrm9z2kXtYhXLLX8LA2bJcWVr1hyphenhyphenMQrgoONOvrnFp9Uag45kUEeBMZqc96lTUBtiFf9lhAYcA8dlg5c75OgF8bbtisvW04/s1600/Snap28.png&quot; height=&quot;170&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMlfcaoPslxMZI6qJKFLvQucFcJ6WYYCAI8Ab0gC8gp0G8x7WqQCSMkIkmsiXe8vqxVUZDPTVoZgd1hZWpoArPoN_oYD7xiPi6LDGR80mfj0YNLgXtWq_FfvrihAFOJRxE7LMV39nZdvw/s1600/Snap27.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMlfcaoPslxMZI6qJKFLvQucFcJ6WYYCAI8Ab0gC8gp0G8x7WqQCSMkIkmsiXe8vqxVUZDPTVoZgd1hZWpoArPoN_oYD7xiPi6LDGR80mfj0YNLgXtWq_FfvrihAFOJRxE7LMV39nZdvw/s1600/Snap27.png&quot; height=&quot;169&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://louiszspower.blogspot.com/feeds/6373312230605056470/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://louiszspower.blogspot.com/2013/06/java-ee-7.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/6373312230605056470'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/6373312230605056470'/><link rel='alternate' type='text/html' href='http://louiszspower.blogspot.com/2013/06/java-ee-7.html' title='我愛Java EE'/><author><name>Louisz</name><uri>http://www.blogger.com/profile/15227162328934605700</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuq5rOe6t7hT-kppa8Fu3eLB6RzgYqY8I7hZyMmMKyeAVUNbzRxsj7SQQA1EyynM-Ac6FjR6PmyXhcfn6PiIsBkByRyY8nSu3CWpAlXTcOcfGjpUDCpSBge2ou1j770EY/s220/IMG_20170629_210051.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjiaE4CqV1ii67xTSIrThCEbj3EyBOKlAr7gjDIyA-ghoTfVsqHPqLk3-Oo284NxUASiU0c44h8cJJ4ymTY9cBqMwHWoFBR3VwJ2bX-XifasBpDgeiW1B7Ii0lV4vsXG0A4c6v9zWwFehE/s72-c/Snap2.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553741655215810943.post-3978789921273914125</id><published>2013-06-20T00:32:00.000-07:00</published><updated>2013-06-22T02:02:11.282-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="AR"/><title type='text'>mixare：Augmented Reality(AR) Open Source Library (一)</title><content type='html'>&lt;h3 class=&quot;post-title entry-title&quot; itemprop=&quot;name&quot; style=&quot;background-color: white; color: #333333; font-family: Verdana, Arial, sans-serif; font-size: 16px; line-height: 1.1em; margin: 0px; padding: 0px;&quot;&gt;
上一篇介紹&lt;a href=&quot;http://louiszspower.blogspot.tw/2013/06/augmented-realityar.html&quot;&gt;AR的概念&lt;/a&gt;，這次來介紹一下一些Open Source的Library-&lt;a href=&quot;http://www.mixare.org/&quot;&gt;mixare&lt;/a&gt;，透過mixare就可以開發出一些東西囉，話不多說就先來用用看囉。&lt;/h3&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
以App的方式進行開發，雖然說可以透過CCD使用，但是用行動裝置總是比較方便，而且mixare也是以App來介紹。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;可以去下載&lt;a href=&quot;http://developer.android.com/sdk/index.html#win-bundle&quot;&gt;Android SDK&lt;/a&gt;，現在已經有內含eclipse囉，就直接使用解壓縮後的eclipse。&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;先去下載&amp;nbsp;&lt;a href=&quot;https://github.com/mixare/mixare&quot;&gt;mixare source&lt;/a&gt;，選擇ZIP整個檔案下載，解壓縮後，先將mixare、mixare lib及其他的plugin import eclipse。&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3u4SCkCNqSj0n5KADGlcs2QX2H6R8Lp0FKJjFO4M3nRLjeGZkdZUwSDyY47o-ArLVEBp_K4ZX7vdLP3_PJnLhGIVmJn9aS-3L09XBu9l4bOqFq4of32-cBc2xVvJpwDjk1fCB0Tck2zI/s1600/Snap1.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3u4SCkCNqSj0n5KADGlcs2QX2H6R8Lp0FKJjFO4M3nRLjeGZkdZUwSDyY47o-ArLVEBp_K4ZX7vdLP3_PJnLhGIVmJn9aS-3L09XBu9l4bOqFq4of32-cBc2xVvJpwDjk1fCB0Tck2zI/s1600/Snap1.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; display: inline !important; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3u4SCkCNqSj0n5KADGlcs2QX2H6R8Lp0FKJjFO4M3nRLjeGZkdZUwSDyY47o-ArLVEBp_K4ZX7vdLP3_PJnLhGIVmJn9aS-3L09XBu9l4bOqFq4of32-cBc2xVvJpwDjk1fCB0Tck2zI/s1600/Snap1.png&quot; height=&quot;32&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3u4SCkCNqSj0n5KADGlcs2QX2H6R8Lp0FKJjFO4M3nRLjeGZkdZUwSDyY47o-ArLVEBp_K4ZX7vdLP3_PJnLhGIVmJn9aS-3L09XBu9l4bOqFq4of32-cBc2xVvJpwDjk1fCB0Tck2zI/s1600/Snap1.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;br /&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3u4SCkCNqSj0n5KADGlcs2QX2H6R8Lp0FKJjFO4M3nRLjeGZkdZUwSDyY47o-ArLVEBp_K4ZX7vdLP3_PJnLhGIVmJn9aS-3L09XBu9l4bOqFq4of32-cBc2xVvJpwDjk1fCB0Tck2zI/s1600/Snap1.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;br /&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3u4SCkCNqSj0n5KADGlcs2QX2H6R8Lp0FKJjFO4M3nRLjeGZkdZUwSDyY47o-ArLVEBp_K4ZX7vdLP3_PJnLhGIVmJn9aS-3L09XBu9l4bOqFq4of32-cBc2xVvJpwDjk1fCB0Tck2zI/s1600/Snap1.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;br /&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3u4SCkCNqSj0n5KADGlcs2QX2H6R8Lp0FKJjFO4M3nRLjeGZkdZUwSDyY47o-ArLVEBp_K4ZX7vdLP3_PJnLhGIVmJn9aS-3L09XBu9l4bOqFq4of32-cBc2xVvJpwDjk1fCB0Tck2zI/s1600/Snap1.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;br /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuWZ6tT2dlZceTyW5VsLV5wMvxFTftUv4ZwsPspkIBdk6Jc3QULjhCGqvn2HQluasou98qPdgMt4KbQrg8pE5466f1yMx6HEpT0RHkpeqX0QIryo9cdUJpNHOT9hztvUgVYPjeaAPVN2k/s1600/Snap2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuWZ6tT2dlZceTyW5VsLV5wMvxFTftUv4ZwsPspkIBdk6Jc3QULjhCGqvn2HQluasou98qPdgMt4KbQrg8pE5466f1yMx6HEpT0RHkpeqX0QIryo9cdUJpNHOT9hztvUgVYPjeaAPVN2k/s1600/Snap2.png&quot; height=&quot;179&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLrgsiaJqmoKxr_O6SHwQ3tZa_Z0fAye0O_XQk6J0PjhOkWtxCcN9-7wMIFVVZ9NGJ5wh74bA0Z90eSE7Oe3_Pyu9pRqCjoxcpYyfRqQxbmxJOrmc4JAu2uU_x7NpyzhXJhRY3HQ4ijLo/s1600/Snap3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLrgsiaJqmoKxr_O6SHwQ3tZa_Z0fAye0O_XQk6J0PjhOkWtxCcN9-7wMIFVVZ9NGJ5wh74bA0Z90eSE7Oe3_Pyu9pRqCjoxcpYyfRqQxbmxJOrmc4JAu2uU_x7NpyzhXJhRY3HQ4ijLo/s1600/Snap3.png&quot; height=&quot;179&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXYyNCjbAleG2eo_Ywxhc50ZxOU-cwNaScZk2AYB5zlwWLKOP8VAMI6EWwgKt4-_mH2VCVqe3B49JTjW0h0M7Fc1NRDmIyAgtsWstj5iBPAhfFYUS13lUHQsZxrcBtgkQOvaCBoUm9Fuc/s1600/Snap4.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXYyNCjbAleG2eo_Ywxhc50ZxOU-cwNaScZk2AYB5zlwWLKOP8VAMI6EWwgKt4-_mH2VCVqe3B49JTjW0h0M7Fc1NRDmIyAgtsWstj5iBPAhfFYUS13lUHQsZxrcBtgkQOvaCBoUm9Fuc/s1600/Snap4.png&quot; height=&quot;179&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjl1Q3g9cI6yxcdpciaPswwXZmgImg7DgNMCL-R6DtYXfyXU5ods2Ds31jJ-UUEkF1TGqWDJQRtgSRqceSuAEbqzM_OIXvzgBOUNPUlavwGT0su9zo1FrMdS0jIHem-FGv07wBb6AoV0qI/s1600/Snap6.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjl1Q3g9cI6yxcdpciaPswwXZmgImg7DgNMCL-R6DtYXfyXU5ods2Ds31jJ-UUEkF1TGqWDJQRtgSRqceSuAEbqzM_OIXvzgBOUNPUlavwGT0su9zo1FrMdS0jIHem-FGv07wBb6AoV0qI/s1600/Snap6.png&quot; height=&quot;179&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;一開始相關project除了mixarelib project其他應該都有錯誤訊息，檢查一下bin目錄下有沒有mixarelib.jar，也可以直接執行build.xml產出。&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiiVrnzOwx73Kvt9cfHGzgzQFW52OZWr4FkW03fx45YM9MCzP69cr9baEHZTFyFCsSg7pz7PeXIGTy22t2PJMMaNf3cS4S-E1I_4Mcpz-1j9CIdKSfIaAr0TW-Ft8mL0GYl0jU2uy0nl04/s1600/Snap13.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiiVrnzOwx73Kvt9cfHGzgzQFW52OZWr4FkW03fx45YM9MCzP69cr9baEHZTFyFCsSg7pz7PeXIGTy22t2PJMMaNf3cS4S-E1I_4Mcpz-1j9CIdKSfIaAr0TW-Ft8mL0GYl0jU2uy0nl04/s1600/Snap13.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_69o1gWjw-YLms_Ssp0lyS9web9HnpTdG0iHeLsHMfCmYzZbbWC_f7QoqtZrs6MOmx_s-5Rj6lHtgY4LytmEW2Tt3R6CLN6TDSdRF93x466DZ0Jcxo5JPQkj_AF27HzJ1e7GI1D1rKUs/s1600/Snap14.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_69o1gWjw-YLms_Ssp0lyS9web9HnpTdG0iHeLsHMfCmYzZbbWC_f7QoqtZrs6MOmx_s-5Rj6lHtgY4LytmEW2Tt3R6CLN6TDSdRF93x466DZ0Jcxo5JPQkj_AF27HzJ1e7GI1D1rKUs/s1600/Snap14.png&quot; height=&quot;179&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6mtUwWVj5eOVFqleX0dhnHZhP4cPLbPJQ2zQ07ICXA8FoRp930KF8TERGeZziHXz_Us_qYRtH4Pif-50xSjzDWb1e8pldoy3V2sAS5x98JZR5fL-5AyA_lIXWY3DBb7KHKNt2EaJ3Z9g/s1600/Snap15.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6mtUwWVj5eOVFqleX0dhnHZhP4cPLbPJQ2zQ07ICXA8FoRp930KF8TERGeZziHXz_Us_qYRtH4Pif-50xSjzDWb1e8pldoy3V2sAS5x98JZR5fL-5AyA_lIXWY3DBb7KHKNt2EaJ3Z9g/s1600/Snap15.png&quot; height=&quot;179&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;mixare主專案中右鍵 Properties---Android應該會看到有紅色XX的標記，按下remove移除掉，並按下Add增加剛剛設定的mixarelib。&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYlH8AiJHsHdYNhKJUQv6xh4b39euNpIIgE6KRH9Ykx-0IAdaQKNJrFi8SaPYIbMlcTJBGJlwJRoHCsjBqXloyP94G0gpfGd6AZC1Xccz7EEW1x0dft032PCPlt7jy0hJHGvCQEG88hHk/s1600/Snap16.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYlH8AiJHsHdYNhKJUQv6xh4b39euNpIIgE6KRH9Ykx-0IAdaQKNJrFi8SaPYIbMlcTJBGJlwJRoHCsjBqXloyP94G0gpfGd6AZC1Xccz7EEW1x0dft032PCPlt7jy0hJHGvCQEG88hHk/s1600/Snap16.png&quot; height=&quot;179&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2TDXbgROJfa525c3BGJGIZli69yOtG7fOndMqzmpzPHUQVq4PJvFCLkUoAU16sJe-DaxoW6Wlnmg_m40cr74LB3bw1wJaaRJ3tjPiivOPEYsCDJXFk5vkxHfgaEVbiBSBkKE-_07pLck/s1600/Snap17.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2TDXbgROJfa525c3BGJGIZli69yOtG7fOndMqzmpzPHUQVq4PJvFCLkUoAU16sJe-DaxoW6Wlnmg_m40cr74LB3bw1wJaaRJ3tjPiivOPEYsCDJXFk5vkxHfgaEVbiBSBkKE-_07pLck/s1600/Snap17.png&quot; height=&quot;220&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQiR9egGouXBFldxZBJDFEf5nL0P5JXEkKRAIIPZlNgZzpTLGSt_NIqAnpCl3UflnW38EJXaf8sWIZg_SjayD0BU4QrtJrMYqwG7bc1gvJ1toC97l3dhE1sblUh7vMbafVuoMcKid1bEY/s1600/Snap18.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQiR9egGouXBFldxZBJDFEf5nL0P5JXEkKRAIIPZlNgZzpTLGSt_NIqAnpCl3UflnW38EJXaf8sWIZg_SjayD0BU4QrtJrMYqwG7bc1gvJ1toC97l3dhE1sblUh7vMbafVuoMcKid1bEY/s1600/Snap18.png&quot; height=&quot;288&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;mixare主專案中有些錯誤，如getColour及implements介面少了一些method，修改一下就好了。把她Deploy到手機上就可以了，不過我覺得他有個Bug就是連不到相關的DataSources時就一直跳出錯誤訊息不是那麼好，連不到了不起就變成相機囉，這部分我會調整一下，之後在分享囉。&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://louiszspower.blogspot.com/feeds/3978789921273914125/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://louiszspower.blogspot.com/2013/06/mixareaugmented-realityar-open-source.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/3978789921273914125'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/3978789921273914125'/><link rel='alternate' type='text/html' href='http://louiszspower.blogspot.com/2013/06/mixareaugmented-realityar-open-source.html' title='mixare：Augmented Reality(AR) Open Source Library (一)'/><author><name>Louisz</name><uri>http://www.blogger.com/profile/15227162328934605700</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuq5rOe6t7hT-kppa8Fu3eLB6RzgYqY8I7hZyMmMKyeAVUNbzRxsj7SQQA1EyynM-Ac6FjR6PmyXhcfn6PiIsBkByRyY8nSu3CWpAlXTcOcfGjpUDCpSBge2ou1j770EY/s220/IMG_20170629_210051.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3u4SCkCNqSj0n5KADGlcs2QX2H6R8Lp0FKJjFO4M3nRLjeGZkdZUwSDyY47o-ArLVEBp_K4ZX7vdLP3_PJnLhGIVmJn9aS-3L09XBu9l4bOqFq4of32-cBc2xVvJpwDjk1fCB0Tck2zI/s72-c/Snap1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553741655215810943.post-6171021420908617219</id><published>2013-06-08T19:59:00.001-07:00</published><updated>2013-06-22T02:02:24.049-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="AR"/><title type='text'>Augmented Reality(AR)擴增實境要起飛囉...</title><content type='html'>因為公司每年都會舉辦創新競賽，讓大家可以提一些點子，看看有沒有市場機會，雖然我覺得技術創新遠比市場機會大，可是偶也不是老大，又為了獎金，所以囉為了五斗米折腰，原本是要提的是&lt;a href=&quot;http://phonegap.com/&quot; title=&quot;PhoneGap&quot;&gt;PhoneGap&lt;/a&gt;(之後也會介紹，是個好物啊!)，結果在搜尋時看到了&lt;a href=&quot;http://www.wikitude.com/&quot; title=&quot;wikitude&quot;&gt;wikitude&lt;/a&gt; ，就一路的看到AR這技術，它不算是新技術，很早就有人提出來了，但是隨著行動裝置的流行，這技術也被重新吵起來，然後&lt;a href=&quot;http://www.google.com/glass/start/&quot; title=&quot;Google Glass&quot;&gt;Google Glass&lt;/a&gt;也算是推力。&lt;br /&gt;
&lt;br /&gt;
它的概念其實是透過設備如手機上相機、眼鏡、CCD，將所看到的真實且即時的影像，混合虛擬的東西，如看到的人頭上找出角，戴上皇冠或是加上鬍子等等，如&lt;a href=&quot;http://handheldar.icg.tugraz.at/artoolkitplus.php&quot;&gt;AR Toolkit&lt;/a&gt;、&lt;a href=&quot;http://www.artag.net/&quot;&gt;AR tag&lt;/a&gt;，若是在加上GPS及Compass，就可以增加區域地點及距離的判斷，如&lt;a href=&quot;http://www.mixare.org/&quot;&gt;mixare&lt;/a&gt;、wikitude、&lt;a href=&quot;https://code.google.com/p/droidar/&quot;&gt;DroidAR&lt;/a&gt;。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;
先介紹一下wikitude，網站上有提供SDK，目前有三種行動裝置的平台可以用，Android、iOS、BlackBlerry 10，也有PhoneGap的plugin，也就是可以走Hybird App的方式，進到網站可以看看showcase，最讓我感到興趣的是&lt;a href=&quot;http://www.wikitude.com/showcase/ice-age-4-scrats-nut-hunt-game-powered-wikitude/&quot; title=&quot;冰原歷險記&quot;&gt;冰原歷險記&lt;/a&gt;的遊戲，大致上AR的應用遊戲是一個很好的方向；&lt;a href=&quot;http://handheldar.icg.tugraz.at/artoolkitplus.php&quot;&gt;AR Toolkit&lt;/a&gt;、&lt;a href=&quot;http://www.artag.net/&quot;&gt;AR tag&lt;/a&gt; 有滿完整的API可以玩玩看，而且又是Open Source，不過相關的演算邏輯倒是很複雜，建議知道如何拿來用就好。&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.mixare.org/&quot;&gt;mixare&lt;/a&gt; 我個人認為是AR入門首選，因為有搭配行動裝置及資料格式有JSON，很容易與Web Ap搭配起來，稍稍修改一下增加一些圖像，就可以做出一些東西出來，之後陸續會先以這個來介紹AR。&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.metaio.com/home/&quot;&gt;metaio&lt;/a&gt;這最近才開始碰，跟wikitude很像，showcase的idea倒很實用。&lt;br /&gt;
最後總結一下，AR技術不會很困難，但他可提供出創意的腦力激盪，我個人認為AR一定很好用，但是創意則是出線的關鍵。&lt;br /&gt;
&lt;br /&gt;
下一篇就來介紹 mixare的使用囉。</content><link rel='replies' type='application/atom+xml' href='http://louiszspower.blogspot.com/feeds/6171021420908617219/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://louiszspower.blogspot.com/2013/06/augmented-realityar.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/6171021420908617219'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/6171021420908617219'/><link rel='alternate' type='text/html' href='http://louiszspower.blogspot.com/2013/06/augmented-realityar.html' title='Augmented Reality(AR)擴增實境要起飛囉...'/><author><name>Louisz</name><uri>http://www.blogger.com/profile/15227162328934605700</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuq5rOe6t7hT-kppa8Fu3eLB6RzgYqY8I7hZyMmMKyeAVUNbzRxsj7SQQA1EyynM-Ac6FjR6PmyXhcfn6PiIsBkByRyY8nSu3CWpAlXTcOcfGjpUDCpSBge2ou1j770EY/s220/IMG_20170629_210051.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553741655215810943.post-311349873705344619</id><published>2013-03-01T01:36:00.000-08:00</published><updated>2013-06-22T02:02:42.019-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="CAS"/><title type='text'>Jasig CAS SSO 安裝篇</title><content type='html'>最近在玩SSO CAS，Open Source的Jasig CAS我覺得很好入手，之後就慢慢介紹囉。&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
先以Tomcat 7.0.37為Ap Server，&lt;/div&gt;
&lt;div&gt;
OS：Window。&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;先安裝JDK及安裝&lt;a href=&quot;http://tomcat.apache.org/download-70.cgi&quot;&gt;Tomcat&lt;/a&gt;。&lt;/li&gt;
&lt;li&gt;再下載&lt;a href=&quot;http://www.jasig.org/cas_server_3_5_2_release&quot;&gt;Jasig CAS Server&lt;/a&gt;，並解開壓縮檔。&lt;/li&gt;
&lt;li&gt;解開後會有很多目錄，都是cas-server-xxxx這些都是source，若是有需求可以自行修改，然後用Maven修改。本次因為只有安裝所以就用modules的目錄就可以囉，複製cas-server-webapp-x.x.x.war到Tomcat\webapps目錄下。&lt;/li&gt;
&lt;li&gt;先啟動Tomcat，正常的話應該是可以正常啟動，然後打開Browser輸入http://hostname:8080/cas-server-webapp-x.x.x/login，應該會看到登入畫面但是有警示，你要使用SSL表示快成功了。&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;設定Tomcat SSL步驟，進入Command line模式，&lt;/li&gt;
&lt;/ul&gt;
&lt;ol&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: 13.333333969116211px; line-height: 1.3;&quot;&gt;產生SSL Server憑證請求檔：&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ol&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: 13px; line-height: 17px;&quot;&gt;JAVA_HOME%\bin\keytool -genkey -alias tomcat -keypass changeit -keyalg RSA&lt;/span&gt;&lt;/blockquote&gt;
&lt;ol&gt;&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: 13.333333969116211px; line-height: 1.3;&quot;&gt;匯出憑證請求檔：&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ol&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: 13.333333969116211px; line-height: 1.3;&quot;&gt;%JAVA_HOME%\bin\keytool -export -alias tomcat -keypass changeit  -file server.crt&lt;/span&gt;&lt;/blockquote&gt;
&lt;ol&gt;&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: 13.333333969116211px; line-height: 1.3;&quot;&gt;匯入憑證請求檔於CA信任根目錄下：&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ol&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: 13.333333969116211px; line-height: 1.3;&quot;&gt;%JAVA_HOME%\bin\keytool -import -file server.crt -keypass changeit -keystore %JAVA_HOME%/jre/lib/security/cacerts&lt;/span&gt;&lt;/blockquote&gt;
&lt;ol&gt;&lt;ul&gt;
&lt;li&gt;建議先將%JAVA_HOME%/bin加入PATH中比較方便，過程中要注意一下關於產生的檔案及匯入CA時權限的問題，也要注意一下keystore的位置，Tomcat會用到。&lt;/li&gt;
&lt;/ul&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;將.keystore複製到指定目錄(可以自行指定)，修改Tomcat Server.xml尋找到被mark起來的&lt;/li&gt;
&lt;/ul&gt;
&lt;ol&gt;
&lt;/ol&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;ol class=&quot;dp-xml&quot; start=&quot;1&quot; style=&quot;background-color: white; border: 1px solid rgb(209, 215, 220); color: #2b91af; font-family: Monaco, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, Consolas, &#39;Courier New&#39;, monospace; font-size: 12px; line-height: 1.4em; list-style-image: initial; list-style-position: initial; margin: 0px 0px 1px; padding: 2px 0px;&quot;&gt;
&lt;li style=&quot;background-color: #fafafa; border-left-color: rgb(209, 215, 220); border-left-style: solid; border-left-width: 1px; font-size: 1em; line-height: 18px; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span class=&quot;tag&quot; style=&quot;color: #006699; font-weight: bold;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;tag-name&quot; style=&quot;color: #006699; font-weight: bold;&quot;&gt;Connector&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;attribute&quot; style=&quot;color: red;&quot;&gt;port&lt;/span&gt;=&lt;span class=&quot;attribute-value&quot; style=&quot;color: blue;&quot;&gt;&quot;8443&quot;&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;attribute&quot; style=&quot;color: red;&quot;&gt;protocol&lt;/span&gt;=&lt;span class=&quot;attribute-value&quot; style=&quot;color: blue;&quot;&gt;&quot;HTTP/1.1&quot;&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;attribute&quot; style=&quot;color: red;&quot;&gt;SSLEnabled&lt;/span&gt;=&lt;span class=&quot;attribute-value&quot; style=&quot;color: blue;&quot;&gt;&quot;true&quot;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;background-color: #fafafa; border-left-color: rgb(209, 215, 220); border-left-style: solid; border-left-width: 1px; font-size: 1em; line-height: 18px; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;attribute&quot; style=&quot;color: red;&quot;&gt;maxThreads&lt;/span&gt;=&lt;span class=&quot;attribute-value&quot; style=&quot;color: blue;&quot;&gt;&quot;150&quot;&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;attribute&quot; style=&quot;color: red;&quot;&gt;scheme&lt;/span&gt;=&lt;span class=&quot;attribute-value&quot; style=&quot;color: blue;&quot;&gt;&quot;https&quot;&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;attribute&quot; style=&quot;color: red;&quot;&gt;secure&lt;/span&gt;=&lt;span class=&quot;attribute-value&quot; style=&quot;color: blue;&quot;&gt;&quot;true&quot;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;background-color: #fafafa; border-left-color: rgb(209, 215, 220); border-left-style: solid; border-left-width: 1px; font-size: 1em; line-height: 18px; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;attribute&quot; style=&quot;color: red;&quot;&gt;clientAuth&lt;/span&gt;=&lt;span class=&quot;attribute-value&quot; style=&quot;color: blue;&quot;&gt;&quot;false&quot;&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;attribute&quot; style=&quot;color: red;&quot;&gt;sslProtocol&lt;/span&gt;=&lt;span class=&quot;attribute-value&quot; style=&quot;color: blue;&quot;&gt;&quot;TLS&quot;&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;tag&quot; style=&quot;color: #006699; font-weight: bold;&quot;&gt;/&amp;gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div&gt;
改成&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;ol class=&quot;dp-xml&quot; start=&quot;1&quot; style=&quot;background-color: white; border: 1px solid rgb(209, 215, 220); color: #2b91af; font-family: Monaco, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, Consolas, &#39;Courier New&#39;, monospace; font-size: 12px; line-height: 1.4em; list-style-image: initial; list-style-position: initial; margin: 0px 0px 1px; padding: 2px 0px;&quot;&gt;
&lt;li style=&quot;background-color: #fafafa; border-left-color: rgb(209, 215, 220); border-left-style: solid; border-left-width: 1px; font-size: 1em; line-height: 18px; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span class=&quot;tag&quot; style=&quot;color: #006699; font-weight: bold;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;tag-name&quot; style=&quot;color: #006699; font-weight: bold;&quot;&gt;Connector&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;attribute&quot; style=&quot;color: red;&quot;&gt;port&lt;/span&gt;=&lt;span class=&quot;attribute-value&quot; style=&quot;color: blue;&quot;&gt;&quot;8443&quot;&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;attribute&quot; style=&quot;color: red;&quot;&gt;protocol&lt;/span&gt;=&lt;span class=&quot;attribute-value&quot; style=&quot;color: blue;&quot;&gt;&quot;org.apache.coyote.http11.Http11Protocol&quot;&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;attribute&quot; style=&quot;color: red;&quot;&gt;SSLEnabled&lt;/span&gt;=&lt;span class=&quot;attribute-value&quot; style=&quot;color: blue;&quot;&gt;&quot;true&quot;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;background-color: #fafafa; border-left-color: rgb(209, 215, 220); border-left-style: solid; border-left-width: 1px; font-size: 1em; line-height: 18px; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;attribute&quot; style=&quot;color: red;&quot;&gt;maxThreads&lt;/span&gt;=&lt;span class=&quot;attribute-value&quot; style=&quot;color: blue;&quot;&gt;&quot;150&quot;&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;attribute&quot; style=&quot;color: red;&quot;&gt;scheme&lt;/span&gt;=&lt;span class=&quot;attribute-value&quot; style=&quot;color: blue;&quot;&gt;&quot;https&quot;&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;attribute&quot; style=&quot;color: red;&quot;&gt;secure&lt;/span&gt;=&lt;span class=&quot;attribute-value&quot; style=&quot;color: blue;&quot;&gt;&quot;true&quot;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;background-color: #fafafa; border-left-color: rgb(209, 215, 220); border-left-style: solid; border-left-width: 1px; font-size: 1em; line-height: 18px; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;attribute&quot; style=&quot;color: red;&quot;&gt;clientAuth&lt;/span&gt;=&lt;span class=&quot;attribute-value&quot; style=&quot;color: blue;&quot;&gt;&quot;false&quot;&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;attribute&quot; style=&quot;color: red;&quot;&gt;sslProtocol&lt;/span&gt;=&lt;span class=&quot;attribute-value&quot; style=&quot;color: blue;&quot;&gt;&quot;TLS&quot;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;background-color: #fafafa; border-left-color: rgb(209, 215, 220); border-left-style: solid; border-left-width: 1px; font-size: 1em; line-height: 18px; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;attribute&quot; style=&quot;color: red;&quot;&gt;keystorePass&lt;/span&gt;=&lt;span class=&quot;attribute-value&quot; style=&quot;color: blue;&quot;&gt;&quot;changeit&quot;&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;attribute&quot; style=&quot;color: red;&quot;&gt;keystoreFile&lt;/span&gt;=&lt;span class=&quot;attribute-value&quot; style=&quot;color: blue;&quot;&gt;&quot;xxx.keystore&quot;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;background-color: #fafafa; border-left-color: rgb(209, 215, 220); border-left-style: solid; border-left-width: 1px; font-size: 1em; line-height: 18px; margin: 0px 0px 0px 38px; padding: 0px 0px 0px 10px;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;tag&quot; style=&quot;color: #006699; font-weight: bold;&quot;&gt;/&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;重新執行步驟4，應該原本警示的訊息沒有了，隨便輸入用戶名及密碼一樣的如 用戶名 louisz密碼 louisz，正常的話應該會看到成功的訊息喔。&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://louiszspower.blogspot.com/feeds/311349873705344619/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://louiszspower.blogspot.com/2013/03/jasig-cas-sso.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/311349873705344619'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/311349873705344619'/><link rel='alternate' type='text/html' href='http://louiszspower.blogspot.com/2013/03/jasig-cas-sso.html' title='Jasig CAS SSO 安裝篇'/><author><name>Louisz</name><uri>http://www.blogger.com/profile/15227162328934605700</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuq5rOe6t7hT-kppa8Fu3eLB6RzgYqY8I7hZyMmMKyeAVUNbzRxsj7SQQA1EyynM-Ac6FjR6PmyXhcfn6PiIsBkByRyY8nSu3CWpAlXTcOcfGjpUDCpSBge2ou1j770EY/s220/IMG_20170629_210051.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553741655215810943.post-4339624058711079796</id><published>2013-01-22T00:55:00.002-08:00</published><updated>2013-06-22T02:02:51.341-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Pentaho"/><title type='text'>Pentaho kettle取指定目錄下的所有檔案</title><content type='html'>最近開始玩 BI的東西，而之前專案有使用到Pentaho Open Source這個好物....&lt;br /&gt;
&lt;br /&gt;
Pentaho裡面很多東西，跟 Jasperreport一樣東西很多，我最先接觸到的是kettle ETL的工具，玩了一陣子，開始有空就把它寫下來，以免忘記。&lt;br /&gt;
&lt;br /&gt;
Scan一個目錄下所有檔案，然後塞進去資料庫&lt;br /&gt;
&lt;br /&gt;
1.先拉兩個 Input，一個Get File Names，一個是CSV file input，再拉一個 output 中的 Table output，然後把他連起來。&lt;br /&gt;
&lt;br /&gt;
2.點開 Get File Names，File or directory設定你的指定目錄，Regular Expression則是輸入.*\.*$則是所有檔案，若是CSV則可.*\.torrent$這可以了，可以按一下 Preview rows看看是否正確。&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
3.在CSV file input則於The filename field....下拉選單選擇filename，並於下方文字檔案格式部分依序輸入該文字檔案格式。這部分就是讓前一個步驟讀取所有檔案後，將檔名自動送進來，依據固定的格式讀入。&lt;br /&gt;
&lt;br /&gt;
4.最後一個Table output就是塞到DB，把相關mapping設定一下就可以了。&lt;br /&gt;
&lt;br /&gt;
Pentaho實在很讚，往後陸續增加囉。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6S0M5lMvIW1BYCyM13ekB0dOL4IvAqdrojTjCrVzYHNM06HqzNeSCDs6U0MCBp7-T6YeQRPK4lf6j6Eb21YiwaFKdfD1FFbBLB-NjfXOx3YuVz3xtbh3muHr2eNJAlXq-nX_jR62-C7E/s1600/Snap10.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6S0M5lMvIW1BYCyM13ekB0dOL4IvAqdrojTjCrVzYHNM06HqzNeSCDs6U0MCBp7-T6YeQRPK4lf6j6Eb21YiwaFKdfD1FFbBLB-NjfXOx3YuVz3xtbh3muHr2eNJAlXq-nX_jR62-C7E/s1600/Snap10.png&quot; height=&quot;189&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjANtDtC0x8TxYX1EPnszZUJwSbFpLmJTmUW_TY4cvH9uHaV_tWYyR5T3ZL39nceV-F5dvs56YJe9J7I-fheMvGlchdbU4P-iinpoKQMUzBQgJ8WD18eGG58cPoGpmzlBbDVfpizxze0PA/s1600/Snap7.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjANtDtC0x8TxYX1EPnszZUJwSbFpLmJTmUW_TY4cvH9uHaV_tWYyR5T3ZL39nceV-F5dvs56YJe9J7I-fheMvGlchdbU4P-iinpoKQMUzBQgJ8WD18eGG58cPoGpmzlBbDVfpizxze0PA/s1600/Snap7.png&quot; height=&quot;133&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0sPNI6gJpOPQAcPKy7RaZe68ZIEs2m0gPt9R8-4YDUmG_ewoACFpU13snCy4EAnWXC7hLYgG1sicxJG1KhaV9m55EuohX5Uci3_k4unuOiATt32ZRwJGnLUxbNok3CbT9xZmm6wpZ14g/s1600/Snap9.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0sPNI6gJpOPQAcPKy7RaZe68ZIEs2m0gPt9R8-4YDUmG_ewoACFpU13snCy4EAnWXC7hLYgG1sicxJG1KhaV9m55EuohX5Uci3_k4unuOiATt32ZRwJGnLUxbNok3CbT9xZmm6wpZ14g/s1600/Snap9.png&quot; height=&quot;171&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://louiszspower.blogspot.com/feeds/4339624058711079796/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://louiszspower.blogspot.com/2013/01/pentaho-kettle.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/4339624058711079796'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/4339624058711079796'/><link rel='alternate' type='text/html' href='http://louiszspower.blogspot.com/2013/01/pentaho-kettle.html' title='Pentaho kettle取指定目錄下的所有檔案'/><author><name>Louisz</name><uri>http://www.blogger.com/profile/15227162328934605700</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuq5rOe6t7hT-kppa8Fu3eLB6RzgYqY8I7hZyMmMKyeAVUNbzRxsj7SQQA1EyynM-Ac6FjR6PmyXhcfn6PiIsBkByRyY8nSu3CWpAlXTcOcfGjpUDCpSBge2ou1j770EY/s220/IMG_20170629_210051.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6S0M5lMvIW1BYCyM13ekB0dOL4IvAqdrojTjCrVzYHNM06HqzNeSCDs6U0MCBp7-T6YeQRPK4lf6j6Eb21YiwaFKdfD1FFbBLB-NjfXOx3YuVz3xtbh3muHr2eNJAlXq-nX_jR62-C7E/s72-c/Snap10.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553741655215810943.post-625269358090846231</id><published>2012-10-09T01:47:00.003-07:00</published><updated>2013-06-22T02:03:02.645-07:00</updated><title type='text'>Barcode Generator 條碼產生器 by ZXing</title><content type='html'>ZXing還滿方便的，產生各式條碼跟讀取，可以參考一下。&lt;br /&gt;
&lt;br /&gt;
這裡介紹QRCode的產生方式&lt;br /&gt;
&lt;br /&gt;
1.下載&amp;nbsp;&lt;a href=&quot;http://zxing.googlecode.com/files/ZXing-2.0.zip&quot;&gt;ZXing&lt;/a&gt;&lt;br /&gt;
2.解開會出現很多目錄，將core及javase裡面的core.jar及javase.jar檔案include進來&lt;br /&gt;
3.部分程式碼&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
import java.io.File;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.util.Hashtable;&lt;br /&gt;
&lt;br /&gt;
import com.google.zxing.BarcodeFormat;&lt;br /&gt;
import com.google.zxing.EncodeHintType;&lt;br /&gt;
import com.google.zxing.MultiFormatWriter;&lt;br /&gt;
import com.google.zxing.WriterException;&lt;br /&gt;
import com.google.zxing.client.j2se.MatrixToImageWriter;&lt;br /&gt;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;&lt;br /&gt;
....&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MultiFormatWriter writer = new MultiFormatWriter(); &amp;nbsp; &lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;Hashtable hints = new Hashtable();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;hints.put( EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.Q ); &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;try {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;MatrixToImageWriter.writeToFile( writer.encode( &quot;Hello World&quot;, BarcodeFormat.QR_CODE, 800, 800, hints ),&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;png&quot;, new File( &quot;qrcode.png&quot; ) );&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;} catch (IOException e) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;} catch (WriterException e) {&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
很簡單吧....BarcodeFormat有很多樣式的條碼，也有CODE_39等等可以玩玩看喔&lt;br /&gt;
&lt;br /&gt;
希望我能持之以恆的寫Blog下去....動力ㄚ....</content><link rel='replies' type='application/atom+xml' href='http://louiszspower.blogspot.com/feeds/625269358090846231/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://louiszspower.blogspot.com/2012/10/barcode-generator-by-zxing.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/625269358090846231'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/625269358090846231'/><link rel='alternate' type='text/html' href='http://louiszspower.blogspot.com/2012/10/barcode-generator-by-zxing.html' title='Barcode Generator 條碼產生器 by ZXing'/><author><name>Louisz</name><uri>http://www.blogger.com/profile/15227162328934605700</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuq5rOe6t7hT-kppa8Fu3eLB6RzgYqY8I7hZyMmMKyeAVUNbzRxsj7SQQA1EyynM-Ac6FjR6PmyXhcfn6PiIsBkByRyY8nSu3CWpAlXTcOcfGjpUDCpSBge2ou1j770EY/s220/IMG_20170629_210051.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553741655215810943.post-6137847372527318026</id><published>2012-04-09T02:41:00.003-07:00</published><updated>2013-06-22T02:03:16.109-07:00</updated><title type='text'>使用Apache Http Server進行Proxy和LoadBalance (補充)</title><content type='html'>1.補上直接使用source進行compile的流程&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;下載http-2.x.tar.gz檔案&lt;/li&gt;
&lt;li&gt;tar xvf http-2.x.tar.gz進入目錄&lt;/li&gt;
&lt;li&gt;./configure --prefix=安裝的目錄 --enable-mods-shard=most --enable-proxy --enable-proxy-ajp --enable-proxy-balancer --enable-proxy-connect --enable-proxy-ftp --enable-proxy-http --enable-rewrite&lt;/li&gt;
&lt;li&gt;./make&lt;/li&gt;
&lt;li&gt;./make install&lt;/li&gt;
&lt;/ol&gt;
後續就是設定httpd.conf檔案了.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;
2.設定balancer-manager,可以直接由Web監控load balance的情況,也可以控制&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Location /balancer-manager &amp;gt;&lt;br /&gt;
&lt;location balancer-manager=&quot;&quot;&gt;&lt;/location&gt;&lt;br /&gt;
SetHandler balancer-manager&lt;br /&gt;
Order Deny,Allow&lt;br /&gt;
Deny from all&lt;br /&gt;
Allow from xxx ----&amp;gt;開放可以accesss的domain或是host&lt;br /&gt;
&amp;lt;/Location &amp;gt;&lt;br /&gt;
&lt;br /&gt;
連結到 http://http-server/&lt;span style=&quot;color: red;&quot;&gt;balancer-manager&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://louiszspower.blogspot.com/feeds/6137847372527318026/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://louiszspower.blogspot.com/2012/04/apache-http-serverproxyloadbalance.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/6137847372527318026'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/6137847372527318026'/><link rel='alternate' type='text/html' href='http://louiszspower.blogspot.com/2012/04/apache-http-serverproxyloadbalance.html' title='使用Apache Http Server進行Proxy和LoadBalance (補充)'/><author><name>Louisz</name><uri>http://www.blogger.com/profile/15227162328934605700</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuq5rOe6t7hT-kppa8Fu3eLB6RzgYqY8I7hZyMmMKyeAVUNbzRxsj7SQQA1EyynM-Ac6FjR6PmyXhcfn6PiIsBkByRyY8nSu3CWpAlXTcOcfGjpUDCpSBge2ou1j770EY/s220/IMG_20170629_210051.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553741655215810943.post-2754308704942756285</id><published>2012-01-30T01:33:00.000-08:00</published><updated>2013-06-22T02:03:32.665-07:00</updated><title type='text'>使用Apache Http Server進行Proxy和LoadB alance</title><content type='html'>&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;環境概述&lt;br /&gt;OS：Linux&lt;br /&gt;Apache Http Server：2.2.21&lt;br /&gt;安裝可以使用rpm或是抓source下來compile，建議前者&lt;br /&gt;rpm –ivh apache-http-xxx.rpm&lt;br /&gt;這裡請注意一下安裝的版本&lt;/li&gt;
&lt;li&gt;http.conf 參數設定&lt;br /&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Proxy&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;virtualhost&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span style=&quot;font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;VirtualHost *:80&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;ProxyPass targetPath fromPath | fromUrl &lt;br /&gt;&lt;span style=&quot;font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;VirtualHost/&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/virtualhost&gt;範例如下&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span style=&quot;font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;VirtualHost *:80&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;ProxyPass /app http://DomainName或IP:8888/app&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;ProxyPassReverse /app http://DomainName或IP:8888/app&lt;br /&gt;&lt;span style=&quot;font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;VirtualHost/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;上述的參數設定為，將某主機的http通訊協定下的Web application(app)，對應到本台Web Server的app下。這樣的Proxy架構的設定對企業內的Web應用程式相當有用處，若是遇到Web Application Server掛點只需要修改Proxy對應，不需要動到dns等等，是個滿便宜的Proxy架構設定喔。﹝不過要注意Web Application要注意redirectc和forward等的撰寫，盡量不要有絕對IP的出現﹞&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
&lt;ol&gt;
&lt;/ol&gt;
&lt;ol&gt;&lt;span style=&quot;background-color: white; color: red; font-size: large;&quot;&gt;&lt;b&gt;Load Balance&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;不用花大錢就可以做到的做法，這方式我倒覺得適合目前的企業，像是IBM Websphere、Oracle Weblogic的Application Server也做得很好，可是反而太過了成為了bottom neck，另外就是License很可怕ㄚ，所以啦用這種方式反而不限定只有Java可以使用。&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;Header add Set-Cookie &quot;ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/&quot; env=BALANCER_ROUTE_CHANGED&lt;/span&gt;&lt;/ol&gt;
&lt;ol&gt;設定Session Sticky模式，不讓其Session循序變動&lt;br /&gt;&lt;proxy balancer:=&quot;&quot; cluster=&quot;&quot; failonstatus=&quot;404,301,500&quot; nofailover=&quot;Off&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;Proxy balancer://cluster failonstatus=404,301,500 nofailover=Off&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;BalancerMember http://DomainName1或IP1:8888/app route=1&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;BalancerMember http://DomainName2或IP2:9999/app route=2&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;ProxySet stickysession=ROUTEID&lt;/span&gt;&lt;/proxy&gt;&lt;virtualhost&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;Proxy/&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;VirtualHost *:80&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;ProxyPass /appbalancer://cluster&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;ProxyPassReverse /app balancer://cluster&lt;br /&gt;&lt;span style=&quot;font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;VirtualHost/&amp;gt; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&amp;nbsp;&lt;/virtualhost&gt;&lt;br /&gt;真的不用太複雜這樣就可以進行LoadBalance很好用ㄚ，不過請注意Web Application資料同步問題需要處理喔。&lt;/ol&gt;
&lt;ol&gt;&lt;br /&gt;&lt;/ol&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://louiszspower.blogspot.com/feeds/2754308704942756285/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://louiszspower.blogspot.com/2012/01/apache-http-serverproxyloadb-alance.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/2754308704942756285'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/2754308704942756285'/><link rel='alternate' type='text/html' href='http://louiszspower.blogspot.com/2012/01/apache-http-serverproxyloadb-alance.html' title='使用Apache Http Server進行Proxy和LoadB alance'/><author><name>Louisz</name><uri>http://www.blogger.com/profile/15227162328934605700</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuq5rOe6t7hT-kppa8Fu3eLB6RzgYqY8I7hZyMmMKyeAVUNbzRxsj7SQQA1EyynM-Ac6FjR6PmyXhcfn6PiIsBkByRyY8nSu3CWpAlXTcOcfGjpUDCpSBge2ou1j770EY/s220/IMG_20170629_210051.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553741655215810943.post-5686908056988983055</id><published>2009-07-27T08:03:00.000-07:00</published><updated>2009-07-27T08:32:54.637-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="MQ"/><title type='text'>MQ PCF API簡介</title><content type='html'>可以透過該API管理QMGR&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;MQAgent.java---&lt;/div&gt;&lt;div&gt;&lt;div&gt;package cgw.mq.admin;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;import cgw.mq.bean.MQManageBean;&lt;/div&gt;&lt;div&gt;import com.ibm.mq.MQEnvironment;&lt;/div&gt;&lt;div&gt;import com.ibm.mq.MQException;&lt;/div&gt;&lt;div&gt;import com.ibm.mq.pcf.PCFMessageAgent;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;public class MQAgent {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt; &lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;private PCFMessageAgent agent;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public MQAgent(MQManageBean bean ,int ccsid){&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;//MQEnvironment.CCSID = ccsid;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;try {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;PCFMessageAgent agent = new PCFMessageAgent(bean.getMqm_ip(),bean.getMqm_port(),bean.getAdmin_channel());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (MQException e) {&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;agent.setCharacterSet(ccsid);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public PCFMessageAgent getAgent() {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;return agent;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public void close() throws MQException{&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;agent.disconnect();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;MQManageBean.java---&lt;/div&gt;&lt;div&gt;&lt;div&gt;package cgw.mq.bean;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;public class MQManageBean {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;private String mqm_ip;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;private int mqm_port;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;private String admin_channel;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public String getAdmin_channel() {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;return admin_channel;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public void setAdmin_channel(String admin_channel) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;this.admin_channel = admin_channel;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public String getMqm_ip() {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;return mqm_ip;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public void setMqm_ip(String mqm_ip) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;this.mqm_ip = mqm_ip;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public int getMqm_port() {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;return mqm_port;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public void setMqm_port(int mqm_port) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;this.mqm_port = mqm_port;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;MQChannel.java---&lt;/div&gt;&lt;div&gt;&lt;div&gt;package cgw.mq.admin;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;import java.io.IOException;&lt;/div&gt;&lt;div&gt;import java.util.ArrayList;&lt;/div&gt;&lt;div&gt;import java.util.List;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;import cgw.mq.bean.MQChannelBean;&lt;/div&gt;&lt;div&gt;import cgw.mq.bean.MQManageBean;&lt;/div&gt;&lt;div&gt;import com.ibm.mq.MQException;&lt;/div&gt;&lt;div&gt;import com.ibm.mq.pcf.CMQC;&lt;/div&gt;&lt;div&gt;import com.ibm.mq.pcf.CMQCFC;&lt;/div&gt;&lt;div&gt;import com.ibm.mq.pcf.CMQXC;&lt;/div&gt;&lt;div&gt;import com.ibm.mq.pcf.PCFException;&lt;/div&gt;&lt;div&gt;import com.ibm.mq.pcf.PCFMessage;&lt;/div&gt;&lt;div&gt;import com.ibm.mq.pcf.PCFMessageAgent;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;public class MQChannel {&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;private PCFMessageAgent agent;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;private int[] attrs = { CMQCFC.MQCACH_CHANNEL_NAME,&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;CMQCFC.MQCACH_CONNECTION_NAME, CMQCFC.MQIACH_MSGS,&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;CMQCFC.MQCACH_LAST_MSG_DATE, CMQCFC.MQCACH_LAST_MSG_TIME,&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;CMQCFC.MQIACH_CHANNEL_STATUS, CMQCFC.MQIACH_CHANNEL_TYPE };&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public static void main(String args[]) throws MQException {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;MQManageBean bean = new MQManageBean();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;bean.setMqm_ip(&quot;192.168.1.2&quot;);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;bean.setMqm_port(1416);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;bean.setAdmin_channel(&quot;SYSTEM.DEF.SVRCONN&quot;);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;MQAgent agent = new MQAgent(bean, 950);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;MQChannel mqc = new MQChannel();&lt;/div&gt;&lt;div&gt;//&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;PCFMessageAgent agent = new PCFMessageAgent(&quot;testPcf&quot;);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;mqc.setAgent(agent.getAgent());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;try {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;//mqc.startChannelListener();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;MQChannelBean channelBean = new MQChannelBean();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;channelBean.setChannelName(&quot;go&quot;);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;channelBean.setChannelType(CMQXC.MQCHT_SVRCONN);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;mqc.createChannel(channelBean);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (PCFException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (MQException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (IOException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public List chkChannel(String targetChannel) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;ArrayList beanList = new ArrayList();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;try {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;PCFMessage request = new PCFMessage(&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;     &lt;/span&gt;CMQCFC.MQCMD_INQUIRE_CHANNEL_STATUS);&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;request.addParameter(CMQCFC.MQCACH_CHANNEL_NAME, targetChannel);&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;request.addParameter(CMQCFC.MQIACH_CHANNEL_INSTANCE_TYPE,&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;     &lt;/span&gt;CMQC.MQOT_CURRENT_CHANNEL);&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;      &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;request.addParameter(CMQCFC.MQIACH_CHANNEL_INSTANCE_ATTRS, attrs);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;PCFMessage[] pcf_resp = getAgent().send(request);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;for (int i = 0; i &lt;span class=&quot;Apple-style-span&quot;   style=&quot; color: rgb(106, 96, 79);  font-family:Helvetica;font-size:12px;&quot;&gt;&amp;lt; pcf_resp.length; i++){&lt;/span&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;MQChannelBean bean = new MQChannelBean();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;bean.setChannelName(pcf_resp[i]&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;      &lt;/span&gt;.getStringParameterValue(CMQCFC.MQCACH_CHANNEL_NAME));&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;bean.setChannelType(pcf_resp[i]&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;      &lt;/span&gt;.getIntParameterValue(CMQCFC.MQIACH_CHANNEL_TYPE));&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;bean&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;      &lt;/span&gt;.setConnectionName(pcf_resp[i]&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;        &lt;/span&gt;.getStringParameterValue(CMQCFC.MQCACH_CONNECTION_NAME));&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;bean.setMsgCount(pcf_resp[i]&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;      &lt;/span&gt;.getIntParameterValue(CMQCFC.MQIACH_MSGS));&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;bean.setLastMsgDate(pcf_resp[i]&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;      &lt;/span&gt;.getStringParameterValue(CMQCFC.MQCACH_LAST_MSG_DATE));&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;bean.setLastMsgTime(pcf_resp[i]&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;      &lt;/span&gt;.getStringParameterValue(CMQCFC.MQCACH_LAST_MSG_TIME));&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;bean.setStatus(pcf_resp[i]&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;      &lt;/span&gt;.getIntParameterValue(CMQCFC.MQIACH_CHANNEL_STATUS));&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;beanList.add(bean);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (PCFException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (MQException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (IOException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;return beanList;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public void startChannelListener() throws PCFException, MQException, IOException{&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;PCFMessage channel_msg = new PCFMessage(CMQCFC.MQCMD_START_CHANNEL_LISTENER);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;getAgent().send(channel_msg);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public void stopChannel(MQChannelBean bean) throws PCFException,&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;MQException, IOException {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;PCFMessage channel_msg = new PCFMessage(CMQCFC.MQCMD_STOP_CHANNEL);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;channel_msg.addParameter(CMQCFC.MQCACH_CHANNEL_NAME, bean&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;.getChannelName());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;channel_msg.addParameter(CMQCFC.MQCACH_CONNECTION_NAME, bean&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;.getConnectionName());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;getAgent().send(channel_msg);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public void startChannel(MQChannelBean bean) throws PCFException,&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;MQException, IOException {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;PCFMessage channel_msg = new PCFMessage(CMQCFC.MQCMD_START_CHANNEL);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;channel_msg.addParameter(CMQCFC.MQCACH_CHANNEL_NAME, bean&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;.getChannelName());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;channel_msg.addParameter(CMQCFC.MQCACH_CONNECTION_NAME, bean&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;.getConnectionName());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;getAgent().send(channel_msg);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public void createChannel(MQChannelBean bean) throws PCFException,&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;MQException, IOException {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;PCFMessage channel_msg = new PCFMessage(CMQCFC.MQCMD_CREATE_CHANNEL);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;channel_msg.addParameter(CMQCFC.MQCACH_CHANNEL_NAME, bean&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;.getChannelName());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;channel_msg.addParameter(CMQCFC.MQIACH_CHANNEL_TYPE, bean&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;.getChannelType());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;getAgent().send(channel_msg);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public PCFMessageAgent getAgent() {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;return agent;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public void setAgent(PCFMessageAgent agent) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;this.agent = agent;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;MQQueue.java---&lt;/div&gt;&lt;div&gt;&lt;div&gt;package cgw.mq.admin;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;import java.io.IOException;&lt;/div&gt;&lt;div&gt;import cgw.mq.bean.MQManageBean;&lt;/div&gt;&lt;div&gt;import com.ibm.mq.MQException;&lt;/div&gt;&lt;div&gt;import com.ibm.mq.pcf.CMQC;&lt;/div&gt;&lt;div&gt;import com.ibm.mq.pcf.CMQCFC;&lt;/div&gt;&lt;div&gt;import com.ibm.mq.pcf.PCFException;&lt;/div&gt;&lt;div&gt;import com.ibm.mq.pcf.PCFMessage;&lt;/div&gt;&lt;div&gt;import com.ibm.mq.pcf.PCFMessageAgent;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;public class MQQueue {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;private String targetQueue;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;private int depth;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;private PCFMessage pcf_req;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;private PCFMessageAgent agent;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;private int[] attrs = { CMQC.MQCA_Q_NAME, CMQC.MQIA_CURRENT_Q_DEPTH };&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public static void main(String[] arg){&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;MQManageBean bean = new MQManageBean();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;bean.setMqm_ip(&quot;192.168.1.1&quot;);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;bean.setMqm_port(1414);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;bean.setAdmin_channel(&quot;SYSTEM.DEF.SVRCONN&quot;);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;MQAgent agent = new MQAgent(bean,950);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;MQQueue mqq = new MQQueue();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;mqq.setTargetQueue(&quot;TEST&quot;);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;mqq.setAgent(agent.getAgent());&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;mqq.init();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;/*&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;try {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;//mqq.createQueue();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;//mqq.removeQueue();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;//mqq.clearQueue();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (PCFException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (MQException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (IOException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;*/&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;mqq.chkQueueDepth();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;System.out.println(mqq.getDepth());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public void init(){&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;pcf_req = new PCFMessage(CMQCFC.MQCMD_INQUIRE_Q);&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;pcf_req.addParameter(CMQC.MQCA_Q_NAME, getTargetQueue());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;pcf_req.addParameter(CMQC.MQIA_Q_TYPE, CMQC.MQQT_LOCAL);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;pcf_req.addParameter(CMQCFC.MQIACF_Q_ATTRS, attrs);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public void chkQueueDepth(){&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;try {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;PCFMessage[] pcf_resp = getAgent().send(getPcf_req());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;for(int i = 0;i&lt;pcf_resp.length;i++){&gt;&lt;/pcf_resp.length;i++){&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;String tmp = pcf_resp[i].getStringParameterValue(CMQC.MQCA_Q_NAME).trim();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;if(getTargetQueue().equals(tmp)){&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;     &lt;/span&gt;setDepth(pcf_resp[i].getIntParameterValue(CMQC.MQIA_CURRENT_Q_DEPTH));&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;}else{&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;     &lt;/span&gt;setDepth(-1);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;}&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (PCFException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (MQException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (IOException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public void createQueue() throws PCFException, MQException, IOException{&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;PCFMessage queue_msg = new PCFMessage(CMQCFC.MQCMD_CREATE_Q);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;queue_msg.addParameter(CMQC.MQCA_Q_NAME, getTargetQueue());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;queue_msg.addParameter(CMQC.MQIA_Q_TYPE, CMQC.MQQT_LOCAL);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;getAgent().send(queue_msg);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public void removeQueue() throws PCFException, MQException, IOException{&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;PCFMessage queue_msg = new PCFMessage(CMQCFC.MQCMD_DELETE_Q);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;queue_msg.addParameter(CMQC.MQCA_Q_NAME, getTargetQueue());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;queue_msg.addParameter(CMQC.MQIA_Q_TYPE, CMQC.MQQT_LOCAL);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;getAgent().send(queue_msg);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public void clearQueue() throws PCFException, MQException, IOException{&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;PCFMessage queue_msg = new PCFMessage(CMQCFC.MQCMD_CLEAR_Q);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;queue_msg.addParameter(CMQC.MQCA_Q_NAME, getTargetQueue());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;//queue_msg.addParameter(CMQC.MQIA_Q_TYPE, CMQC.MQQT_LOCAL);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;getAgent().send(queue_msg);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public String getTargetQueue() {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;return targetQueue;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public void setTargetQueue(String targetQueue) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;this.targetQueue = targetQueue;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public int getDepth() {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;return depth;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public void setDepth(int depth) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;this.depth = depth;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public PCFMessage getPcf_req() {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;return pcf_req;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public void setPcf_req(PCFMessage pcf_req) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;this.pcf_req = pcf_req;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public PCFMessageAgent getAgent() {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;return agent;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public void setAgent(PCFMessageAgent agent) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;this.agent = agent;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;package cgw.mq.admin;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;import java.io.IOException;&lt;/div&gt;&lt;div&gt;import java.util.ArrayList;&lt;/div&gt;&lt;div&gt;import java.util.List;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;import cgw.mq.bean.MQChannelBean;&lt;/div&gt;&lt;div&gt;import cgw.mq.bean.MQManageBean;&lt;/div&gt;&lt;div&gt;import com.ibm.mq.MQException;&lt;/div&gt;&lt;div&gt;import com.ibm.mq.pcf.CMQC;&lt;/div&gt;&lt;div&gt;import com.ibm.mq.pcf.CMQCFC;&lt;/div&gt;&lt;div&gt;import com.ibm.mq.pcf.CMQXC;&lt;/div&gt;&lt;div&gt;import com.ibm.mq.pcf.PCFException;&lt;/div&gt;&lt;div&gt;import com.ibm.mq.pcf.PCFMessage;&lt;/div&gt;&lt;div&gt;import com.ibm.mq.pcf.PCFMessageAgent;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;public class MQChannel {&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;private PCFMessageAgent agent;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;private int[] attrs = { CMQCFC.MQCACH_CHANNEL_NAME,&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;CMQCFC.MQCACH_CONNECTION_NAME, CMQCFC.MQIACH_MSGS,&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;CMQCFC.MQCACH_LAST_MSG_DATE, CMQCFC.MQCACH_LAST_MSG_TIME,&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;CMQCFC.MQIACH_CHANNEL_STATUS, CMQCFC.MQIACH_CHANNEL_TYPE };&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public static void main(String args[]) throws MQException {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;MQManageBean bean = new MQManageBean();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;bean.setMqm_ip(&quot;192.168.1.2&quot;);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;bean.setMqm_port(1416);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;bean.setAdmin_channel(&quot;SYSTEM.DEF.SVRCONN&quot;);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;MQAgent agent = new MQAgent(bean, 950);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;MQChannel mqc = new MQChannel();&lt;/div&gt;&lt;div&gt;//&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;PCFMessageAgent agent = new PCFMessageAgent(&quot;testPcf&quot;);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;mqc.setAgent(agent.getAgent());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;try {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;//mqc.startChannelListener();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;MQChannelBean channelBean = new MQChannelBean();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;channelBean.setChannelName(&quot;go&quot;);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;channelBean.setChannelType(CMQXC.MQCHT_SVRCONN);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;mqc.createChannel(channelBean);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (PCFException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (MQException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (IOException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public List chkChannel(String targetChannel) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;ArrayList beanList = new ArrayList();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;try {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;PCFMessage request = new PCFMessage(&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;     &lt;/span&gt;CMQCFC.MQCMD_INQUIRE_CHANNEL_STATUS);&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;request.addParameter(CMQCFC.MQCACH_CHANNEL_NAME, targetChannel);&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;request.addParameter(CMQCFC.MQIACH_CHANNEL_INSTANCE_TYPE,&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;     &lt;/span&gt;CMQC.MQOT_CURRENT_CHANNEL);&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;      &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;request.addParameter(CMQCFC.MQIACH_CHANNEL_INSTANCE_ATTRS, attrs);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;PCFMessage[] pcf_resp = getAgent().send(request);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;for (int i = 0; i &lt;&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;MQChannelBean bean = new MQChannelBean();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;bean.setChannelName(pcf_resp[i]&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;      &lt;/span&gt;.getStringParameterValue(CMQCFC.MQCACH_CHANNEL_NAME));&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;bean.setChannelType(pcf_resp[i]&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;      &lt;/span&gt;.getIntParameterValue(CMQCFC.MQIACH_CHANNEL_TYPE));&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;bean&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;      &lt;/span&gt;.setConnectionName(pcf_resp[i]&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;        &lt;/span&gt;.getStringParameterValue(CMQCFC.MQCACH_CONNECTION_NAME));&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;bean.setMsgCount(pcf_resp[i]&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;      &lt;/span&gt;.getIntParameterValue(CMQCFC.MQIACH_MSGS));&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;bean.setLastMsgDate(pcf_resp[i]&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;      &lt;/span&gt;.getStringParameterValue(CMQCFC.MQCACH_LAST_MSG_DATE));&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;bean.setLastMsgTime(pcf_resp[i]&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;      &lt;/span&gt;.getStringParameterValue(CMQCFC.MQCACH_LAST_MSG_TIME));&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;bean.setStatus(pcf_resp[i]&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;      &lt;/span&gt;.getIntParameterValue(CMQCFC.MQIACH_CHANNEL_STATUS));&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;beanList.add(bean);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (PCFException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (MQException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (IOException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;return beanList;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public void startChannelListener() throws PCFException, MQException, IOException{&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;PCFMessage channel_msg = new PCFMessage(CMQCFC.MQCMD_START_CHANNEL_LISTENER);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;getAgent().send(channel_msg);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public void stopChannel(MQChannelBean bean) throws PCFException,&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;MQException, IOException {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;PCFMessage channel_msg = new PCFMessage(CMQCFC.MQCMD_STOP_CHANNEL);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;channel_msg.addParameter(CMQCFC.MQCACH_CHANNEL_NAME, bean&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;.getChannelName());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;channel_msg.addParameter(CMQCFC.MQCACH_CONNECTION_NAME, bean&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;.getConnectionName());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;getAgent().send(channel_msg);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public void startChannel(MQChannelBean bean) throws PCFException,&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;MQException, IOException {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;PCFMessage channel_msg = new PCFMessage(CMQCFC.MQCMD_START_CHANNEL);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;channel_msg.addParameter(CMQCFC.MQCACH_CHANNEL_NAME, bean&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;.getChannelName());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;channel_msg.addParameter(CMQCFC.MQCACH_CONNECTION_NAME, bean&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;.getConnectionName());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;getAgent().send(channel_msg);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public void createChannel(MQChannelBean bean) throws PCFException,&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;MQException, IOException {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;PCFMessage channel_msg = new PCFMessage(CMQCFC.MQCMD_CREATE_CHANNEL);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;channel_msg.addParameter(CMQCFC.MQCACH_CHANNEL_NAME, bean&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;.getChannelName());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;channel_msg.addParameter(CMQCFC.MQIACH_CHANNEL_TYPE, bean&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;    &lt;/span&gt;.getChannelType());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;getAgent().send(channel_msg);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public PCFMessageAgent getAgent() {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;return agent;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public void setAgent(PCFMessageAgent agent) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;this.agent = agent;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://louiszspower.blogspot.com/feeds/5686908056988983055/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://louiszspower.blogspot.com/2009/07/mq-pcf-api.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/5686908056988983055'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/5686908056988983055'/><link rel='alternate' type='text/html' href='http://louiszspower.blogspot.com/2009/07/mq-pcf-api.html' title='MQ PCF API簡介'/><author><name>Louisz</name><uri>http://www.blogger.com/profile/15227162328934605700</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuq5rOe6t7hT-kppa8Fu3eLB6RzgYqY8I7hZyMmMKyeAVUNbzRxsj7SQQA1EyynM-Ac6FjR6PmyXhcfn6PiIsBkByRyY8nSu3CWpAlXTcOcfGjpUDCpSBge2ou1j770EY/s220/IMG_20170629_210051.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553741655215810943.post-807263291579883371</id><published>2009-03-09T01:15:00.000-07:00</published><updated>2009-03-09T01:37:33.906-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="工作"/><title type='text'>利用Asprise OCR辨識PDF中的條碼</title><content type='html'>http://asprise.com/product/ocr/index.php?lang=java&lt;br /&gt;這個API還滿不錯用的，它可以直接辨識PDF中的條碼，不過Free的版本跟文件似乎有些不一樣，底下是辨識PDF文件的條碼步驟：&lt;br /&gt;1.下載Asprise OCR v4.0 for Java，http://asprise.com/product/ocr/download.php?lang=java，以及AspriseJavaPDF-free.jar，http://asprise.com/product/javapdf/util.php&lt;br /&gt;2.有Developer Guide手冊可以參考一下，把AspriseOCR.dll、DevIL.dll及ILU.dll放在LIBRARY(如Window/system32或是project的lib)&lt;br /&gt;3.程式碼如下&lt;br /&gt;OCR ocr = new OCR();&lt;br /&gt;        PDFReader pdfreader = new PDFReader(new File(&quot;d:\\lunch.pdf&quot;));&lt;br /&gt;        pdfreader.open();&lt;br /&gt;        int pageCount = pdfreader.getNumberOfPages();&lt;br /&gt;       // PDFToImage pdfToImage = new PDFToImage(&quot;D:\\lunch.pdf&quot;);&lt;br /&gt;        pdfreader.close();&lt;br /&gt;        PDFToImage pdfToImage = new PDFToImage(&quot;D:\\lunch.pdf&quot;);&lt;br /&gt;       for(int j=1;j&lt;pagecount;j++){&gt;&lt;br /&gt;           BufferedImage img = pdfToImage.getImage(j);              &lt;br /&gt;           String text=ocr.recognizeBarcode(img);&lt;br /&gt;//Vector v = ocr.recognizeBarcodes(img);&lt;br /&gt;           System.out.println(text);&lt;br /&gt;       }&lt;br /&gt;一頁是多個條碼時，可以用Vector就可以了，滿方便的不過不用錢的每辨識一頁就會跳出一個版權視窗按下否或是，才會往下辨識，比較麻煩一點&lt;br /&gt;&lt;/pagecount;j++){&gt;</content><link rel='replies' type='application/atom+xml' href='http://louiszspower.blogspot.com/feeds/807263291579883371/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://louiszspower.blogspot.com/2009/03/asprise-ocrpdf.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/807263291579883371'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/807263291579883371'/><link rel='alternate' type='text/html' href='http://louiszspower.blogspot.com/2009/03/asprise-ocrpdf.html' title='利用Asprise OCR辨識PDF中的條碼'/><author><name>Louisz</name><uri>http://www.blogger.com/profile/15227162328934605700</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuq5rOe6t7hT-kppa8Fu3eLB6RzgYqY8I7hZyMmMKyeAVUNbzRxsj7SQQA1EyynM-Ac6FjR6PmyXhcfn6PiIsBkByRyY8nSu3CWpAlXTcOcfGjpUDCpSBge2ou1j770EY/s220/IMG_20170629_210051.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553741655215810943.post-7325726764417125112</id><published>2009-02-19T22:20:00.000-08:00</published><updated>2009-02-19T23:11:58.816-08:00</updated><title type='text'>XEN on CentOS</title><content type='html'>最近因為我申請的開發機器下來了，就玩玩之前沒測完的XEN，先說一下我機器的配備應該算是很高檔.&lt;br /&gt;&lt;br /&gt;CPU---QC * 2 ---共8核&lt;br /&gt;RAM---12GB&lt;br /&gt;硬碟----3顆1T&lt;br /&gt;&lt;br /&gt;有三台(呵呵很酷喔而且還只拿來開發)&lt;br /&gt;&lt;br /&gt;回到正題，上次XEN少了Window，這次給他補足了順便紀錄一下遇到的一些問題&lt;br /&gt;1.要在XEN安裝Window系列，Intel CPU要具備VT，AMD要具備AMD-V如何確認呢&lt;br /&gt;cat /proc/cpuinfo | grep flags&lt;br /&gt;看看有沒有VMX的項目，有就可以安裝.&lt;br /&gt;p.s這裡還要注意一點若是CPU有註明有VT或是AMD-V可是下該指令沒有的話就請確認核心有沒有開啟(SuSe 11.1就沒有)&lt;br /&gt;&lt;br /&gt;2.強烈建議使用CentOS5.2進行，OpenSuSe我分別裝了10.1 - 10.3及11統統不行在XEN裡裝Window，CentOS5.2很順。&lt;br /&gt;&lt;br /&gt;3.網路設定問題&lt;br /&gt;  a.希望外部可以直接連到虛擬機器(domainU)，安裝CentOS時先不要在實體網路卡上設定任何IP，但實體線路可以插上去，然後再安裝CentOS，起動虛擬機器管理員(是圖形介面)，連接並建立一新的DomainU，依據所需進行設定，到了Host network設定時請選擇第二項shard physical network，就一路安裝下去囉..安裝好DomainU的作業環境，然後再設定網路卡的IP(DomainU的)應該就可以囉.&lt;br /&gt;※這裡可以把DomainO(CentOS)的網路卡當做一個HUB來看就不難理解他不用設IP了，可是不要問我原因我也不知道&lt;br /&gt;&lt;br /&gt;b.希望走DHCP方式同a步驟，到Host network請選擇第一項virtual network後面步驟就一樣了，可是要外部連到這台機器時，則要在DominO(CentOS)上利用iptables進行囉&lt;br /&gt;&lt;br /&gt;4.可以使用virt-clone進行複製好用喔</content><link rel='replies' type='application/atom+xml' href='http://louiszspower.blogspot.com/feeds/7325726764417125112/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://louiszspower.blogspot.com/2009/02/xen-on-centos.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/7325726764417125112'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/7325726764417125112'/><link rel='alternate' type='text/html' href='http://louiszspower.blogspot.com/2009/02/xen-on-centos.html' title='XEN on CentOS'/><author><name>Louisz</name><uri>http://www.blogger.com/profile/15227162328934605700</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuq5rOe6t7hT-kppa8Fu3eLB6RzgYqY8I7hZyMmMKyeAVUNbzRxsj7SQQA1EyynM-Ac6FjR6PmyXhcfn6PiIsBkByRyY8nSu3CWpAlXTcOcfGjpUDCpSBge2ou1j770EY/s220/IMG_20170629_210051.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553741655215810943.post-5581099723806309911</id><published>2009-01-13T23:04:00.000-08:00</published><updated>2009-01-13T23:18:48.239-08:00</updated><title type='text'>IReport中的條碼類別BcImage</title><content type='html'>最近有一個繳費單的專案，需要列印條碼，因為IReport本身就有提供列印條碼的功能，所以就用IReport設計繳費單然後再用Jasperreport API寫批次程式去產生PDF，資料量大概3000多筆(頁)拆成幾個檔案，可是就發生了一個問題居然發生部分繳費單的條碼有問題，看了一下程式研判是Race Condition因為程式採用的是多執行緒，若是依序個別產生是不會有問題，但是同時執行的時候就會亂掉，而且都錯在條碼，令我覺得很奇怪，後來我查了一下發現it.businesslogic.ireport.barcode.BcImage 類別我猜是這裡的問題，就先加上synchronized重新編譯在去執行，嘿嘿條碼就對了，做了一下壓測也正常，程式碼如下，不過這樣事不是對了可能還要仔細查查看。&lt;br /&gt;&lt;br /&gt;public class BcImage {&lt;br /&gt;    private static net.sourceforge.barbecue.Barcode bc = null;&lt;br /&gt;   &lt;br /&gt;    public synchronized static net.sourceforge.barbecue.Barcode getBarcode() {&lt;br /&gt;        return bc;&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;        public synchronized static BufferedImage getBarcodeImage(int type, Object aText, boolean showText, boolean checkSum) {&lt;br /&gt;            return getBarcodeImage(type, aText, showText, checkSum,&quot;&quot;,0,0);&lt;br /&gt;        }&lt;br /&gt;       &lt;br /&gt;    public synchronized static BufferedImage getBarcodeImage(int type, Object aText, boolean showText, boolean checkSum, String applicationIdentifier, int width, int height) {&lt;br /&gt;        // 2of7, 3of9, Bookland, Codabar, Code128, Code128A, Code128B, Code128C, Code39, EAN128, EAN13, GlobalTradeItemNumber, Int2of5, Int2of5, Monarch, NW7, PDF417, SCC14ShippingCode, ShipmentIdentificationNumber, SSCC18, Std2of5, Std2of5, UCC128, UPCA, USD3, USD4, USPS&lt;br /&gt;       &lt;br /&gt;        String text = new StringBuffer().append(aText).toString();&lt;br /&gt;&lt;br /&gt;        try {&lt;br /&gt;            switch (type) {&lt;br /&gt;                                case 0: return null;&lt;br /&gt;                                case 1: bc = BarcodeFactory.create2of7(text); break;&lt;br /&gt;                case 2: bc = BarcodeFactory.create3of9(text, checkSum);    break;&lt;br /&gt;                case 3: bc = BarcodeFactory.createBookland(text); break;&lt;br /&gt;                case 4: bc = BarcodeFactory.createCodabar(text); break;&lt;br /&gt;                case 5: bc = BarcodeFactory.createCode128(text); break;&lt;br /&gt;                case 6: bc = BarcodeFactory.createCode128A(text); break;&lt;br /&gt;                case 7: bc = BarcodeFactory.createCode128B(text); break;&lt;br /&gt;                case 8: bc = BarcodeFactory.createCode128C(text); break;&lt;br /&gt;                case 9: bc = BarcodeFactory.createCode39(text, checkSum ); break;&lt;br /&gt;                case 10: bc = BarcodeFactory.createEAN128(text); break;&lt;br /&gt;                case 11: bc = BarcodeFactory.createEAN13(text);    break;&lt;br /&gt;                case 12: bc = BarcodeFactory.createGlobalTradeItemNumber(text);    break;&lt;br /&gt;                case 13: bc = BarcodeFactory.createInt2of5(text, checkSum); break;&lt;br /&gt;                case 14: bc = BarcodeFactory.createMonarch(text); break;&lt;br /&gt;                case 15: bc = BarcodeFactory.createNW7(text); break;&lt;br /&gt;                case 16: bc = BarcodeFactory.createPDF417(text); break;&lt;br /&gt;                case 17: bc = BarcodeFactory.createSCC14ShippingCode(text); break;&lt;br /&gt;                case 18: bc = BarcodeFactory.createShipmentIdentificationNumber(text); break;&lt;br /&gt;                case 19: bc = new UCCEAN128Barcode(UCCEAN128Barcode.SSCC_18_AI, text, checkSum); break; //BarcodeFactory.createSSCC18(text); break;&lt;br /&gt;                case 20: bc = BarcodeFactory.createStd2of5(text, checkSum); break;&lt;br /&gt;                case 21: bc = new UCCEAN128Barcode(applicationIdentifier, text, checkSum); break; //BarcodeFactory.createUCC128(applicationIdentifier, text); break;&lt;br /&gt;                case 22: bc = BarcodeFactory.createUPCA(text); break;&lt;br /&gt;                case 23: bc = BarcodeFactory.createUSD3(text, checkSum); break;&lt;br /&gt;                case 24: bc = BarcodeFactory.createUSD4(text); break;&lt;br /&gt;                case 25: bc = BarcodeFactory.createUSPS(text); break;&lt;br /&gt;                                case 26: bc = new net.sourceforge.barbecue.linear.code39.Code39Barcode(text, checkSum, true);  break;&lt;br /&gt;            }&lt;br /&gt;           &lt;br /&gt;                        if (width &gt; 0) bc.setBarWidth(width);&lt;br /&gt;                        if (height &gt; 0) bc.setBarHeight(height);&lt;br /&gt;            bc.setDrawingText(showText);&lt;br /&gt;                        return net.sourceforge.barbecue.BarcodeImageHandler.getImage(bc);&lt;br /&gt;        }&lt;br /&gt;        catch (Exception e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;            //generate a runtime exception, invalid value passed.&lt;br /&gt;            //the user must be notified if fail&lt;br /&gt;            throw new RuntimeException(e.getMessage());&lt;br /&gt;            //return null;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}</content><link rel='replies' type='application/atom+xml' href='http://louiszspower.blogspot.com/feeds/5581099723806309911/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://louiszspower.blogspot.com/2009/01/ireportbcimage.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/5581099723806309911'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/5581099723806309911'/><link rel='alternate' type='text/html' href='http://louiszspower.blogspot.com/2009/01/ireportbcimage.html' title='IReport中的條碼類別BcImage'/><author><name>Louisz</name><uri>http://www.blogger.com/profile/15227162328934605700</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuq5rOe6t7hT-kppa8Fu3eLB6RzgYqY8I7hZyMmMKyeAVUNbzRxsj7SQQA1EyynM-Ac6FjR6PmyXhcfn6PiIsBkByRyY8nSu3CWpAlXTcOcfGjpUDCpSBge2ou1j770EY/s220/IMG_20170629_210051.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553741655215810943.post-8548309096499357306</id><published>2008-12-02T20:45:00.000-08:00</published><updated>2008-12-02T21:48:51.687-08:00</updated><title type='text'>IReport透過寫程式自訂功能</title><content type='html'>IReport是透過SQL進行資料的取得，所以很多邏輯都需要靠SQL來進行，有時候只是要進行一個資料的對應大部分都是透過join table進行，或是需要另一資料來源時就需要特別客製化應用程式等等，假如IReport可以呼叫Java程式那就非常之完美了，舉個例子說&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;原本在IReport中的SQL為&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;select a.name,b.className,c.countryName,a.telephone from student a ,class b,country c where a.id = b.id and a.id=c.id&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;若是b 跟 c不再同一個資料來源怎麼辦?&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;步驟&lt;/div&gt;&lt;div&gt;1.寫一隻Java程式可以連到其他資料來源,並把它包成jar檔案&lt;/div&gt;&lt;div&gt;2.將該jar檔案放在IReport的lib下&lt;/div&gt;&lt;div&gt;3.透過SQL去呼叫如&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;select name,test.ClassUtils.getClassName(id),test.CountryUtils.getCountry(countryId),test.TranUtils.translate(telephone) from student&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;這樣就可以了若是在搭配scriptlet方式進行那就真的很Power.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;P.S 應用程式使用時也只要把jar放在classpath也可以喔~~&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://louiszspower.blogspot.com/feeds/8548309096499357306/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://louiszspower.blogspot.com/2008/12/ireport.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/8548309096499357306'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/8548309096499357306'/><link rel='alternate' type='text/html' href='http://louiszspower.blogspot.com/2008/12/ireport.html' title='IReport透過寫程式自訂功能'/><author><name>Louisz</name><uri>http://www.blogger.com/profile/15227162328934605700</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuq5rOe6t7hT-kppa8Fu3eLB6RzgYqY8I7hZyMmMKyeAVUNbzRxsj7SQQA1EyynM-Ac6FjR6PmyXhcfn6PiIsBkByRyY8nSu3CWpAlXTcOcfGjpUDCpSBge2ou1j770EY/s220/IMG_20170629_210051.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553741655215810943.post-8134594007369362576</id><published>2008-11-30T22:12:00.000-08:00</published><updated>2008-11-30T22:30:21.878-08:00</updated><title type='text'>玩玩DES及RSA</title><content type='html'>最近有個需求,就是希望能把儲存在文字檔中的密碼,增加一些安全機制,想說之前(參考JavaWorld@TW的一些資料)有玩過一下下DES及RSA說不定可以試試看，流程大概先產生一把KEY(DES)或是一對KEY(RSA),使用KEY針對資料進行加密,加過密的文字有可能會是非法字元,所以用BASE64進行encode或是decode,應用程式要使用加個密的資料,需要兩個要素第一個就是key,另外就是API,缺一不可(盡量防止Developer).&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;DES部分&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;DESGenerator&lt;/div&gt;&lt;div&gt;&lt;div&gt;import java.io.FileNotFoundException;&lt;/div&gt;&lt;div&gt;import java.io.FileOutputStream;&lt;/div&gt;&lt;div&gt;import java.io.IOException;&lt;/div&gt;&lt;div&gt;import java.io.ObjectOutputStream;&lt;/div&gt;&lt;div&gt;import java.security.NoSuchAlgorithmException;&lt;/div&gt;&lt;div&gt;import java.security.NoSuchProviderException;&lt;/div&gt;&lt;div&gt;import java.security.SecureRandom;&lt;/div&gt;&lt;div&gt;import java.security.spec.InvalidKeySpecException;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;import javax.crypto.KeyGenerator;&lt;/div&gt;&lt;div&gt;import javax.crypto.SecretKey;&lt;/div&gt;&lt;div&gt;import javax.crypto.SecretKeyFactory;&lt;/div&gt;&lt;div&gt;import javax.crypto.spec.DESKeySpec;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;import entiebank.utils.Utils;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;public class DESKeyGenerator {&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public static void genDESKey(String keyFileName,String alg){&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;try {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;KeyGenerator kpg = KeyGenerator.getInstance(alg);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;//TODO Default alg maybe can change&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;//SecureRandom random = SecureRandom.getInstance(&quot;SHA1PRNG&quot;,&quot;SUN&quot;);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;//常用的&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;//&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;random.setSeed(101L);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;//&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;kpg.init(56,random);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;SecretKey sKey = kpg.generateKey();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;System.out.println(sKey.hashCode());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;//&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;SecretKeyFactory kfactory = SecretKeyFactory.getInstance(alg);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;//DESKeySpec kspec = (DESKeySpec)kfactory.getKeySpec(sKey, DESKeySpec.class);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;Utils.writeKeyFile(keyFileName, sKey);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;//output File&lt;/div&gt;&lt;div&gt;//&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;FileOutputStream fos = new FileOutputStream(keyFileName);&lt;/div&gt;&lt;div&gt;//&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;ObjectOutputStream oos  = new ObjectOutputStream(fos);&lt;/div&gt;&lt;div&gt;//&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;oos.writeObject(sKey);&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;&lt;/div&gt;&lt;div&gt;//&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;oos.close();&lt;/div&gt;&lt;div&gt;////&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;fos.write(sKey.getEncoded());&lt;/div&gt;&lt;div&gt;//&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;fos.close();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (NoSuchAlgorithmException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} &lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public static void main(String[] arg){&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;DESKeyGenerator.genDESKey(&quot;louisz.des&quot;, &quot;DES&quot;);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;DESUtils&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;import java.io.FileInputStream;&lt;/div&gt;&lt;div&gt;import java.io.FileNotFoundException;&lt;/div&gt;&lt;div&gt;import java.io.IOException;&lt;/div&gt;&lt;div&gt;import java.io.ObjectInputStream;&lt;/div&gt;&lt;div&gt;import java.security.InvalidKeyException;&lt;/div&gt;&lt;div&gt;import java.security.NoSuchAlgorithmException;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;import javax.crypto.BadPaddingException;&lt;/div&gt;&lt;div&gt;import javax.crypto.Cipher;&lt;/div&gt;&lt;div&gt;import javax.crypto.IllegalBlockSizeException;&lt;/div&gt;&lt;div&gt;import javax.crypto.NoSuchPaddingException;&lt;/div&gt;&lt;div&gt;import javax.crypto.SecretKey;&lt;/div&gt;&lt;div&gt;import javax.crypto.spec.DESKeySpec;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;import entiebank.utils.Utils;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;import sun.misc.BASE64Decoder;&lt;/div&gt;&lt;div&gt;import sun.misc.BASE64Encoder;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;public class DESUtils {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;private static SecretKey sKey = null; &lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public static void loadDESKey(String keyFileName){&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;sKey = (SecretKey)Utils.readKeyFile(keyFileName);&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;private static void readKey(){&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;System.out.println(sKey.hashCode());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public static SecretKey getDESKey(){&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;return sKey;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public static String encrypt(String clearString){&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;try {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;Cipher desCipher = Cipher.getInstance(&quot;DES/ECB/PKCS5Padding&quot;);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;desCipher.init(Cipher.ENCRYPT_MODE,getDESKey());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;//System.out.println(&quot;clearStr=&quot;+encryptString);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;//System.out.println(&quot;encrypt==&quot;+new String(desCipher.doFinal(encryptString.getBytes())));&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;return bytesToBase64Str(desCipher.doFinal(clearString.getBytes()));&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (NoSuchAlgorithmException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (NoSuchPaddingException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (InvalidKeyException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (IllegalBlockSizeException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (BadPaddingException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;return null;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public static String decrypt(String encryptString){&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;try {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;Cipher desCipher = Cipher.getInstance(&quot;DES/ECB/PKCS5Padding&quot;);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;desCipher.init(Cipher.DECRYPT_MODE,getDESKey());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;return new String(desCipher.doFinal(base64StrToBytes(encryptString)));&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (NoSuchAlgorithmException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (NoSuchPaddingException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (IllegalBlockSizeException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (BadPaddingException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (InvalidKeyException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;return null;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;public static String decrypt(String keyFilename,String encryptString){&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;try {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;SecretKey desKey = (SecretKey)Utils.readKeyFile(keyFilename);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;Cipher desCipher = Cipher.getInstance(&quot;DES/ECB/PKCS5Padding&quot;);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;desCipher.init(Cipher.DECRYPT_MODE,desKey);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;return new String(desCipher.doFinal(base64StrToBytes(encryptString)));&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (NoSuchAlgorithmException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (NoSuchPaddingException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (IllegalBlockSizeException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (BadPaddingException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (InvalidKeyException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;return null;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public static String bytesToBase64Str(byte[] bytes){&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;return new BASE64Encoder().encode(bytes);&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public static byte[] base64StrToBytes(String base64Str){&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;try {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;return new BASE64Decoder().decodeBuffer(base64Str);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (IOException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;return null;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public static void main(String[] arg){&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;//&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;DESUtils des = new DESUtils();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;DESUtils.loadDESKey(&quot;Key&quot;);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;DESUtils.readKey();&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;//System.out.println(DESUtils.encrypt(&quot;hehe it&#39;s can works&quot;));&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;System.out.println(DESUtils.decrypt(&quot;l+M1yV2Mf4yaTlSxmPU3GA==&quot;));&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;RSA部分&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;RSAGenerator&lt;/div&gt;&lt;div&gt;&lt;div&gt;import java.security.KeyPair;&lt;/div&gt;&lt;div&gt;import java.security.KeyPairGenerator;&lt;/div&gt;&lt;div&gt;import java.security.NoSuchAlgorithmException;&lt;/div&gt;&lt;div&gt;import java.security.NoSuchProviderException;&lt;/div&gt;&lt;div&gt;import java.security.PrivateKey;&lt;/div&gt;&lt;div&gt;import java.security.PublicKey;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;import entiebank.utils.Utils;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;public class RSAKeyGenerator {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public static void genRSAPairKey(String keyFileName,String alg){&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;try {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;KeyPairGenerator keyGen = KeyPairGenerator.getInstance(alg);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;keyGen.initialize(1024);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;KeyPair keyPair =keyGen.generateKeyPair();&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;PublicKey  pubKey = keyPair.getPublic();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;System.out.println(pubKey.hashCode());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;Utils.writeKeyFile(keyFileName+&quot;.pub&quot;, pubKey);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;PrivateKey priKey= keyPair.getPrivate();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;System.out.println(priKey.hashCode());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;Utils.writeKeyFile(keyFileName+&quot;.pri&quot;, priKey);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (NoSuchAlgorithmException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public static void main(String[] arg){&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;RSAKeyGenerator.genRSAPairKey(&quot;louisz&quot;,&quot;RSA&quot;);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;RSAUtils&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;import java.io.FileInputStream;&lt;/div&gt;&lt;div&gt;import java.io.FileNotFoundException;&lt;/div&gt;&lt;div&gt;import java.io.IOException;&lt;/div&gt;&lt;div&gt;import java.io.ObjectInputStream;&lt;/div&gt;&lt;div&gt;import java.security.InvalidKeyException;&lt;/div&gt;&lt;div&gt;import java.security.NoSuchAlgorithmException;&lt;/div&gt;&lt;div&gt;import java.security.PrivateKey;&lt;/div&gt;&lt;div&gt;import java.security.PublicKey;&lt;/div&gt;&lt;div&gt;import javax.crypto.BadPaddingException;&lt;/div&gt;&lt;div&gt;import javax.crypto.Cipher;&lt;/div&gt;&lt;div&gt;import javax.crypto.IllegalBlockSizeException;&lt;/div&gt;&lt;div&gt;import javax.crypto.NoSuchPaddingException;&lt;/div&gt;&lt;div&gt;import javax.crypto.SecretKey;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;import entiebank.security.des.DESUtils;&lt;/div&gt;&lt;div&gt;import entiebank.utils.Utils;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;public class RSAUtils {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;private static PublicKey pubKey = null; &lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;private static PrivateKey priKey = null;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public static void loadRSAPubKey(String keyFileName){&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;pubKey=(PublicKey)Utils.readKeyFile(keyFileName);&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public static void loadRSAPriKey(String keyFileName){&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;priKey=(PrivateKey)Utils.readKeyFile(keyFileName);&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public static PublicKey getPublicKey(){&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;return pubKey;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public static PrivateKey getPrivateKey(){&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;return priKey;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public static String encrypt(String clearString){&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;try {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;Cipher desCipher = Cipher.getInstance(&quot;RSA&quot;);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;desCipher.init(Cipher.ENCRYPT_MODE,getPublicKey());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;//System.out.println(&quot;clearStr=&quot;+encryptString);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;//System.out.println(&quot;encrypt==&quot;+new String(desCipher.doFinal(encryptString.getBytes())));&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;return Utils.bytesToBase64Str(desCipher.doFinal(clearString.getBytes()));&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (NoSuchAlgorithmException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (NoSuchPaddingException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (InvalidKeyException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (IllegalBlockSizeException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (BadPaddingException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;return null;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public static String decrypt(String encryptString){&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;try {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;Cipher desCipher = Cipher.getInstance(&quot;RSA&quot;);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;desCipher.init(Cipher.DECRYPT_MODE,getPrivateKey());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;return new String(desCipher.doFinal(Utils.base64StrToBytes(encryptString)));&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (NoSuchAlgorithmException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (NoSuchPaddingException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (IllegalBlockSizeException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (BadPaddingException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (InvalidKeyException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;return null;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public static void main(String[] arg){&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;//RSAUtils rsa = new RSAUtils();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;RSAUtils.loadRSAPriKey(&quot;louisz.pri&quot;);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;RSAUtils.loadRSAPubKey(&quot;louisz.pub&quot;);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;System.out.println(RSAUtils.encrypt(&quot;hehe it&#39;s can works&quot;));&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;//System.out.println(rsa.decrypt(&quot;m/krh4KOgSNrDWpUrgUQ0ifVYmBnDAhdYU/B9HFZGiPsHDKOob/oQaJWyQX0a+VrC4igFq2a7zERrqUBjrImGgknMgjlko6NAufOHMu4BP4wblY68pIFPdIb1VZrN38vLgrtUjk1eXok7akn89Lu6NksBrlKoYEy2rOW/BfrCGs=&quot;));&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Utils&lt;/div&gt;&lt;div&gt;&lt;div&gt;import java.io.BufferedInputStream;&lt;/div&gt;&lt;div&gt;import java.io.BufferedReader;&lt;/div&gt;&lt;div&gt;import java.io.FileInputStream;&lt;/div&gt;&lt;div&gt;import java.io.FileNotFoundException;&lt;/div&gt;&lt;div&gt;import java.io.FileOutputStream;&lt;/div&gt;&lt;div&gt;import java.io.FileReader;&lt;/div&gt;&lt;div&gt;import java.io.IOException;&lt;/div&gt;&lt;div&gt;import java.io.ObjectInputStream;&lt;/div&gt;&lt;div&gt;import java.io.ObjectOutputStream;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;import javax.crypto.SecretKey;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;import sun.misc.BASE64Decoder;&lt;/div&gt;&lt;div&gt;import sun.misc.BASE64Encoder;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;public class Utils {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public static Object readKeyFile(String keyFileName){&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;Object obj = null;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;try {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;FileInputStream fin = new FileInputStream(keyFileName);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;ObjectInputStream ios = new ObjectInputStream(fin);&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;&lt;/div&gt;&lt;div&gt;//&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;DESKeySpec kSpec = (DESKeySpec)ios.readObject();&lt;/div&gt;&lt;div&gt;//&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;kSpec.getKey();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt; obj= ios.readObject();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;ios.close();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;fin.close();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;return obj;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (FileNotFoundException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (IOException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (ClassNotFoundException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;}&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;return null;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public static void writeKeyFile(String keyFileName,Object sKey){&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;try {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;FileOutputStream fos = new FileOutputStream(keyFileName);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;ObjectOutputStream oos = new ObjectOutputStream(fos);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;oos.writeObject(sKey);&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;oos.close();&lt;/div&gt;&lt;div&gt;//&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;fos.write(sKey.getEncoded());&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;fos.close();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (IOException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public static String bytesToBase64Str(byte[] bytes){&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;return new BASE64Encoder().encode(bytes);&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;public static byte[] base64StrToBytes(String base64Str){&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;try {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;return new BASE64Decoder().decodeBuffer(base64Str);&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;} catch (IOException e) {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;return null;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://louiszspower.blogspot.com/feeds/8134594007369362576/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://louiszspower.blogspot.com/2008/11/desrsa.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/8134594007369362576'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/8134594007369362576'/><link rel='alternate' type='text/html' href='http://louiszspower.blogspot.com/2008/11/desrsa.html' title='玩玩DES及RSA'/><author><name>Louisz</name><uri>http://www.blogger.com/profile/15227162328934605700</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuq5rOe6t7hT-kppa8Fu3eLB6RzgYqY8I7hZyMmMKyeAVUNbzRxsj7SQQA1EyynM-Ac6FjR6PmyXhcfn6PiIsBkByRyY8nSu3CWpAlXTcOcfGjpUDCpSBge2ou1j770EY/s220/IMG_20170629_210051.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553741655215810943.post-6756560150927230098</id><published>2008-11-24T22:21:00.000-08:00</published><updated>2008-11-24T22:34:01.918-08:00</updated><title type='text'>IReport use stored procedure</title><content type='html'>很簡單&lt;div&gt;{call stored_procedure(&quot;param1&quot;&lt;span&gt;, &quot;param2&quot;...)&lt;/span&gt; }&lt;/div&gt;&lt;div&gt;這樣就可以了，會以回傳ResultSet的方式進行，下一步則可以看到回傳的欄位&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;img src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDCg1pYmqN15e0LfSi2pZDzhiTiUU14_CffBdW_ERrhxKxAHwjEUt77doRF4dUJ3GttMtyZ_KSDOw3pzNQGcFtW8HOOFFiWXFEUKEoqPqn6qLeI_ZwA7ncfUreJpe1WYoMRaKGyM5mRDc/s400/sp_1.JPG&quot; style=&quot;cursor:pointer; cursor:hand;width: 400px; height: 300px;&quot; border=&quot;0&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5272478879141982130&quot; /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://louiszspower.blogspot.com/feeds/6756560150927230098/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://louiszspower.blogspot.com/2008/11/ireport-use-stored-procedure.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/6756560150927230098'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/6756560150927230098'/><link rel='alternate' type='text/html' href='http://louiszspower.blogspot.com/2008/11/ireport-use-stored-procedure.html' title='IReport use stored procedure'/><author><name>Louisz</name><uri>http://www.blogger.com/profile/15227162328934605700</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuq5rOe6t7hT-kppa8Fu3eLB6RzgYqY8I7hZyMmMKyeAVUNbzRxsj7SQQA1EyynM-Ac6FjR6PmyXhcfn6PiIsBkByRyY8nSu3CWpAlXTcOcfGjpUDCpSBge2ou1j770EY/s220/IMG_20170629_210051.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDCg1pYmqN15e0LfSi2pZDzhiTiUU14_CffBdW_ERrhxKxAHwjEUt77doRF4dUJ3GttMtyZ_KSDOw3pzNQGcFtW8HOOFFiWXFEUKEoqPqn6qLeI_ZwA7ncfUreJpe1WYoMRaKGyM5mRDc/s72-c/sp_1.JPG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5553741655215810943.post-6209446100467873269</id><published>2008-11-24T00:22:00.000-08:00</published><updated>2008-11-24T01:08:15.348-08:00</updated><title type='text'>JMeter設定JDBC連線測試</title><content type='html'>&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-left:29.5pt;text-indent:-24.0pt;mso-list:l0 level1 lfo1; tab-stops:list 29.5pt;mso-layout-grid-align:none;text-autospace:none&quot;&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-left:29.5pt;text-indent:-24.0pt;mso-list:l0 level1 lfo1; tab-stops:list 29.5pt;mso-layout-grid-align:none;text-autospace:none&quot;&gt;1.先將欲測試的JDBC驅動程式放在Jmeter/lib下&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-left:29.5pt;text-indent:-24.0pt;mso-list:l0 level1 lfo1; tab-stops:list 29.5pt;mso-layout-grid-align:none;text-autospace:none&quot;&gt;2.啟動Jmeter，滑鼠右鍵於【測試計畫】新增【執行緒群組】新增【設定元素】選擇【JDBC連線設定】相關設定說明如下&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-left:29.5pt;text-indent:-24.0pt;mso-list:l0 level1 lfo1; tab-stops:list 29.5pt;mso-layout-grid-align:none;text-autospace:none&quot;&gt;名稱：連線設定名稱&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-left:29.5pt;text-indent:-24.0pt;mso-list:l0 level1 lfo1; tab-stops:list 29.5pt;mso-layout-grid-align:none;text-autospace:none&quot;&gt;變數名稱：為該JDBC連線的變數，請以英數字為主&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-left:29.5pt;text-indent:-24.0pt;mso-list:l0 level1 lfo1; tab-stops:list 29.5pt;mso-layout-grid-align:none;text-autospace:none&quot;&gt;資料庫URL設定：欲連接的資料庫及JDBC的URL設定&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-left:29.5pt;text-indent:-24.0pt;mso-list:l0 level1 lfo1; tab-stops:list 29.5pt;mso-layout-grid-align:none;text-autospace:none&quot;&gt;JDBC驅動程式：欲測試的JDBC驅動程式的Driver名稱&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-left:29.5pt;text-indent:-24.0pt;mso-list:l0 level1 lfo1; tab-stops:list 29.5pt;mso-layout-grid-align:none;text-autospace:none&quot;&gt;使用者：資料庫連線使用者&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-left:29.5pt;text-indent:-24.0pt;mso-list:l0 level1 lfo1; tab-stops:list 29.5pt;mso-layout-grid-align:none;text-autospace:none&quot;&gt;密碼：上述使用者之密碼&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-left:29.5pt;text-indent:-24.0pt;mso-list:l0 level1 lfo1; tab-stops:list 29.5pt;mso-layout-grid-align:none;text-autospace:none&quot;&gt;其他設定可採用預設質或是依據所需進行設定&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-left:29.5pt;text-indent:-24.0pt;mso-list:l0 level1 lfo1; tab-stops:list 29.5pt;mso-layout-grid-align:none;text-autospace:none&quot;&gt;&lt;img src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZOfLbPyv59GYZUCieMyT0JKCCgI2XCg0HsYxGBWapcsmFBCF7l09JyvNXMQPSyQsSeFeiRHSJVzdCTOgv8-9xOsRqaRk0N2PM0S2iJPAE-CdfjGC6rZLGXaGN-N9jo0Wdi9oD76D9s_A/s400/jmeter-1.JPG&quot; style=&quot;cursor:pointer; cursor:hand;width: 400px; height: 300px;&quot; border=&quot;0&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5272140669588842194&quot; /&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-left:29.5pt;text-indent:-24.0pt;mso-list:l0 level1 lfo1; tab-stops:list 29.5pt;mso-layout-grid-align:none;text-autospace:none&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-left:29.5pt;text-indent:-24.0pt;mso-list:l0 level1 lfo1; tab-stops:list 29.5pt;mso-layout-grid-align:none;text-autospace:none&quot;&gt;3.於【執行緒群組】新增【JDBC要求】相關設定如下&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-left:29.5pt;text-indent:-24.0pt;mso-list:l0 level1 lfo1; tab-stops:list 29.5pt;mso-layout-grid-align:none;text-autospace:none&quot;&gt;名稱：JDBC要求名稱&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-left:29.5pt;text-indent:-24.0pt;mso-list:l0 level1 lfo1; tab-stops:list 29.5pt;mso-layout-grid-align:none;text-autospace:none&quot;&gt;變數名稱：請使用JDBC連線設定的變數名稱&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-left:29.5pt;text-indent:-24.0pt;mso-list:l0 level1 lfo1; tab-stops:list 29.5pt;mso-layout-grid-align:none;text-autospace:none&quot;&gt;Query Type：請依所需使用囉&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-left:29.5pt;text-indent:-24.0pt;mso-list:l0 level1 lfo1; tab-stops:list 29.5pt;mso-layout-grid-align:none;text-autospace:none&quot;&gt;&lt;img src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiif-k9hz6dIzfbd6op6dfzLSs2Gd68rIrvTMPMXgeVJe39ZVG_rrj0v9n_UTfI6B5OuEaiE8lAsCq8SbLjmsjKXEsofawhzRRGrS0cY9sWlR7fnexyzrs-9A4YH0qyFGUZcdjg7MlynAE/s400/jmeter-2.JPG&quot; style=&quot;cursor:pointer; cursor:hand;width: 400px; height: 300px;&quot; border=&quot;0&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5272148061978806306&quot; /&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-left:29.5pt;text-indent:-24.0pt;mso-list:l0 level1 lfo1; tab-stops:list 29.5pt;mso-layout-grid-align:none;text-autospace:none&quot;&gt;查詢：請輸入需要測試的SQL&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-left:29.5pt;text-indent:-24.0pt;mso-list:l0 level1 lfo1; tab-stops:list 29.5pt;mso-layout-grid-align:none;text-autospace:none&quot;&gt;4.於【執行緒群組】中【接聽】新增所需要看到的測試結果，例如檢視結果、檢視表格式結果等等&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-left:29.5pt;text-indent:-24.0pt;mso-list:l0 level1 lfo1; tab-stops:list 29.5pt;mso-layout-grid-align:none;text-autospace:none&quot;&gt;5.先測試相關設定有無問題，於【執行】中執行【開始】，在檢視結果中看看是否都是綠燈號誌&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-left:29.5pt;text-indent:-24.0pt;mso-list:l0 level1 lfo1; tab-stops:list 29.5pt;mso-layout-grid-align:none;text-autospace:none&quot;&gt;6.再依據所需於【執行緒群組】中設定測試數值再執行&lt;/p&gt;&lt;p&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://louiszspower.blogspot.com/feeds/6209446100467873269/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://louiszspower.blogspot.com/2008/11/jmeterjdbc.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/6209446100467873269'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5553741655215810943/posts/default/6209446100467873269'/><link rel='alternate' type='text/html' href='http://louiszspower.blogspot.com/2008/11/jmeterjdbc.html' title='JMeter設定JDBC連線測試'/><author><name>Louisz</name><uri>http://www.blogger.com/profile/15227162328934605700</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuq5rOe6t7hT-kppa8Fu3eLB6RzgYqY8I7hZyMmMKyeAVUNbzRxsj7SQQA1EyynM-Ac6FjR6PmyXhcfn6PiIsBkByRyY8nSu3CWpAlXTcOcfGjpUDCpSBge2ou1j770EY/s220/IMG_20170629_210051.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZOfLbPyv59GYZUCieMyT0JKCCgI2XCg0HsYxGBWapcsmFBCF7l09JyvNXMQPSyQsSeFeiRHSJVzdCTOgv8-9xOsRqaRk0N2PM0S2iJPAE-CdfjGC6rZLGXaGN-N9jo0Wdi9oD76D9s_A/s72-c/jmeter-1.JPG" height="72" width="72"/><thr:total>0</thr:total></entry></feed>