记录日常

 <!--配置之后,在加入了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

发布了28 篇原创文章 · 获赞 7 · 访问量 8601

猜你喜欢

转载自blog.csdn.net/qq_35953966/article/details/95407712
今日推荐