實現pdfmake使用中文本體主要就是編譯新的vfs_fonts.js代替原來vfs_fonts.js文檔引入到前端頁面中,為了編譯出新的字體文檔,下列是中文顯示的解決方法,供大家參考:

操作系統:Windows

操作步驟:

1. 安裝node.js

2. 下載pdfmake的源代碼、下載地址https://github.com/bpampuch/pdfmake

3. 在源代碼根目錄下安裝gulp:

打開cmd命令窗口,定位到源代碼根目錄,如:cd V:\pdfmake-master


npm install gulp
npm install -g gulp
npm i -g gulp-cli

執行gulp -v顯示gulp版本號則説明安裝成功

4. 利用gulp打包字體ttf文檔到vfs_fonts.js文檔中

gulp安裝成功後,查看源代碼根目錄下的gulpfile.js,發現gulp編譯還依賴了很多其他的模塊,所以需要一一安裝,沒辦法所以得一一安裝:npm install webpack-stream、npm install gulp-uglify 等等


V:\pdfmake-master>npm i -g gulp-cli

V:\node-v8.12.0-win-x64\gulp -> V:\node-v8.12.0-win-x64\node_modules\gulp-cli\bin\gulp.js

+ gulp-cli@2.0.1

added 235 packages from 147 contributors in 6.71s

V:\pdfmake-master>gulp buildFonts

[13:48:16] Using gulpfile V:\pdfmake-master\gulpfile.js

[13:48:16] Starting 'buildFonts'...

[13:48:17] Finished 'buildFonts' after 382 ms

 

從本地 C:\Windows\Fonts 下拷貝一箇中文本體到D:\download\chrome\pdfmake-master\examples\fonts目錄下,並刪除fonts目錄下原來的ttf文檔,這裏有一個問題,中文本體都很大,囧。

請選了一個最小的字體上:標楷體-標準 ,這一步完成之後,字體打包生成的vfs_fonts.js會覆蓋源代碼根目錄的build目錄下的vfs_fonts.js文檔,這時需要將vfs_fonts.js拷貝到你的項目當中替換原來的vfs_fonts.js,並引用的html頁面中

 

以 DataTables 為例

<button onclick="down('pdf文件中文顯示')">PDF下載</button>

      <!-- SELECT2 EXAMPLE -->
      <div class="box box-danger">
        <div class="box-header with-border">
          <h3 class="box-title">維護畫面</h3>

          <div class="box-tools pull-right">
            <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
            <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-remove"></i></button>
          </div>
        </div>
        <!-- /.box-header -->
        <div class="box-body">
          <div class="row">
            <div class="col-md-6">
              <div class="form-group">
                <label for="authorityName">Name</label>
                <input type="text" class="form-control" id="authorityName" placeholder="Authority Name" name="name">
                
              </div>
              <!-- /.form-group -->
              <div class="form-group">                
                <label for="authorityDescription">description</label>
                <input type="text" class="form-control" id="authorityDescription" placeholder="Authority Description" name="description">
              </div>
              <!-- /.form-group -->
            </div><!-- /.col -->
            
          </div><!-- /.row -->
        </div>
        <!-- /.box-body -->
        <div class="box-footer">
          Visit <a href="/security/authority">Authority</a>
        </div>
      </div>
      <!-- /.box -->


      <!-- Default box -->
      <div class="box box-info">
        <div class="box-header">
          <h3 class="box-title">角色清單</h3>

          <div class="box-tools pull-right">
            <button type="button" class="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip"
                    title="Collapse">
              <i class="fa fa-minus"></i></button>
            <button type="button" class="btn btn-box-tool" data-widget="remove" data-toggle="tooltip" title="Remove">
              <i class="fa fa-times"></i></button>
          </div>
        </div>
        <div class="box-body">
         
          <table id="tblAuthority" class="table table-bordered table-striped" style="width:100%">
            <thead>
            <tr>
              <th>id</th>
              <th>name</th>
              <th>description</th>
              <th>Options</th>
            </tr>
            </thead>
            
            <tfoot>
            <tr>
              <th>id</th>
              <th>name</th>
              <th>description</th>
              <th>Options</th>
            </tr>
            </tfoot>
          </table>
                                             
        </div>
        <!-- /.box-body -->
        <div class="box-footer">
          Footer
        </div>
        <!-- /.box-footer-->
      </div>
      <!-- /.box -->

<!-- page script -->
<script>
function down(data) {
    var dd = {
        content: [
            data,
            'Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines'
        ],
        defaultStyle: {
            font: 'kaiu'
        }
    };
    pdfMake.fonts = {
                kaiu: {
            normal: 'kaiu.ttf',
            bold: 'kaiu.ttf',
            italics: 'kaiu.ttf',
            bolditalics: 'kaiu.ttf'
        }
    };
    pdfMake.createPdf(dd).download();
}

$(document).ready(function() {
        
        pdfMake.fonts = {
                Roboto: {
            normal: 'kaiu.ttf',
            bold: 'kaiu.ttf',
            italics: 'kaiu.ttf',
            bolditalics: 'kaiu.ttf'
        }
    };  
        
          $('#tblAuthority').DataTable({        
        ajax: {url:"/authentication/authorities",dataSrc:""},
        columns: [
                { data: "id", visible: false},
            { data: "name" },
            { data: "description" },
            {
              data: "id", render: function(data, type, row, meta) {                  
                  return '<a href=' data ' class="btn btn-xs btn-primary"><i class="fa fa-pencil"></i>Edit</a> <a href=' data ' class="btn btn-xs btn-danger"><i class="fa fa-trash-o">Delete</a>'
              },
              className: "center",              
            }
        ],
        dom: 'lrBtip',        
        buttons: [
                'copy','excel', 
                {
                        extend: 'pdf',
                        text: 'PDF',
                        className: "btn btn-xs btn-primary",
                        'title': 'Authority List',                 
                'download': 'open',//直接在視窗開啟 
                },
                {
                extend: 'csv',
                text: 'CSV',
                className: "btn btn-xs btn-primary",
                bom : true
            }, 
            {
                text: 'My button',
                className: "btn btn-xs btn-primary",
                action: function ( e, dt, node, config ) {
                    alert( 'Button activated' );
                }
            },
            {
                text: 'Reload',
                className: "btn btn-xs btn-primary",
                action: function ( e, dt, node, config ) {
                    dt.ajax.reload();
                }
            }            
        ]
        
    });   

  })
</script>

https://hk.saowen.com/a/b58fede7fdfaef23bb9236286cc6ac318607f9f6899fd684c6d2af2509a4be3f

https://blog.csdn.net/qq_30076899/article/details/79731508

https://github.com/bpampuch/pdfmake/wiki/Custom-Fonts---client-side

文章標籤

MIS 發表在 痞客邦 留言(0) 人氣()

使用 Hibernate Tool 去產生 Domain Code ( Model ) 時, 當 User.java & Authority.java 有相互參考時, 在 spring boot 使用 @RestController 會發生 Direct self-reference leading to cycle 的錯誤訊息, 解決的方法可以在 Domain Code ( Model ) 上加上 @JsonManagedReference & @JsonBackReference 來防止錯誤.

 

User.java

/**
 * User generated by hbm2java
 */
@Entity
@Table(name = "user")
public class User implements java.io.Serializable {

        private Long id;
        private User userByCreateUser;
        private User userByUpdateUser;
        private String username;
        private String password;
        private String firstname;
        private String lastname;
        private String email;
        private Boolean enabled;
        private Date lastpasswordresetdate;
        private Date activeDate;
        private Date inactiveDate;
        private Date createDate;
        private Date updateDate;
        private Set authorities = new HashSet(0);
        private Set usersForCreateUser = new HashSet(0);
        private Set usersForUpdateUser = new HashSet(0);

        public User() {
        }

        public User(String username, String password, String firstname, String lastname, String email,
                        Date lastpasswordresetdate) {
                this.username = username;
                this.password = password;
                this.firstname = firstname;
                this.lastname = lastname;
                this.email = email;
                this.lastpasswordresetdate = lastpasswordresetdate;
        }

        public User(User userByCreateUser, User userByUpdateUser, String username, String password, String firstname,
                        String lastname, String email, Boolean enabled, Date lastpasswordresetdate, Date activeDate,
                        Date inactiveDate, Date createDate, Date updateDate, Set authorities,
                        Set usersForCreateUser, Set usersForUpdateUser) {
                this.userByCreateUser = userByCreateUser;
                this.userByUpdateUser = userByUpdateUser;
                this.username = username;
                this.password = password;
                this.firstname = firstname;
                this.lastname = lastname;
                this.email = email;
                this.enabled = enabled;
                this.lastpasswordresetdate = lastpasswordresetdate;
                this.activeDate = activeDate;
                this.inactiveDate = inactiveDate;
                this.createDate = createDate;
                this.updateDate = updateDate;
                this.authorities = authorities;
                this.usersForCreateUser = usersForCreateUser;
                this.usersForUpdateUser = usersForUpdateUser;
        }

        @Id
        @GeneratedValue(strategy = IDENTITY)

        @Column(name = "id", unique = true, nullable = false)
        public Long getId() {
                return this.id;
        }

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

        @ManyToOne(fetch = FetchType.LAZY)
        @JoinColumn(name = "create_user")
        public User getUserByCreateUser() {
                return this.userByCreateUser;
        }

        public void setUserByCreateUser(User userByCreateUser) {
                this.userByCreateUser = userByCreateUser;
        }

        @ManyToOne(fetch = FetchType.LAZY)
        @JoinColumn(name = "update_user")
        public User getUserByUpdateUser() {
                return this.userByUpdateUser;
        }

        public void setUserByUpdateUser(User userByUpdateUser) {
                this.userByUpdateUser = userByUpdateUser;
        }

        @Column(name = "username", nullable = false, length = 50)
        public String getUsername() {
                return this.username;
        }

        public void setUsername(String username) {
                this.username = username;
        }

        @Column(name = "password", nullable = false, length = 100)
        public String getPassword() {
                return this.password;
        }

        public void setPassword(String password) {
                this.password = password;
        }

        @Column(name = "firstname", nullable = false, length = 50)
        public String getFirstname() {
                return this.firstname;
        }

        public void setFirstname(String firstname) {
                this.firstname = firstname;
        }

        @Column(name = "lastname", nullable = false, length = 50)
        public String getLastname() {
                return this.lastname;
        }

        public void setLastname(String lastname) {
                this.lastname = lastname;
        }

        @Column(name = "email", nullable = false, length = 50)
        public String getEmail() {
                return this.email;
        }

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

        @Column(name = "enabled")
        public Boolean getEnabled() {
                return this.enabled;
        }

        public void setEnabled(Boolean enabled) {
                this.enabled = enabled;
        }

        @Temporal(TemporalType.TIMESTAMP)
        @Column(name = "lastpasswordresetdate", nullable = false, length = 19)
        public Date getLastpasswordresetdate() {
                return this.lastpasswordresetdate;
        }

        public void setLastpasswordresetdate(Date lastpasswordresetdate) {
                this.lastpasswordresetdate = lastpasswordresetdate;
        }

        @Temporal(TemporalType.TIMESTAMP)
        @Column(name = "active_date", length = 19)
        public Date getActiveDate() {
                return this.activeDate;
        }

        public void setActiveDate(Date activeDate) {
                this.activeDate = activeDate;
        }

        @Temporal(TemporalType.TIMESTAMP)
        @Column(name = "inactive_date", length = 19)
        public Date getInactiveDate() {
                return this.inactiveDate;
        }

        public void setInactiveDate(Date inactiveDate) {
                this.inactiveDate = inactiveDate;
        }

        @Temporal(TemporalType.TIMESTAMP)
        @Column(name = "create_date", length = 19)
        public Date getCreateDate() {
                return this.createDate;
        }

        public void setCreateDate(Date createDate) {
                this.createDate = createDate;
        }

        @Temporal(TemporalType.TIMESTAMP)
        @Column(name = "update_date", length = 19)
        public Date getUpdateDate() {
                return this.updateDate;
        }

        public void setUpdateDate(Date updateDate) {
                this.updateDate = updateDate;
        }

        @ManyToMany(fetch = FetchType.LAZY)
        @JoinTable(name = "user_authority", catalog = "my_spring", joinColumns = {
                        @JoinColumn(name = "user_id", nullable = false, updatable = false) }, inverseJoinColumns = {
                                        @JoinColumn(name = "authority_id", nullable = false, updatable = false) })
        @JsonManagedReference
        public Set getAuthorities() {
                return this.authorities;
        }

        public void setAuthorities(Set authorities) {
                this.authorities = authorities;
        }

        @OneToMany(fetch = FetchType.LAZY, mappedBy = "userByCreateUser")
        public Set getUsersForCreateUser() {
                return this.usersForCreateUser;
        }

        public void setUsersForCreateUser(Set usersForCreateUser) {
                this.usersForCreateUser = usersForCreateUser;
        }

        @OneToMany(fetch = FetchType.LAZY, mappedBy = "userByUpdateUser")
        public Set getUsersForUpdateUser() {
                return this.usersForUpdateUser;
        }

        public void setUsersForUpdateUser(Set usersForUpdateUser) {
                this.usersForUpdateUser = usersForUpdateUser;
        }

}

 

Authority.java

/**
 * Authority generated by hbm2java
 */
@Entity
@Table(name = "authority")
public class Authority implements java.io.Serializable {

        private Long id;
        private String name;
        private String description;
        private Set users = new HashSet(0);

        public Authority() {
        }

        public Authority(String name, String description) {
                this.name = name;
                this.description = description;
        }

        public Authority(String name, String description, Set users) {
                this.name = name;
                this.description = description;
                this.users = users;
        }

        @Id
        @GeneratedValue(strategy = IDENTITY)

        @Column(name = "id", unique = true, nullable = false)
        public Long getId() {
                return this.id;
        }

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

        @Column(name = "name", nullable = false, length = 50)
        public String getName() {
                return this.name;
        }

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

        @Column(name = "description", nullable = false, length = 100)
        public String getDescription() {
                return this.description;
        }

        public void setDescription(String description) {
                this.description = description;
        }

        @ManyToMany(fetch = FetchType.LAZY)
        @JoinTable(name = "user_authority", catalog = "my_spring", joinColumns = {
                        @JoinColumn(name = "authority_id", nullable = false, updatable = false) }, inverseJoinColumns = {
                                        @JoinColumn(name = "user_id", nullable = false, updatable = false) })
         @JsonBackReference
        public Set getUsers() {
                return this.users;
        }

        public void setUsers(Set users) {
                this.users = users;
        }
}

 

 

 

參考:

http://keenformatics.blogspot.com/2013/08/how-to-solve-json-infinite-recursion.html

文章標籤

MIS 發表在 痞客邦 留言(0) 人氣()

SpringBoot+SpringSecurity+Freemarker專案中在頁面上使用security標籤控制按鈕顯示隱藏達到對按鈕級許可權控制還是比較方便的,如下配置即可。


1. gradle 引入依賴


dependencies {
        compile("org.springframework.security:spring-security-taglibs")
        compile("javax.servlet.jsp:javax.servlet.jsp-api:2.3.3")
}


2. 依賴引入後到spring-security-taglibs包中META-INF下security.tld複製出來,放到/resources/static下,最後建一個目錄tags,如下:

springboot-taglib.jpg
3. 建一個配置類


@Configuration
public class MvcConfig implements WebMvcConfigurer {
         @Autowired
         FreeMarkerConfigurer freeMarkerConfigurer;
    
    /**
     *  
     *    加入 spring-security-taglibs 對 FreeMarker 的支援
     */
    @PostConstruct
    public void freeMarkerConfigurer() {
        List tlds = new ArrayList();
        tlds.add("/static/tags/security.tld");
        TaglibFactory taglibFactory = freeMarkerConfigurer.getTaglibFactory();
        taglibFactory.setClasspathTlds(tlds);
        if(taglibFactory.getObjectWrapper() == null) {
            taglibFactory.setObjectWrapper(freeMarkerConfigurer.getConfiguration().getObjectWrapper());
        }
    }
}


4. 在freemarker頁面頂部引入標籤


<#assign security=JspTaglibs["http://www.springframework.org/security/tags"] />


5. 標籤應用如下


<@security.authorize access="hasRole('ADMIN')">

Admin can read
</@security.authorize>

<@security.authorize access="hasRole('USER')">

User can read
</@security.authorize>
文章標籤

MIS 發表在 痞客邦 留言(0) 人氣()

除了 痞客邦 PIXNET 使用 Syntax Highlighter 顯示程式碼 以外, 也可以使用 highlight.js 來讓 pixnet 顯示程式碼

在後台管理的 側欄管理, 選擇 頁尾描述加入

<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/languages/go.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>


日後要展示程式碼的部分,先在撰寫貼上程式碼,轉到原始碼模式,用

<pre><code class="html">...</code></pre>

把程式碼包起來。

文章標籤

MIS 發表在 痞客邦 留言(0) 人氣()

Spring Boot + Freemarker 多語言國際化的作法

1. 在 application.properties 增加

# ===============================
# Multi Language
# ===============================
spring.messages.basename=i18n/messages

# 為了取得當前頁面的URL (get current page url)
spring.freemarker.expose-spring-macro-helpers=true

2. 在 resource 目錄下建立一個目錄 i18n , 並新增三個檔

messages.properties , messages_zh_TW.properties , 內容為

label.login =  登入

messages_en_US.properties 內容為

label.login =  Login

3. 建立 WebMvcConfig : MvcConfig.class

@Configuration
public class MvcConfig implements WebMvcConfigurer {    
    //多語系設定
    @Bean(name = "localeResolver")
    public LocaleResolver getLocaleResolver()  {
        CookieLocaleResolver resolver= new CookieLocaleResolver();
        resolver.setCookieDomain("jwtLocaleCookie");
        // 60 minutes 
        resolver.setCookieMaxAge(60*60); 
        return resolver;
    } 
    //多語系設定 語系切換偵測
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        LocaleChangeInterceptor localeInterceptor = new LocaleChangeInterceptor();
        localeInterceptor.setParamName("lang");
                  
        registry.addInterceptor(localeInterceptor).addPathPatterns("/*");
    }

}

4. Control file: MainController.class

@Controller
public class MainController {
        
        @RequestMapping(value = { "/","/home" })
    public String staticResource(Model model) {
        return "home";
    }

}

5. View: home.ftl

<#import "/spring.ftl" as spring/>





注意, FTL的第一行要 import "/spring.ftl" ,這樣子就可以輕鬆切換語系了

 

文章標籤

MIS 發表在 痞客邦 留言(0) 人氣()

使用 Hibernate Tool 產生 Model 時, FetchType 預設是 FetchType.LAZY , 但在執行時, 卻常會產生類似下列 no Session 的錯誤訊息

org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.spring.jwt.db.maria.model.authentication.User.userAuthorities, could not initialize proxy - no Session

 

這時候需要在 Method 前加入 @Transactional 就可以解決

@Test
@Transactional
public void testUserAuthority() {
        User user = userRepository.findById(1L).get();
        JwtUser jwtUser = JwtUserFactory.create(user);
        logger.info(jwtUser.getUsername());
        
}

Ref: http://javasampleapproach.com/hibernate/use-hibernate-lazy-fetch-eager-fetch-type-spring-boot-mysql

MIS 發表在 痞客邦 留言(0) 人氣()

使用 Spring Boot 2 建置系統就是希望快速. 若專案範圍小的話, 資料庫倒是可以考慮使用 H2 database 來建罝

在 build.gradle 上加入

compile('com.h2database:h2')

然後編輯 application.properties

server.port=8088
# ===============================
# H2
# ===============================
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
這樣就可以登入 http://localhost:8088/h2-console 操作了
文章標籤

MIS 發表在 痞客邦 留言(0) 人氣()

 環境: ApacheFriends XAMPP Version 7.1.7

  + Apache 2.4.26
  + MariaDB 10.1.25
  + PHP 7.1.7 (VC14 X86 32bit thread safe) + PEAR
  + phpMyAdmin 4.7.0
  + OpenSSL 1.0.2f
  + ADOdb 518a
  + Mercury Mail Transport System v4.63 (not included in the portable version)
  + FileZilla FTP Server 0.9.41 (not included in the portable version)
  + Webalizer 2.23-04 (not included in the portable version)
  + Strawberry Perl 5.16.1.1 Portable
  + Tomcat 7.0.56
  + XAMPP Control Panel Version 3.2.2 by hackattack142

Step01: 先將 php.ini 裡的 extension=php_pdo_oci.dll 注釋移除

; Be sure to appropriately set the extension_dir directive.
;
extension=php_bz2.dll
extension=php_curl.dll
extension=php_fileinfo.dll
;extension=php_ftp.dll
extension=php_gd2.dll
extension=php_gettext.dll
;extension=php_gmp.dll
;extension=php_intl.dll
;extension=php_imap.dll
;extension=php_interbase.dll
;extension=php_ldap.dll
extension=php_mbstring.dll
extension=php_exif.dll      ; Must be after mbstring as it depends on it
extension=php_mysqli.dll
;extension=php_oci8_12c.dll  ; Use with Oracle Database 12c Instant Client
;extension=php_openssl.dll
;extension=php_pdo_firebird.dll
extension=php_pdo_mysql.dll
extension=php_pdo_oci.dll
;extension=php_pdo_odbc.dll
;extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll
;extension=php_pgsql.dll
;extension=php_shmop.dll

Step02: 在 common\config 裡增加兩個檔 dbMaria.php & dbOracle.php

dbMaria.php

<?php
return [
        'class' => 'yii\db\Connection',
        'dsn' => 'mysql:host=localhost;dbname=mysite', // MySQL, MariaDB
        //'dsn' => 'sqlite:/path/to/database/file', // SQLite
        //'dsn' => 'pgsql:host=localhost;port=5432;dbname=mydatabase', // PostgreSQL
        //'dsn' => 'cubrid:dbname=demodb;host=localhost;port=33000', // CUBRID
        //'dsn' => 'sqlsrv:Server=localhost;Database=mydatabase', // MS SQL Server, sqlsrv driver
        //'dsn' => 'dblib:host=localhost;dbname=mydatabase', // MS SQL Server, dblib driver
        //'dsn' => 'mssql:host=localhost;dbname=mydatabase', // MS SQL Server, mssql driver
        //'dsn' => 'oci:dbname=//localhost:1521/mydatabase', // Oracle
        'username' => 'root',
        'password' => 'password',
        'charset' => 'utf8',
];
?>   

dbOracle.php

<?php
return [
        'class' => 'yii\db\Connection',
        //'dsn' => 'mysql:host=localhost;dbname=mysite', // MySQL, MariaDB
        //'dsn' => 'sqlite:/path/to/database/file', // SQLite
        //'dsn' => 'pgsql:host=localhost;port=5432;dbname=mydatabase', // PostgreSQL
        //'dsn' => 'cubrid:dbname=demodb;host=localhost;port=33000', // CUBRID
        //'dsn' => 'sqlsrv:Server=localhost;Database=mydatabase', // MS SQL Server, sqlsrv driver
        //'dsn' => 'dblib:host=localhost;dbname=mydatabase', // MS SQL Server, dblib driver
        //'dsn' => 'mssql:host=localhost;dbname=mydatabase', // MS SQL Server, mssql driver
        'dsn' => 'oci:dbname=//localhost:1521/xe;charset=AL32UTF8', // Oracle  ;charset=AL32UTF8=>解決中文亂碼
        'username' => 'system',
        'password' => 'password',
];
?>   

Step03 : 修改 common\config 裡的 main-local.php

<?php
return [
    'components' => [
        'db'=>require(__DIR__ . '/dbMaria.php'),
        'db2'=>require(__DIR__ . '/dbOracle.php'),

        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'viewPath' => '@common/mail',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => true,
        ],
    ],
    'timeZone' => 'Asia/Taipei',
];

Step04: 測試:

   /**
     * Displays a single Post model.
     * @param integer $id
     * @return mixed
     */
    public function actionView($id)
    {
//         $post = Yii::$app->db->createCommand('select * from post
//                     where id=:id and status=:status')
//                     ->bindValue(':id', $_GET['id'])
//                     ->bindValue(':status', 2)
//                     ->queryOne();

//         $post = Post::find()->where(['id'=>$id])->one();
//         $post = Post::findOne(['id'=>$id]);
//         var_dump($post);
//         $posts = Post::findAll(['status'=>2]);
//         $posts = Post::find()->where(['and','author_id=1', ['status'=>2],['like','title','yii2']])
//                              ->orderBy('id')->all();        
//         var_dump($posts);

        $users = Yii::$app->db2->createCommand('select * from spfs.USER_DETAILS')->queryAll();        
        var_dump($users);
        exit(0);

        
        return $this->render('view', [
            'model' => $this->findModel($id),
        ]);
    }

 

 

 

文章標籤

MIS 發表在 痞客邦 留言(0) 人氣()

在 Tomcat 的 server.xml 裡設定

<Context docBase="weixin" path="/weixin" reloadable="true" source="org.eclipse.jst.jee.server:weixin">
        <Resource name="jdbc/mysqlLocalDS01" username="root" password="password" url="jdbc:mysql://localhost:3306?characterEncoding=utf-8" auth="Container" driverClassName="com.mysql.cj.jdbc.Driver" factory="org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory" maxIdle="10" maxTotal="20" maxWaitMillis="-1" type="javax.sql.DataSource" />      
        <Resource name="jdbc/JappsDS01" username="ap" password="password" url="jdbc:oracle:thin:@127.0.0.1:1521:xe" driverClassName="oracle.jdbc.driver.OracleDriver" maxIdle="2" maxTotal="4" maxWaitMillis="5000"  type="javax.sql.DataSource" validationQuery="select 1 from dual"/>
    <Resources>
       <PreResources base="C://CKFinderJava//userfiles" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/userfiles"/>
   </Resources>
</Context>

在 JBoss EAP 6.x 上, 需建一個檔案: WEB-INF\jboss-web.xml

<jboss-web version="7.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jboss="http://www.jboss.com/xml/ns/javaee"  
               xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee jboss-web_7_0.xsd">  
        <symbolic-linking-enabled>true</symbolic-linking-enabled>    
        <overlay>C:/CKFinderJava/userfiles</overlay>
 
</jboss-web>

就可以用下列的連結來看檔案。

PS: mis 是目前的專案,而 images/S_13164601.jpgC:/CKFinderJava/userfiles 下的目錄及檔案

http://localhost:8080/mis/images/S_13164601.jpg

 

REF: https://developer.jboss.org/thread/266445

文章標籤

MIS 發表在 痞客邦 留言(0) 人氣()

環境:

eclipse : https://eclipse.org/downloads/packages/release/Neon/3

python: Python 3.6.1

django: Django-1.11.1.tar.gz

先下載 Python 3.6.1 安裝在 C:\Python\Python36-32 然後增加 Path

Django-1.11.1.tar.gz 解壓縮在 C:\Python\Python36-32 目錄下,然後執行下列指令

C:\Python\Python36-32\Django-1.11.1\python setup.py install

 

最後在eclipse 的 Preferences 設定即可

參考:

http://www.pydev.org/download.html

文章標籤

MIS 發表在 痞客邦 留言(0) 人氣()