我有一种情况,我想将数组列表传递给控制器我附加我的控制器和下面的java代码请给我一个想法或建议去做 模型类......
stdClass Object
(
[success] => 1
[pagename] => RC1_PGR_Questions
[result] => stdClass Object
(
[CurrentInsuranceStatus] => stdClass Object
(
[QuestionData] => stdClass Object
(
[_answer] =>
[_answerOptions] => Array
(
[0] => stdClass Object
(
[_answerKey] => 340280
[_hideAnswer] => 1
[_order] => 110
[_promptText] => Yes
[_value] => Y
[_errorLog] => Array
(
)
)
[1] => stdClass Object
(
[_answerKey] => 340290
[_hideAnswer] =>
[_order] => 120
[_promptText] => Yes, on parent's policy
[_value] => Parents
[_errorLog] => Array
(
)
)
[2] => stdClass Object
(
[_answerKey] => 340300
[_hideAnswer] =>
[_order] => 130
[_promptText] => Yes, insured through employer
[_value] => Company
[_errorLog] => Array
(
)
)
[3] => stdClass Object
(
[_answerKey] => 340310
[_hideAnswer] =>
[_order] => 140
[_promptText] => No, policy lapsed/expired
[_value] => Lapsed
[_errorLog] => Array
(
)
)
[4] => stdClass Object
(
[_answerKey] => 340320
[_hideAnswer] =>
[_order] => 150
[_promptText] => No, never been insured
[_value] => Never
[_errorLog] => Array
(
)
)
[5] => stdClass Object
(
[_answerKey] => 340330
[_hideAnswer] =>
[_order] => 160
[_promptText] => No, I didn't have a vehicle to insure
[_value] => First
[_errorLog] => Array
(
)
)
[6] => stdClass Object
(
[_answerKey] => 340340
[_hideAnswer] =>
[_order] => 170
[_promptText] => No, been deployed/overseas in the military
[_value] => Military
[_errorLog] => Array
(
)
)
[7] => stdClass Object
(
[_answerKey] => 340350
[_hideAnswer] =>
[_order] => 180
[_promptText] => No, other reason
[_value] => Other
[_errorLog] => Array
(
)
)
)
[_answersDivID] => html_CurrentInsuranceStatus
[_phoneAreaField] =>
[_attributeName] => CurrentInsuranceStatus
[_criteriaBasedQuestion] => 1
[_dateField] =>
[_eventHandler] =>
[_fieldType] => select
[_hideQuestion] => 1
[_monthField] =>
[_phoneNumberField] =>
[_order] => 10000
[_pageAttributes] => stdClass Object
(
[additionalLabel] =>
[answerStyle] =>
[colNum] =>
[colWidth] =>
[cssclass] =>
[defaultValue] =>
[isMultiSelect] =>
[maxLength] =>
[min] =>
[questionSkinStyle] =>
[toolTip] =>
)
[_phonePreFixField] =>
[_questionDivID] => prompt_CurrentInsuranceStatus
[_questionKey] => 7169010
[_required] => 1
[_text] => Current insurance status
[_yearField] =>
[_errorLog] => Array
(
)
)
)
)
)
这是创建列表的java类..
#include <Servo.h>;
Servo servo;
void setup () {
servo.attach(9);
servo.write(0);
Serial.begin(9600);
}
int seconds = millis()/1000;
int degs = 0;
int time = 0;
int runs = 0
void loop() {
// put your main code here, to run repeatedly:
seconds = millis();
while(time <= 28) {
Serial.write(seconds);
degs = map(time, 0, 29, 0, 179);
servo.write(degs);
delay(1000);
}
runs = runs + 1;
time = seconds * (runs*29)
servo.write(0);
time = 0;
}
控制器
public class Rules {
String id;
String details;
String parameter;
String value;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getDetails() {
return details;
}
public void setDetails(String details) {
this.details = details;
}
public String getParameter() {
return parameter;
}
public void setParameter(String parameter) {
this.parameter = parameter;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public Rules(){}
public Rules(String id,String details,String parameter, String value){
this.id=id;
this.details=details;
this.value=value;
this.parameter=parameter;
}
我需要帮助才能做到,请帮助我, 谢谢....
答案 0 :(得分:0)
使用类似的json:
model.addAttribute("listRule1", new JSONArray().addAll(obj1.addRule()));
修改强> 你可以通过在你的情况下传递整个对象,你将传递CompArray对象,并在那里接收它只是调用你的函数,它将返回arraylist
import java.util.ArrayList;
import com.demo.Rules;
public class CompArray {
public ArrayList<Rules> a1= new ArrayList<Rules>();
public CompArray (){
Rules rul = new Rules();
rul.setId("1001");
rul.setDetails("khagfkj");
rul.setParameter("lsrkjglkrs");
rul.setValue("lskdjfk");
a1.add(rul);
}
public ArrayList<Rules> getRules(){
return a1;
}
}
和控制器
@RequestMapping(value = "/compplan", method = RequestMethod.GET)
public String listRules1(ModelMap model) {
CompArray obj1 = new CompArray();
model.addAttribute("listRule1", obj1);
return "hello";
}
答案 1 :(得分:0)
使用RestController :
尝试此操作@RestController = @Controller + @ResponseBody 所以会返回列表 以JSON格式
Log in to use your Facebook account with ** SOME APP**