Spring+MyBatis问题集锦2

来源:互联网 发布:php 返回页面 编辑:程序博客网 时间:2024/05/29 13:36
上传文件的时候出现以下这个异常:
HTTP Status 400
The request sent by the client was syntactically incorrect.
解决方法为:由于上传文件方式使用的是仿表单提交,所以请求参数为:
method="post" enctype="multipart/form-data"
通过这种方式提交的参数只能是字符串类型,只要接收参数中有其他类型的参数就会报如此错误,
因此,解决办法为,把接收参数不是字符串类型都转为字符串类型,接收到参数之后再进行转换


Mybatis使用Map传入多参数
Map<?,?> map=new HashMap<?,?>();
map.put("cId","xxx");
map.put("meet","xxx");
注意在test中获取参数的方式,是不需要使用井号(#)来获取


Mybatis使用注解传入多个参数:
List<MeetFile> selectByCmpId(@Param("cId")String cId,@Param("meet")boolean isMeet);
使用方式和使用Map传入多个参数一样


Mybatis读取Map中的布尔值时,true为1,false为0




2、更新数据库(用户表)
update tbl_user set deptName=(select deptName from tbl_dept where deptId='4ea23cda-b168-471e-aab7-bd4413a47015') where deptId='4ea23cda-b168-471e-aab7-bd4413a47015';
update tbl_user set cId=(select cId from tbl_dept where deptId='4ea23cda-b168-471e-aab7-bd4413a47015') where deptId='4ea23cda-b168-471e-aab7-bd4413a47015';


//获取SpringMVC的上下文ApplicationContext
1、先在web.xml中配置上下文参数
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-web.xml</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>spring_mvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-web.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>spring_mvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

2、获取方式
ApplicationContext context = WebApplicationContextUtils
.getRequiredWebApplicationContext(request.getServletContext());


android 对apk进行命令行打包

//创建签名,生成签名文件
keytool -genkey -v -keystore stone.keystore -alias stone -keyalg RSA -keysize 2048-validity 10000
//为apk签名 stone是别名,不生成新文件
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore stone.keystore unsigned.apk stone
//检测apk是否签名
jarsigner -verbose -certs -verify signed.apk
//优化apk
zipalign -f -v 4 signed_unaligned.apk signed_aligned.apk

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore xz.mk.jks app-release-unsign.apk stone

Spring自定义异常处理
1、实现HandlerExceptionResolver接口
在resolveException方法中实现各种异常的处理

2、spring-x.xml的配置中添加bean实例
<bean id="handlerExceptionResolver" class="com.dazzle.meet.resolver.ExceptionResolver" />

3、在web.xml中Servlet,DispatcherServlet的初始化中,禁用默认的异常处理
<init-param>
<param-name>detectAllHandlerExceptionResolvers</param-name>
<param-value>false</param-value>
</init-param>
原创粉丝点击