文章目录
MySQL中获取当前时间的函数 now()
select now()
MyBatis中查询时间,却显示成时间戳,要求会显示为字符串的问题
可以使用 DATE_FORMAT(datetime,'%Y-%m-%d %H:%i:%s')
来解决
SELECT DATE_FORMAT(download_time,'%Y-%m-%d %H:%i:%s') download_time FROM download_record
SpringMvc @ResponseBody字符串中文乱码原因及解决方案
- 使用xml配置消息转换器,指定响应的字符集为utf-8
<mvc:annotation-driven conversion-service="conversionService">
<mvc:message-converters register-defaults="true">
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="defaultCharset" value="UTF-8"/>
<property name="writeAcceptCharset" value="false"/>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
- 使用注解,指定响应的字符集为utf-8
@RequestMapping(value = "/demo1",produces = {"text/plain;charset=utf-8","text/html;charset=utf-8"})
@ResponseBody
public String demo1(){
return "我是中文测试";
}
- 使用注解,使结果转为JSON返回客户端
@RequestMapping(value = "/demo1",produces = {"application/json;charset=utf-8"})
@ResponseBody
public String demo1() throws JsonProcessingException {
return new ObjectMapper().writeValueAsString("我是中文测试");
}
java中cookie存取值
Cookie userCookie=new Cookie("loginInfo",loginInfo);
userCookie.setMaxAge(30*24*60*60); //存活期为一个月 30*24*60*60
userCookie.setPath("/"); //设置保存的路径
response.addCookie(userCookie);
Cookie[] cookies = request.getCookies();
for(Cookie cookie : cookies){
if(cookie.getName().equals("loginInfo")){
String loginInfo = cookie.getValue();
String username = loginInfo.split(",")[0];
String password = loginInfo.split(",")[1];
request.setAttribute("username", username);
request.setAttribute("password", password);
}
}