<!--配置之后,在加入了jackson的core和mapper包之后,不写配置文件也能自动转换成json)。 -->
<mvc:annotation-driven />
也就是
package cn.hufei.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.hufei.pojo.User;
import cn.hufei.service.UserService;
@Controller
public class UserController {
@Autowired
private UserService userService;
@RequestMapping("/welcome")
@ResponseBody
public User getUser(Model model) {
return userService.getUser();
}
}
可以直接返回对象而不需要转换成json