spring mvc 相关
http://www.mkyong.com/spring-mvc/spring-3-mvc-and-json-example/
@RequestMapping(value = "test/user/json", method = RequestMethod.GET)
public @ResponseBody User getJson() {
return new User("name", "password", "login");
}
Jackson library is existed in the project classpath
2.The mvc:annotation-driven is enabled
Return method annotated with @ResponseBody
定义一个form.ftl宏,restful风格的uri中需要添加_method这个hidden input,内容分别为put(修改),delete(删除),post(新加) 如果用@s.formXXX Controller中必须有绑定的对象,在这个例子里必须有User 对象,可以new,可以传参。
<#macro userform action method="post" button_content="注册新用户" >
<form action=${action} method="post">
<input type="hidden" name="_method" value="${method}">
<#if method!='delete'>
<#import "/spring.ftl" as s />
<@s.formHiddenInput "user.uuser_id"/>
<@s.showErrors "<div>" />
登录名:
<@s.formInput "user.login_name" "class='loginText'"/>
<@s.showErrors "<div>" />
用户名:
<@s.formInput "user.user_name" />
<@s.showErrors "<div>" />
密码:
<@s.formPasswordInput "user.password"/>
<@s.showErrors "<div>" />
<button type="submit">${button_content}</button>
<#else>
<#nested>
</#if>
</form>
</#macro>
对应文件引用即可
新增post
<#import "form.ftl" as form/>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>
form
</title>
</head>
<body>
<div>
<@form.userform action="post" button_content="注册新用户"/>
</div>
</body>