6 changed files with 95 additions and 7 deletions
@ -0,0 +1,46 @@ |
|||||
|
package app.bcms.jchat.web; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.boot.web.error.ErrorAttributeOptions; |
||||
|
import org.springframework.boot.web.servlet.error.ErrorAttributes; |
||||
|
import org.springframework.boot.web.servlet.error.ErrorController; |
||||
|
import org.springframework.http.MediaType; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
import org.springframework.web.context.request.ServletWebRequest; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletRequest; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 系统默认错误页面 |
||||
|
*/ |
||||
|
|
||||
|
@RestController |
||||
|
public class ChErrorController implements ErrorController { |
||||
|
|
||||
|
@Autowired |
||||
|
private ErrorAttributes errorAttributes; |
||||
|
|
||||
|
/** |
||||
|
* 默认错误 |
||||
|
*/ |
||||
|
private static final String path_default = "/error"; |
||||
|
|
||||
|
public String getErrorPath() { |
||||
|
return path_default; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* JSON格式错误信息 |
||||
|
*/ |
||||
|
@RequestMapping(value = path_default, produces = {MediaType.APPLICATION_JSON_VALUE}) |
||||
|
public JSONObject error(HttpServletRequest request) { |
||||
|
JSONObject jsonObject =new JSONObject(); |
||||
|
ServletWebRequest servletWebRequest = new ServletWebRequest(request); |
||||
|
jsonObject.put("errmsg",errorAttributes.getErrorAttributes(servletWebRequest, ErrorAttributeOptions.defaults())); |
||||
|
return jsonObject; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,38 @@ |
|||||
|
package app.bcms.jchat.web; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import org.springframework.stereotype.Controller; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.ResponseBody; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletRequest; |
||||
|
|
||||
|
/** |
||||
|
* 聊天 |
||||
|
*/ |
||||
|
@Controller |
||||
|
@RequestMapping("/v2") |
||||
|
public class ChatController { |
||||
|
/** |
||||
|
* 系统首页 |
||||
|
* @return |
||||
|
*/ |
||||
|
@RequestMapping("/chat") |
||||
|
@ResponseBody |
||||
|
public String home(HttpServletRequest request){ |
||||
|
//获取各种参数
|
||||
|
JSONObject json = new JSONObject(); |
||||
|
json.put("params",request.getParameterMap()); |
||||
|
// json.put("header",request.getHttpServletMapping());
|
||||
|
return json.toString(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 需要建立一个模版文件 |
||||
|
* @return |
||||
|
*/ |
||||
|
@RequestMapping("/test") |
||||
|
public String stest(){ |
||||
|
return "ok"; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,5 @@ |
|||||
|
<html> |
||||
|
<body> |
||||
|
<p>it's ok !!</p> |
||||
|
</body> |
||||
|
</html> |
||||
@ -1,6 +0,0 @@ |
|||||
<html> |
|
||||
<body> |
|
||||
<h1>hello word!!!</h1> |
|
||||
<p>this is a html page</p> |
|
||||
</body> |
|
||||
</html> |
|
||||
Loading…
Reference in new issue