Springmvc+mybatis 问题总结(续ing)

1、java.lang.IllegalStateException: getWriter() has already been called for this response

拦截器中相关代码
@Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
            Object arg2) throws Exception {
        response.setCharacterEncoding("UTF-8"); // 设置输出流格式为utf-8
        PrintWriter out = response.getWriter();  //获得输出流
    }

controller相关代码

@ResponseBody
    @RequestMapping(value="/back/updateadmin")
    public Json updateAdmin(UpdateAdmin admin,HttpServletResponse respose) {
        int result = 0;
        Json json = new Json();
        try {
            result = adminService.updateAdmin(admin);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if(result != 0) {
                json.setMsg("更新管理员操作成功");
                json.setSuccess(true);
            } else {
                json.setMsg("更新管理员失败");
                json.setSuccess(false);
            }
        }
        return json;    
    }

问题原因:
在拦截器中 获得了PrintWriter对象
而在Controller中@responseBody 返回json格式字符串时会自动调用getOutputStream方法。

解决方法:
在拦截器中加上
response.reset();即可

2.SELECT top(1) * FROM edition ORDER BY id DESC
在mysql 数据库下一直报
**You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘FROM edition
ORDER BY id DESC’ at line 1**

问题原因:
并不是所有的数据库都支持top子句

解决方法:
select * from edition order by id limit 1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值