[TOC]
# struts MVC

# Action生命周期
1. 每次請求到來時,都會創建一個新的Action實例
2. Action是線程安全的.可以使用成員變量接收參數
# 屬性獲得參數
表單頁面
~~~
<form action="${pageContext.request.contextPath}/hello/HelloAction">
用戶名:<input type="text" name="name" /><br>
年齡:<input type="text" name="age" /><br>
生日:<input type="text" name="birthday" /><br>
<input type="submit" value="提交" />
</form>
~~~
action類
~~~
// 準備與參數鍵名稱相同的屬性
private String name;
// 自動類型轉換 只能轉換8大基本數據類型以及對應包裝類
private Integer age;
// 支持特定類型字符串轉換為Date ,例如 yyyy-MM-dd
private Date birthday;
public String hello() {
System.out.println("name參數值:" + name + ",age參數值:" + age + ",生日:" + birthday);
return "success";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
~~~
# 對象驅動
編寫一個對象,用來存放參數
User類
~~~
package param;
import java.util.Date;
public class User {
private String name;
private Integer age;
private Date birthday;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
@Override
public String toString() {
return "User [name=" + name + ", age=" + age + ", birthday=" + birthday + "]";
}
}
~~~
form表單頁面
~~~
<form action="${pageContext.request.contextPath}/hello/HelloAction">
用戶名:<input type="text" name="user.name" /><br>
年齡:<input type="text" name="user.age" /><br>
生日:<input type="text" name="user.birthday" /><br>
<input type="submit" value="提交" />
</form>
~~~
Action類
~~~
// 準備user對象
private User user;
public String hello() {
System.out.println(user);
return "success";
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
~~~
# 模型驅動
User類還是上面的
form表單
~~~
<form action="${pageContext.request.contextPath}/hello/HelloAction">
用戶名:<input type="text" name="name" /><br>
年齡:<input type="text" name="age" /><br>
生日:<input type="text" name="birthday" /><br>
<input type="submit" value="提交" />
</form>
~~~
Action類
~~~
package domain;
import com.opensymphony.xwork2.ModelDriven;
import param.User;
public class HelloAction implements ModelDriven<User> {
// 準備user對象
private User user = new User();;
public String hello() {
System.out.println(user);
return "success";
}
@Override
public User getModel() {
return user;
}
}
~~~
# 集合封裝
## list
form表單
~~~
<form action="${pageContext.request.contextPath}/hello/HelloAction">
list:<input type="text" name="list" /><br>
list:<input type="text" name="list[3]" /><br>
<input type="submit" value="提交" />
</form>
~~~
Action類
~~~
package domain;
import java.util.List;
public class HelloAction {
// list
private List<String> list;
public String hello() {
System.out.println("list:" + list);
return "success";
}
public List<String> getList() {
return list;
}
public void setList(List<String> list) {
this.list = list;
}
}
~~~
## map
form表單
~~~
<form action="${pageContext.request.contextPath}/Demo11Action" method="post" >
map:<input type="text" name="map['haha']" /><br>
<input type="submit" value="提交" />
</form>
~~~
Action類
~~~
import java.util.Map;
public class HelloAction {
// Map
private Map<String, String> map;
public String hello() {
System.out.println("map:" + map);
return "success";
}
public Map<String, String> getMap() {
return map;
}
public void setMap(Map<String, String> map) {
this.map = map;
}
}
~~~
- 基礎
- 編譯和安裝
- scanner類(鍵盤錄入)
- Random類(隨機數)
- 數組
- 方法
- 類
- ArrayList集合
- char與int
- eclipse
- IDEA
- 變量與常量
- 常用API
- String,StringBuffer,StringBuilder
- 正則,Date,DateFormat,Calendar
- 包裝類,System,Math,Arrays,BigInteger,BigDecimal
- 集合,迭代器,增強for,泛型
- List,set,判斷集合唯一
- map,Entry,HashMap,Collections
- 異常
- IO
- File
- 遞歸
- 字節流
- 字符流
- IO流分類
- 轉換流
- 緩沖流
- 流的操作規律
- properties
- 序列化流與反序列化流
- 打印流
- commons-IO
- IO流總結
- 多線程
- 線程池
- 線程安全
- 線程同步
- 死鎖
- lock接口
- ThreadLoad
- 等待喚醒機制
- 線程狀態
- jdbc
- DBUtils
- 連接池DBCP
- c3p0連接池
- 網絡編程
- 多線程socket上傳圖片
- 反射
- xml
- 設計模式
- 裝飾器模式
- web service
- tomcat
- Servlet
- response
- request
- session和cookie
- JSP
- EL
- JSTL
- 事務
- 監聽器Listener
- 過濾器Filter
- json
- linux安裝軟件
- 反射詳解
- 類加載器和注解
- 動態代理
- jedis
- Hibernate
- 簡介
- 創建映射文件
- Hibernate核心配置文件
- 事務和增刪改查
- HibernateUtils
- 持久化對象的三種狀態
- 檢索方式
- query
- Criteria
- SQLQuery
- 持久化類
- 主鍵生成策略
- 緩存
- 事務管理
- 關系映射
- 注解
- 優化
- struts2
- 搭建
- 配置詳解
- Action
- 結果跳轉方式
- 訪問ServletAPI方式
- 如何獲得參數
- OGNL表達式
- valueStack 值棧
- Interceptor攔截器
- spring
- 導包
- IOC和DI
- Bean獲取與實例化
- Bean屬性注入
- spring注解
- 注解分層
- junit整合
- aop
- 動態代理實現
- cglib代理實現
- aop名詞
- spring的aop
- aop-xml詳解
- aop-注解詳解
- 代理方式選擇
- jdbcTemplate
- spring事務管理
- 回滾注意
- 事務傳播屬性
- MyBatis
- MyBatis簡介
- 入門程序
- 與jdbc hibernate不同
- 原始Dao開發
- Mapper動態代理方式
- SqlMapConfig.xml配置文件
- 輸入參數pojo包裝類
- resultMap
- 動態sql
- 一對一關聯
- 一對多
- 整合spring
- 逆向工程
- maven
- maven簡介
- 倉庫
- maven目錄結構
- maven常用命令
- 生命周期
- eclipse中maven插件
- 入門程序
- 整合struct
- 依賴范圍
- 添加插件
- idea配置
- jar包沖突
- 分模塊開發
- 構建可執行的jar包(包含依賴jar包)
- springMVC
- 處理流程
- java面試
- java版本升級
- java1-8版本變更
- java9新特性
- 鎖
- java資料
- idea
- jdk版本切換
- log4j
- 入門實例
- 基本使用方法
- Web中使用Log4j
- spring中使用log4j
- java代碼優化