我想创建一个函数,以编程方式在页面上添加一些元素.
假设我想添加一个包含四个选项的下拉列表:
<select name="drop1" id="Select1">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我有一张桌子.每个人都有财产,许多人可能拥有某些财产.所以这是一个多对多的关系.这是架构:
CREATE TABLE persons (
person_id int(11) NOT NULL AUTO_INCREMENT,
firstname varchar(30) NOT NULL,
lastname varchar(30) NOT NULL,
PRIMARY KEY (person_id)
);
CREATE TABLE properties (
property_id int(11) NOT NULL AUTO_INCREMENT,
property varchar(254) NOT NULL UNIQUE,
PRIMARY KEY (property_id)
);
CREATE TABLE has_property (
person_id int(11) NOT NULL,
property_id int(11) NOT NULL,
PRIMARY KEY (person_id,property_id),
FOREIGN KEY (person_id) REFERENCES persons (person_id),
FOREIGN KEY (property_id) REFERENCES properties (property_id)
);
Run Code Online (Sandbox Code Playgroud)
现在让我说我想向这个人插入数据库:
人
+-----------+-----------+----------+
| person_id | …Run Code Online (Sandbox Code Playgroud) 我想从一个地址获取一个地方的纬度和经度.我不想从GPS或网络中获得经度和纬度.
我希望用户能够在TextView中输入他想要的地址(例如他的办公室)和文本字段下方的一些建议,就像在Google地图应用中输入地址一样.然后我想检索给定地址的坐标.
如果无法做到这一点,有办法通过谷歌地图应用程序本身获取地址.也许我可以从我的应用程序调用gmaps,用户将键入地址,gmaps将返回坐标.
我该怎么做?
我的json序列化有问题ZonedDateTime.当转换为json时,它产生了一个巨大的对象,我不希望每次都传输所有这些数据.所以我尝试将其格式化为ISO,但它不起作用.我怎样才能让它格式化?
这是我的实体类:
@MappedSuperclass
public abstract class AuditBase {
@Id
@GeneratedValue
private Long id;
@CreatedDate
private ZonedDateTime createdDate;
@LastModifiedDate
private ZonedDateTime lastModifiedDate;
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
public ZonedDateTime getLastModifiedDate() {
return lastModifiedDate;
}
public void setLastModifiedDate(ZonedDateTime lastModifiedDate) {
this.lastModifiedDate = lastModifiedDate;
}
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
public ZonedDateTime getCreatedDate() {
return createdDate;
}
public void setCreatedDate(ZonedDateTime createdDate) {
this.createdDate = createdDate;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@PrePersist
public void …Run Code Online (Sandbox Code Playgroud) 如何以编程方式将边框添加到LinearLayout?让我们说我们创建这个布局:
LinearLayout TitleLayout = new LinearLayout(getApplicationContext());
TitleLayout.setOrientation(LinearLayout.HORIZONTAL);
Run Code Online (Sandbox Code Playgroud)
那我该怎么办?
我创建了一个显示字母表字母的gridview.我使用自定义BaseAdapter使用字符串数组填充gridview.
我想要做的是能够获得被点击的单元格的值(字母).为了验证它是否有效,我创建了一个TextView,我希望当用户点击一个项目(单元格)时,使用所选单元格的值设置TextView的文本
我做了一个不起作用的尝试.这是我的代码:
activity_main.xml中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:ignore="MergeRootFrame" >
<GridView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/myGridView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:numColumns="7" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/feedback"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
cell.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/grid_item"
android:layout_gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="05"
android:textSize="20sp"
android:enabled="true"
android:clickable="true">
</Button>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
主要活动
public class MainActivity extends Activity {
private TextView text;
private GridView gridView;
private final String[] items = new String[]{"A", "B", "C", "D", "E", "F", "G", "H", "I", …Run Code Online (Sandbox Code Playgroud) 我需要在页面加载时加载一些数据,然后执行任务.为了获得我想要的数据,我执行多个不同的ajax调用.但是为了执行任务,我需要所有人确保所有的ajax调用都已完成.这是我到目前为止所做的:
$q.when(
$http.get('url1').success(function (data) {
$scope.data1 = data;
console.log("ajax1 finished");
}),
$http.get('url2').success(function (data) {
$scope.data2 = data;
console.log("ajax2 finished");
}),
$http.get('url3').success(function (data) {
$scope.data3 = data;
console.log("ajax3 finished");
}),
$http.get('url4').success(function (data) {
$scope.data4 = data;
console.log("ajax4 finished");
})
).then(
console.log("All ajax calls have finished!"),
executeTask()
);
Run Code Online (Sandbox Code Playgroud)
我的问题是在所有 ajax调用完成后,块中的代码then(...);不会被执行.我在我的控制台中得到这样的东西:
ajax2 finished
ajax1 finished
All ajax calls have finished!
ajax3 finished
ajax4 finished
Run Code Online (Sandbox Code Playgroud)
我一定做错了什么.我怎样才能让它按照我想要的方式工作?
编辑:我尝试了以下,就像答案中提到的那样,但我仍然面临同样的问题.
$q.all([
$http.get('url1').then(function (data) {
$scope.data1 = data;
console.log("");
}),
$http.get('url2').success(function (data) …Run Code Online (Sandbox Code Playgroud) 我有两个实体,Company和Job,具有OneToMany双向关系.我的问题是我不能懒得加载公司的List<Job> jobs.
例如,当我这样做时:
获取/api/companies/1这是JSON响应:
{
"id": 1,
"name": "foo",
...
"_embedded": {
"jobs": [
{...},
...
{...}
],
"employees": [
{...},
{...}
]
},
"_links": {
"self": {
"href": "http://localhost:8080/api/companies/1"
},
"jobs": {
"href": "http://localhost:8080/api/companies/1/jobs"
},
"employees": {
"href": "http://localhost:8080/api/companies/1/employees"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我不想拥有,_embedded因为我没有设置FetchType = EAGER.这是我的模特:
Company.java
@Entity
public class Company {
@Column(nullable = false, unique = true)
private String name;
@OneToMany(mappedBy = "company", fetch = FetchType.LAZY)
private List<Job> jobs;
...
public Company() { …Run Code Online (Sandbox Code Playgroud) 我从用户那里得到了他在DatePickerDialog中设置的日期.我得到的日期是这种格式:
int selectedYear, int selectedMonth, int selectedDay
Run Code Online (Sandbox Code Playgroud)
我可以将它格式化为"Day,Month dd,yyyy",如下图所示吗?

我有一个发送HTTP POST请求的函数,我想记录它以进行调试.这是功能:
function serverRequest(URL, DATA, callback) {
$.ajax({
url: URL,
type: "POST",
dataType: "text",
contentType: "text/xml",
processData: false,
data: DATA,
success: function (response) {
console.log(response);
callback(response);
},
error: function (response) {
console.log(response);
callback(null);
}
});
}
Run Code Online (Sandbox Code Playgroud)
如何发送,我如何记录整个HTTP POST请求(HTTP标头+数据)?
谢谢.
android ×4
java ×3
javascript ×3
ajax ×2
spring ×2
angularjs ×1
baseadapter ×1
border ×1
coordinates ×1
date-format ×1
gridview ×1
html ×1
html-select ×1
httprequest ×1
jpa ×1
jquery ×1
json ×1
layout ×1
location ×1
logging ×1
many-to-many ×1
mysql ×1
relationship ×1
sql-insert ×1