Flex最近学了,但是感觉使用Flex与数据库交互,是可以互相传值调用,但是感觉都是同步的。我的按钮一按,他就响应。我传的也只是一个属性而已,也不是一个model。谁有可以传递一个对象的完整实例?学习!
下面这个不是完全懂,谁能给个完整的?
对于建立一个flex web应用的步骤我就不多说了哈。
首先要求大家到数据库建立一个数据库,在我这例子中数据库名为userDb,建立一个表userInfo,里面设置两个字段一个为id,一个为name.第二,创建以下java代码在src目录下
User.java
package org.rjb.java;
public class User {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this .name = name;
}
}
UserDao.java
package org.rjb.java;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
public class UserDao {
public static Connection getConnection() {
Connection c = null ;
try {
String driver = " com.mysql.jdbc.Driver " ;
String url = " jdbc:mysql://localhost:3306/userDb " ;
String username = " root " ;
String password = " 1235 " ;
Class.forName(driver);
c = DriverManager.getConnection(url,username,password) ;
} catch (Exception e) {
System.out.println(e.getMessage());
}
return c;
}
public List getAllUser() throws SQLException {
Connection c = getConnection();
Statement st = c.createStatement();
ResultSet rs = st.executeQuery( " select * from UserInfo " );
ArrayList userList = new ArrayList ();
while (rs.next()) {
User u = new User();
u.setName(rs.getString( " name " ));
userList.add(u);
}
return userList;
}
}
以上是java端的全部代码了,下面是flex端的代码。
第三,创建以下代码在flex_src下:
User.as
package org.rjb.flex
{
[RemoteClass(alias = " org.rjb.java.User " )]
public class User
{
private var _name:String;
public function User()
{
}
public function get name():String {
return this ._name;
}
public function set name(name:String): void {
this ._name = name;
}
}
}
User.as
package org.rjb.flex
{
[RemoteClass(alias = " org.rjb.java.User " )]
public class User
{
private var _name:String;
public function User()
{
}
public function get name():String {
return this ._name;
}
public function set name(name:String): void {
this ._name = name;
}
}
}
接下来是mxml代码,也就是我们真正展示我们数据的界面
FlexWithJava .mxml
第四,配置remoting-config.xml,在里面加上如下配置文件:
source > org.rjb.java.UserDao source >
下面这个不是完全懂,谁能给个完整的?
对于建立一个flex web应用的步骤我就不多说了哈。
首先要求大家到数据库建立一个数据库,在我这例子中数据库名为userDb,建立一个表userInfo,里面设置两个字段一个为id,一个为name.第二,创建以下java代码在src目录下
User.java
package org.rjb.java;
public class User {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this .name = name;
}
}
UserDao.java
package org.rjb.java;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
public class UserDao {
public static Connection getConnection() {
Connection c = null ;
try {
String driver = " com.mysql.jdbc.Driver " ;
String url = " jdbc:mysql://localhost:3306/userDb " ;
String username = " root " ;
String password = " 1235 " ;
Class.forName(driver);
c = DriverManager.getConnection(url,username,password) ;
} catch (Exception e) {
System.out.println(e.getMessage());
}
return c;
}
public List getAllUser() throws SQLException {
Connection c = getConnection();
Statement st = c.createStatement();
ResultSet rs = st.executeQuery( " select * from UserInfo " );
ArrayList userList = new ArrayList ();
while (rs.next()) {
User u = new User();
u.setName(rs.getString( " name " ));
userList.add(u);
}
return userList;
}
}
以上是java端的全部代码了,下面是flex端的代码。
第三,创建以下代码在flex_src下:
User.as
package org.rjb.flex
{
[RemoteClass(alias = " org.rjb.java.User " )]
public class User
{
private var _name:String;
public function User()
{
}
public function get name():String {
return this ._name;
}
public function set name(name:String): void {
this ._name = name;
}
}
}
User.as
package org.rjb.flex
{
[RemoteClass(alias = " org.rjb.java.User " )]
public class User
{
private var _name:String;
public function User()
{
}
public function get name():String {
return this ._name;
}
public function set name(name:String): void {
this ._name = name;
}
}
}
接下来是mxml代码,也就是我们真正展示我们数据的界面
FlexWithJava .mxml
第四,配置remoting-config.xml,在里面加上如下配置文件:
source > org.rjb.java.UserDao source >