Spring Framework: различия между версиями

Содержимое удалено Содержимое добавлено
Нет описания правки
Нет описания правки
Строка 1542:
package app.controller;
 
import java.util.ArrayList;
import java.util.List;
import org.springframework.webhttp.bind.annotation.ResponseBodyHttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
 
@Controller
Строка 1553:
@RequestMapping(value="/list", method=RequestMethod.GET)
@ResponseBody
public Stringfinal List<UserObject> list(){
return "index";
List<UserObject> list = new ArrayList<UserObject>();
list.add(new UserObject(Long.valueOf(1), "one"));
list.add(new UserObject(Long.valueOf(2), "two"));
return "index"list;
}
{
@RequestMapping(value="/", method=RequestMethod.GET)
public String help(){
Строка 1561 ⟶ 1566 :
}
@RequestMapping(value="add/{id}create", method=RequestMethod.GETPOST)
@ResponseBody
@ResponseStatus(HttpStatus.CREATED)
public UserObject add(@PathVariable String id){
public UserObject create(@RequestBody return newfinal UserObject(id, "Object " + id entity);{
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
public UserObject addfindByID(@PathVariable Stringfinal Long id){
return new UserObject(id, "three");
}
}
</source>
Строка 1575 ⟶ 1604 :
 
public class UserObject {
private StringLong id;
private String name;
 
Строка 1582 ⟶ 1611 :
}
 
public UserObject(StringLong id, String name) {
{
this.id = id;
this.name = name;
}
 
public StringLong getId() {
{
return id;
}
 
public void setId(StringLong id) {
{
this.id = id;
}
 
public String getName()
Строка 1621 ⟶ 1647 :
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>WelcomeUser to Spring Web MVC projectService</title>
</head>
 
<body>
<a href="add/5list">addlist</a>
<p>Hello! This is the default welcome page for a Spring Web MVC project.</p>
<a href="add/5">add</a>
</body>
</html>
Строка 1639 ⟶ 1664 :
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSPUser PageService</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>