PIXNET Logo登入

Codeless的部落格

跳到主文

歡迎光臨Codeless在痞客邦的小天地

部落格全站分類:數位生活

  • 相簿
  • 部落格
  • 留言
  • 名片
  • 6月 18 週四 201511:07
  • Sprng Form Handling

Spging mvc 可以針對簡單的form去處理(結合JSTL)。

web.xml

<display-name>Spring MVC Form Handling</display-name>
 <session-config>
 <session-timeout>
 30
 </session-timeout>
 </session-config>
 <servlet>
 <servlet-name>HelloWeb</servlet-name>
 <servlet-class>
 org.springframework.web.servlet.DispatcherServlet
 </servlet-class>
 <init-param>
 <param-name>contextConfigLocation</param-name>
 <param-value>/WEB-INF/spring-config.xml</param-value>
 </init-param>
 <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
 <servlet-name>HelloWeb</servlet-name>
 <url-pattern>/</url-pattern>
 </servlet-mapping>
 

spring-config.xml

<context:component-scan base-package="com.example" />
 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
 <property name="prefix" value="/WEB-INF/jsp/" />
 <property name="suffix" value=".jsp" />
 </bean>
 

(繼續閱讀...)
文章標籤

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

  • 個人分類:Spring tutorial
▲top
  • 6月 15 週一 201510:22
  • Spring MVC

安裝環境

O.S.:Win7

JDK:1.8.0

Eclipse:Luna 4.4.1

Server:Tomcat 1.8

(繼續閱讀...)
文章標籤

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

  • 個人分類:Spring tutorial
▲top
  • 6月 15 週一 201510:11
  • Annotation

Spting2.5後就可以使用Annotation的部分,在使用上面(較容易)可以取代原先XML的設定,但若是遇上Annotation和XML衝突的時候,則會以XML為主。

  • Required (可使用在setter上)

Customer.java

package com.example ;
 
 import org.springframework.beans.factory.annotation.Required;
 
 public class Customer {
 
 private String name ;
 private int age ;
 public String getName() {
 return name;
 }
 @Required
 public void setName(String name) {
 this.name = name;
 }
 public int getAge() {
 return age;
 }
 
 @Required
 public void setAge(int age) {
 this.age = age;
 } 
 }
 
 

Main.java

(繼續閱讀...)
文章標籤

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

  • 個人分類:Spring tutorial
▲top
  • 6月 15 週一 201509:56
  • Auto-wiring

Auto-wiring

config設定中autowire屬性可以依據當時的的狀況(no(預設)、byName、byType、constructor、autodetect)去自動綁定,而不需要去大量去撰寫的程式碼。

  • byName

Customer.java

package com.example;
 
 public class Customer 
 {
 private Address address;
 
 public Address getAddress() {
 return address;
 }
 
 public void setAddress(Address address) {
 this.address = address;
 }
 
 @Override
 public String toString() {
 return "Customer [address=" + address + "]";
 }
 
 }
 

(繼續閱讀...)
文章標籤

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

  • 個人分類:Spring tutorial
▲top
  • 6月 14 週日 201516:18
  • Injection Collection

注入除了一般型態外,也可針對Collection(List、Map、Set、Properties)進行注入。

Customer.java

package com.example ;
 
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
 
 
 public class Customer {
 
 private List nameList ;
 private Map nameMap ; 
 private Set nameSet ; 
 private Properties nameProp ;
 public List getNameList() {
 return nameList;
 }
 public void setNameList(List nameList) {
 this.nameList = nameList;
 }
 public Map getNameMap() {
 return nameMap;
 }
 public void setNameMap(Map nameMap) {
 this.nameMap = nameMap;
 }
 public Set getNameSet() {
 return nameSet;
 }
 public void setNameSet(Set nameSet) {
 this.nameSet = nameSet;
 }
 public Properties getNameProp() {
 return nameProp;
 }
 public void setNameProp(Properties nameProp) {
 this.nameProp = nameProp;
 }
 }
 

Main.java

package com.example ;
 
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 public class Main {
 
 public static void main(String[] args) {
 ApplicationContext context = 
 new ClassPathXmlApplicationContext("Beans.xml");
 
 Customer cust = (Customer) context.getBean("Customer");
 System.out.println("name list:"+cust.getNameList()) ;
 System.out.println("name map:"+cust.getNameMap()) ;
 System.out.println("name set:"+cust.getNameSet()) ;
 System.out.println("name property:"+cust.getNameProp()) ;
 }
 }
 

(繼續閱讀...)
文章標籤

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

  • 個人分類:Spring tutorial
▲top
  • 5月 19 週二 201517:02
  • Dependency Injection

(繼續閱讀...)
文章標籤

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

  • 個人分類:Spring tutorial
▲top
  • 5月 19 週二 201510:24
  • Bean Inheritance

(繼續閱讀...)
文章標籤

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

  • 個人分類:Spring tutorial
▲top
  • 5月 18 週一 201517:56
  • BeanPostProcessor 用法

(繼續閱讀...)
文章標籤

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

  • 個人分類:Spring tutorial
▲top
  • 5月 18 週一 201516:55
  • BEAN的scope和life cycle

(繼續閱讀...)
文章標籤

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

  • 個人分類:Spring tutorial
▲top
  • 5月 12 週二 201511:13
  • Spring基本概念

Spring 基本概念

Spring框架的核心就是Spring容器,主要是透過容器建立、設定、管理直到銷毀物件。容器主要是利用dependency injection (DI)去管理組成應用程式的元件(物件),而這些元件(物件)則稱為所謂的Beans。

Spring提供了下列兩種不同的容器:

Spring BeanFactory Container

HelloWorld.java

(繼續閱讀...)
文章標籤

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

  • 個人分類:Spring tutorial
▲top
12»

個人資訊

Codeless
暱稱:
Codeless
分類:
數位生活
好友:
累積中
地區:

熱門文章

  • ()Weblogic 清除cache方式
  • ()Spring 設定與安裝
  • ()Spring基本概念
  • ()JAVA透過URL抓取JSON
  • ()Spring MVC
  • ()Maven 環境設定與安裝
  • ()Junit 環境設定與安裝
  • ()Junit Annotation的應用
  • ()Eclipse內建立Maven project
  • ()Maven repository 概念

程式天地

  • 未分類文章 (1)

最新文章

    動態訂閱

    文章精選

    文章搜尋

    誰來我家

    參觀人氣

    • 本日人氣:
    • 累積人氣: