锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
boolean isObject = s instanceOf Object;
鎴戜滑澹版槑浜嗕竴涓猄tring瀵硅薄寮曠敤, 鎸囧悜涓涓猄tring 瀵硅薄, 鐒跺悗鐢╥nstanceof 鏉ユ祴璇曞畠鎵鎸囧悜鐨勫璞℃槸鍚︽槸Object綾葷殑涓涓疄渚? 鏄劇劧, 榪欐槸鐪熺殑, 鎵浠ヨ繑鍥瀟rue,涔熷氨鏄痠sObject鐨勫間負True.
instanceof鏈変竴浜涚敤澶? 姣斿鎴戜滑鍐欎簡涓涓鐞嗗笎鍗曠殑緋葷粺, 鍏朵腑鏈夎繖鏍蜂笁涓被錛?br> public class Bill{//鐪佺暐緇嗚妭}
public class PhoneBill extends Bill {//鐪佺暐緇嗚妭}
public class GasBill extends Bill {//鐪佺暐緇嗚妭}
鍦ㄥ鐞嗙▼搴忛噷鏈変竴涓柟娉? 鎺ュ彈涓涓狟ill綾誨瀷鐨勫璞? 璁$畻閲戦. 鍋囪涓ょ甯愬崟璁$畻鏂規硶涓嶅悓, 鑰屼紶鍏ョ殑Bill瀵硅薄鍙兘鏄袱縐嶄腑鐨勪換浣曚竴縐? 鎵浠ヨ鐢╥nstanceof鏉ュ垽鏂細
public double calculate(Bill bill){
if(bill instanceof PhoneBill){
//璁$畻鐢佃瘽甯愬崟
}
if(bill instanceof GasBill){
//璁$畻鐓ゆ皵甯愬崟
}
...
}
榪欐牱灝卞彲浠ョ敤涓涓柟娉曞鐞嗕袱縐嶅瓙綾?
鐒惰? 榪欑鍋氭硶閫氬父琚涓烘槸娌℃湁濂藉ソ鍒╃敤闈㈠悜瀵硅薄涓殑澶氭佹? 鍏跺疄涓婇潰鐨勫姛鑳借姹傜敤鏂規硶閲嶈澆瀹屽叏鍙互瀹炵幇, 榪欐槸闈㈠悜瀵硅薄緙栨垚搴旀湁鐨勫仛娉? 閬垮厤鍥炲埌緇撴瀯鍖栫紪紼嬫ā寮? 鍙湁鎻愪緵涓や釜鍚嶅瓧鍜岃繑鍥炲奸兘鐩稿悓, 鎺ュ彈鍙傛暟綾誨瀷涓嶅悓鐨勬柟娉曞氨鍙互浜?
public double calculate(PhoneBill bill){
//璁$畻鐢佃瘽甯愬崟
}
public double calculate(GasBill bill){
//璁$畻鐕冩皵甯愬崟
}
鎵浠? 浣跨敤instanceof鍦ㄧ粷澶у鏁版儏鍐典笅騫朵笉鏄帹鑽愮殑鍋氭硶, 搴斿綋濂藉ソ鍒╃敤澶氭?
]]>
PROCEDURE A(errbuf OUT VARCHAR2,
retcode OUT VARCHAR2,
p_1 IN VARCHAR2,
p_2 IN NUMBER);
end XXXX_X_XXX_PKG ;
娉細鍖呭ご涓0鏄庝竴涓狿rocedure, 鍖呬綋涓0鏄庝竴涓富Procedure(渚嬪: A),澶氫釜浠嶱rocedure(涓鑸槸浜涘叡鐢ㄦ柟娉?(渚嬪錛欱), 娉ㄦ剰鍖呬綋涓璓rocedure瀹炵幇嬈″簭錛屽簲鍏堝0鏄嶣 ,
鍦ˋ榪囩▼閲岋紝鍙互璋冪敤B.
鏂規硶浜?
鍖呭ご:
create or replace package XXXX_X_XXX_PKG is
PROCEDURE A(errbuf OUT VARCHAR2,
retcode OUT VARCHAR2,
p_1 IN VARCHAR2,
p_2 IN NUMBER);
PROCEDURE B( retcode OUT VARCHAR2,
p_1 IN VARCHAR2,);
end XXXX_X_XXX_PKG ;
鍖呬綋涓?姝ゆ椂A鍙互鐩存帴寮曠敤B,涓嶈瀹炵幇嬈″簭.
begin
BEGIN
SELECT attribute5
INTO l_list_name
FROM qp_list_headers_all
WHERE list_header_id = p_list_header_id ;
exception
when others then
raise targetListNameError;
end;
exception
WHEN targetListNameError THEN
-- fnd_file.put_line(fnd_file.output , rpad(upload_list.item_number,20,' ')
-- ||'Start date should later than the current latest effective start data of the target price list.'); --姝や俊鎭緭鍑哄埌EBS騫沖彴涓璙iew Output涓俧nd_file.log: 杈撳嚭鍒癓og涓?br> dbms_output.put_line('Target List is Null!'); --娉ㄦ剰: 姝や俊鎭敤浜庤緭鍑哄埌PL/SQL Developer鎺у埗鍙頒腑銆?br>END;
for (int j = 0; j < size; j++) {
if (!line[j].getNewRecord() && !line[j+1].getNewRecord()) {
if (line[j].getBoxQuantity() == 0L) {
line[j].setBoxQuantity(null);
}
if (line[j].getMiniQuantity() == 0L) {
line[j].setMiniQuantity(null);
}
if (line[j].getQuantity() == 0D) {
line[j].setQuantity(null);
}
rowList.add(line[j]);
}
if (j == rowId && !line[j].getNewRecord()) {
CreateDeliveryLineRow row = new CreateDeliveryLineRow();
BeanUtils.copyProperties(row,line[j]);
row.setQuantity(null);
row.setMfgLot(null);
row.setMiniQuantity(null);
row.setBoxQuantity(null);
rowList.add(row);
//rowList.add(cdr);
}
}
}
聽<welcome-file-list>
聽聽聽 <welcome-file>search.jsp</welcome-file>
聽</welcome-file-list>
2.dwr.xml
聽<dwr>
聽聽聽 <allow><convert convert="bean"聽 match="dwr.sample.Apartment"/>
聽聽聽 <create>
聽聽聽聽聽聽聽聽聽聽 <creator="new" javascript="ApartmentDAO" class="dwr.sample.ApartmentDAO">
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <include method="findApartments"/>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 <include method="countApartments"/>
聽聽聽聽聽聽聽聽聽聽 </creator>
聽聽聽 </create>
聽聽聽 </allow>
</dwr>
3.DB
CREATE TABLE APARTMENTS (id INTEGER, bedrooms INTEGER, bathrooms INTEGER, price INTEGER, address VARCHAR, city VARCHAR, province VARCHAR);
INSERT INTO APARTMENTS VALUES (16001, 1, 1, 850, '123 King St. East', 'Toronto', 'ON');
INSERT INTO APARTMENTS VALUES (16002, 2, 1, 1000, '1023 Yonge Ave.', 'Toronto', 'ON');
INSERT INTO APARTMENTS VALUES (16003, 2, 2, 1050, '27 Winchester St.', 'Toronto', 'ON');
4.Apertment.java
鏅氱殑javabean
5.DBUtils.java
聽聽聽鏁版嵁搴撻摼鎺ョ被
聽聽 public class DBUtils {
聽/*
聽 * Creates the sample data (table and records).
聽 */
聽public static void setupDatabase(BufferedReader reader) {
聽聽Connection c = null;
聽聽Statement stmt = null;
聽聽try {
聽聽聽c = openConnection();
聽聽聽stmt = c.createStatement();
聽聽聽// reads the file with the SQL statements
聽聽聽String line;
聽聽聽while ((line = reader.readLine()) != null) {
聽聽聽聽stmt.execute(line);
聽聽聽}
聽聽聽stmt.close();
聽聽聽c.close();
聽聽} catch (IOException e) {
聽聽聽e.printStackTrace();
聽聽} catch (SQLException e) {
聽聽聽e.printStackTrace();
聽聽} finally {
聽聽聽try {
聽聽聽聽stmt.close();
聽聽聽聽c.close();
聽聽聽} catch (SQLException e) {
聽聽聽聽e.printStackTrace();
聽聽聽}
聽聽}
聽}
聽
聽/*
聽 * Opens a database connection.
聽 */
聽public static Connection openConnection() throws SQLException {
聽聽Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:dwr-sample", "sa", "");
聽聽return c;
聽}
聽
}
6.ContextListener.java
聽聽 瀹炵幇浜哠ervletContextListerer鎺ュ彛鐨勭被
聽聽 public class ContextListener implements javax.servlet.ServletContextListener {
聽/**
聽 * This method is invoked when the Web Application has been removed and is
聽 * no longer able to accept requests.
聽 * @param event
聽 */
聽public void contextDestroyed(ServletContextEvent event) {
聽}
聽/**
聽 * This method is invoked when the Web Application is ready to service requests.
聽 * @param event
聽 */
聽public void contextInitialized(ServletContextEvent event) {
聽聽try {
聽聽聽// load the driver
聽聽聽Class.forName("org.hsqldb.jdbcDriver");
聽聽聽// create the table and add sample data
聽聽聽InputStreamReader in = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("db.sql"));
聽聽聽BufferedReader reader = new BufferedReader(in);
聽聽聽DBUtils.setupDatabase(reader);
聽聽} catch (ClassNotFoundException e) {
聽聽聽e.printStackTrace();
聽聽}
聽聽
聽}
}
7.ApartmentDAO.java
聽聽 涓氬姟閫昏緫灞?br />聽聽 public class ApartmentDAO {
聽
聽/**
聽 * Returns the available apartments based on the search criteria.
聽 * @param bedrooms minimum number of bedrooms
聽 * @param bathrooms minimum number of bathrooms
聽 * @param price maximum price to be paid
聽 * @return
聽 */
聽public Collection findApartments(int bedrooms, int bathrooms, int price) {
聽聽Collection list = new Vector();
聽聽String sql = "select * from APARTMENTS" +
聽聽聽聽createSearchWhereClause(bedrooms, bathrooms, price) +
聽聽聽聽"order by bedrooms, bathrooms, price";
聽聽// define db variables
聽聽Connection c = null;
聽聽Statement stmt = null;
聽聽try {
聽聽聽c = DBUtils.openConnection();
聽聽聽stmt = c.createStatement();
聽聽聽// just run the sql statement
聽聽聽ResultSet rs = stmt.executeQuery(sql);
聽聽聽while(rs.next()) {
聽聽聽聽Apartment apartment = this.getApartment(rs);
聽聽聽聽list.add(apartment);
聽聽聽}
聽聽} catch (SQLException e) {
聽聽聽e.printStackTrace();
聽聽} finally {
聽聽聽try {
聽聽聽聽stmt.close();
聽聽聽聽c.close();
聽聽聽} catch (SQLException e) {
聽聽聽聽e.printStackTrace();
聽聽聽}
聽聽}
聽聽return list;
聽}
聽
聽/**
聽 * Returns the number of available apartments based on the search criteria.
聽 * @param bedrooms minimum number of bedrooms
聽 * @param bathrooms minimum number of bathrooms
聽 * @param price maximum price to be paid
聽 * @return
聽 */
聽public int countApartments(int bedrooms, int bathrooms, int price) {
聽聽String sql = "select count(*) as total from APARTMENTS" + createSearchWhereClause(bedrooms, bathrooms, price);
聽聽int numberApartments = -1;
聽聽// define db variables
聽聽Connection c = null;
聽聽Statement stmt = null;
聽聽try {
聽聽聽c = DBUtils.openConnection();
聽聽聽stmt = c.createStatement();
聽聽聽// just run the sql statement
聽聽聽ResultSet rs = stmt.executeQuery(sql);
聽聽聽if (rs.next()) {
聽聽聽聽numberApartments = rs.getInt("total");
聽聽聽}
聽聽} catch (SQLException e) {
聽聽聽e.printStackTrace();
聽聽} finally {
聽聽聽try {
聽聽聽聽stmt.close();
聽聽聽聽c.close();
聽聽聽} catch (SQLException e) {
聽聽聽聽e.printStackTrace();
聽聽聽}
聽聽}
聽聽
聽聽return numberApartments;
聽}
聽
聽/**
聽 * Creates a Unit object from the database.
聽 * @param rs
聽 * @return
聽 * @throws SQLException
聽 */
聽private Apartment getApartment(ResultSet rs) throws SQLException {
聽聽Apartment ap = new Apartment();
聽聽ap.setId(rs.getInt("id"));
聽聽ap.setAddress(rs.getString("address"));
聽聽ap.setBedrooms(rs.getInt("bedrooms"));
聽聽ap.setBathrooms(rs.getInt("bathrooms"));
聽聽ap.setPrice(rs.getInt("price"));
聽聽ap.setCity(rs.getString("city"));
聽聽ap.setProvince(rs.getString("province"));
聽聽return ap;
聽}
聽
聽
聽/**
聽 * Creates the where clause for the search SQL statement.
聽 * @param bedrooms
聽 * @param bathrooms
聽 * @param price
聽 * @return
聽 */
聽private String createSearchWhereClause(int bedrooms, int bathrooms, int price) {
聽聽String where = " where bedrooms >= " + bedrooms +
聽聽聽聽" and bathrooms >= " + bathrooms +
聽聽聽聽" and price < " + price;
聽聽return where;
聽}
}
8. search.jsp
聽 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
聽 <title>DWR Example</title>
聽聽 <style type="text/css" media="screen">
聽聽聽聽聽聽 @import url( style.css );
聽聽 </style>聽
聽
聽 <script src='dwr/interface/ApartmentDAO.js'></script>
聽 <script src='dwr/engine.js'></script>
聽 <script src='dwr/util.js'></script>
聽 <script>
聽
聽 function updateTotal() {
聽聽聽 $("resultTable").style.display = 'none';
聽聽聽 var bedrooms = document.getElementById("bedrooms").value;
聽聽聽 var bathrooms = document.getElementById("bathrooms").value;
聽聽聽 var price = document.getElementById("price").value;
聽聽聽 ApartmentDAO.countApartments(loadTotal, bedrooms, bathrooms, price);
聽 }
聽 function updateResults() {
聽聽聽 DWRUtil.removeAllRows("apartmentsbody");
聽聽聽 var bedrooms = document.getElementById("bedrooms").value;
聽聽聽 var bathrooms = document.getElementById("bathrooms").value;
聽聽聽 var price = document.getElementById("price").value;
聽聽聽 ApartmentDAO.findApartments(fillTable, bedrooms, bathrooms, price);
聽聽聽 $("resultTable").style.display = '';
聽 }
聽
聽 var getId = function(unit) { return unit.id };
聽 var getAddress = function(unit) { return unit.address };
聽 var getBedrooms = function(unit) { return unit.bedrooms };
聽 var getBathrooms = function(unit) { return unit.bathrooms };
聽 var getPrice = function(unit) { return unit.price };
聽聽聽
聽 function loadTotal(data) {
聽聽聽 document.getElementById("totalRecords").innerHTML = data;
聽 }
聽
聽 function fillTable(apartment) {
聽聽聽 DWRUtil.addRows("apartmentsbody", apartment, [ getId, getAddress, getBedrooms, getBathrooms, getPrice ]);
聽 }
聽
</script>
</head>
<body onload="updateTotal();">
<h2>Find an apartment to rent</h2>
<table border="0">
<form name="rentalForm">
聽 <tr width="400">
聽聽 <td width="100">City</td>
聽聽 <td width="300">Toronto</td>
聽 </tr>
聽 <tr>
聽聽 <td>Beds</td>
聽聽 <td>
聽聽聽 <select id="bedrooms" onchange="updateTotal()">
聽聽聽聽 <option value="1">1 or more</option>
聽聽聽聽 <option value="2">2 or more</option>
聽聽聽聽 <option value="3">3 or more</option>
聽聽聽聽 <option value="4">4 or more</option>
聽聽聽 </select>
聽聽 </td>
聽 </tr>
聽 <tr>
聽聽 <td>Baths</td>
聽聽 <td>
聽聽聽 <select id="bathrooms" onchange="updateTotal()">
聽聽聽聽 <option value="1">1 or more</option>
聽聽聽聽 <option value="2">2 or more</option>
聽聽聽聽 <option value="3">3 or more</option>
聽聽聽聽 <option value="4">4 or more</option>
聽聽聽 </select>
聽聽 </td>
聽 </tr>
聽 <tr>
聽聽 <td>Price</td>
聽聽 <td>
聽聽聽 <select id="price" onchange="updateTotal()">
聽聽聽聽 <option value="800">under $800</option>
聽聽聽聽 <option value="1000">under $1,000</option>
聽聽聽聽 <option value="1250">under $1,250</option>
聽聽聽聽 <option value="1500" selected="selected">under $1,500</option>
聽聽聽聽 <option value="1800">under $1,800</option>
聽聽聽聽 <option value="2000">under $2,000</option>
聽聽聽 </select>
聽聽 </td>
聽 </tr>
聽 <tr>
聽聽 <td colspan="2">
聽聽聽 <blockquote>
聽聽聽聽 Available apartments: <span id="totalRecords" style="font-weight:bold;"></span>
聽聽聽 </blockquote>
聽聽 </td>
聽 </tr>
</form>
</table>
<p><input type="button" value="Show results!" onClick="updateResults();"></p>
<div id="resultTable">
<h2>Results</h2>
聽<table border="1">
聽 <thead>
聽聽聽 <tr>
聽聽聽聽聽 <th width="40">Id</th>
聽聽聽聽聽 <th width="180">Address</th>
聽聽聽聽聽 <th width="60">Beds</th>
聽聽聽聽聽 <th width="60">Baths</th>
聽聽聽聽聽 <th width="60">Price</th>
聽聽聽 </tr>
聽 </thead>
聽 <tbody id="apartmentsbody">
聽 </tbody>
聽</table>
</div>
</body>
</html>
鐢變簬欏圭洰闇瑕?闇鍦ㄦ垜浠幇鏈夌殑struts銆乭ibernate宸ョ▼涓婇泦鎴恆jax鍔熻兘.欏圭洰緇勫喅瀹氫嬌鐢―wr.
鍒氬紑濮嬬爺絀禗wr.瑙夊緱鐪熺殑寰堜笉閿? 鍙渶寰堝皯閲忕殑浠g爜,灝辮兘鍦ㄧ幇鏈夌殑宸ョ▼涓婇泦鎴恆jax鎶鏈? 鏈熷緟Dwr鏈夋洿杈夌厡鐨勬槑澶╋紒
鍠滄Dwr鎶鏈殑IT鐣屾湅鍙嬪彲浠ヤ笌鏈漢鑱旂郴錛佹湜鎻愬嚭濂界殑鎰忚涓庡緩璁?