Spring Framework: различия между версиями
Содержимое удалено Содержимое добавлено
Moriline (обсуждение | вклад) Нет описания правки |
Moriline (обсуждение | вклад) Нет описания правки |
||
Строка 1542:
package app.controller;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.
▲import org.springframework.web.bind.annotation.ResponseBody;
@Controller
Строка 1553:
@RequestMapping(value="/list", method=RequestMethod.GET)
@ResponseBody
public
return "index";▼
List<UserObject> list = new ArrayList<UserObject>();
list.add(new UserObject(Long.valueOf(1), "one"));
list.add(new UserObject(Long.valueOf(2), "two"));
}
@RequestMapping(value="/", method=RequestMethod.GET)
public String help(){
Строка 1561 ⟶ 1566 :
}
@RequestMapping(value="
@ResponseBody
@ResponseStatus(HttpStatus.CREATED)
public UserObject add(@PathVariable String id){▼
public UserObject create(@RequestBody
entity.setId(new Long(1));
// add to somewhere
System.out.println("create");
return entity;
}
@RequestMapping(value="update", method=RequestMethod.PUT)
@ResponseStatus(HttpStatus.OK)
public final void update(@RequestBody final UserObject entity){
// update to somewhere
System.out.println("update");
@RequestMapping(value="delete/{id}", method=RequestMethod.DELETE)
@ResponseStatus(HttpStatus.OK)
public final void delete(@PathVariable final Long id){
// delete to somewhere
System.out.println("delete");
}
@RequestMapping(value="findbyid/{id}", method=RequestMethod.GET)
@ResponseBody
return new UserObject(id, "three");
}
}
</source>
Строка 1575 ⟶ 1604 :
public class UserObject {
private
private String name;
Строка 1582 ⟶ 1611 :
}
public UserObject(
▲ {
this.id = id;
this.name = name;
}
public
▲ {
return id;
}
public void setId(
▲ {
this.id = id;
}
public String getName()
Строка 1621 ⟶ 1647 :
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>
</head>
<body>
▲ <a href="add/5">add</a>
</body>
</html>
Строка 1639 ⟶ 1664 :
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>
</head>
<body>
<h1>Help</h1>
<a href="list">list</a>
<a href="delete/5">delete id = 5</a>
<a href="findbyid/5">find by id = 5</a>
</body>
</html>
|