您的位置:首页 > 其它

SSM项目重构时遇到的一些问题及解决方法

2017-10-19 09:54 561 查看
1.mybatis模糊查询,xml中的查询语句怎么写?

<select id="findSpecialControl" resultType="com.picc.ecargo.po.code.Smallgoodstype" parameterType="string">
select
<include refid="Base_Column_List" />
from smallgoodstype
where specialcontrolid like concat(concat('%',#{string}),'%')
</select>
我用的是oracle数据库,这么写就没问题了,网上有其他的方法,都可以试一下,不过我试过其他的,都不行,报了很多错。

2.批量查询(前台传来的数据中类似这样的:1,2,3,4)

前端:

前台传来的数据中类似这样的:1,2,3,4

controller:

将1,2,3,4这样的数据分割成字符串数组

service中:

public List<Smallgoodstype> findGoodsBytemp(String[] split) {
return smallgoodstypeDao.findSmallGoodsById(split);
}

xml中:
<select id="findSmallGoodsById" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from smallgoodstype
where goodstypeid in
<foreach item="item" index="index" collection="array" open="(" separator="," close=")">
#{item}
</foreach>
</select>
3.如何比较2个集合中不同的元素
这里的比较就是将不同的元素拿出来:
list1.removeAll(list2)
这时候,list1中的元素就是list1和list2中不同的元素了

4.遇到一个异常:Invalid bound statement (not found) 
这个异常后面会标记出是哪个类的问题。
出现这个异常的时候只要查看一下mybatis的配置文件就可以,我这里的配置文件是applicationContext-mybatis.xml这个文件,里面有这么行代码:
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 配置数据源 -->
<property name="dataSource" ref="dataSource"/>
<!-- 配置别名包路径 -->
<property name="typeAliasesPackage" value="com.picc.**.po;ins.**.po;com.picc.ecargo.**.po"/>
<!--常见问题-Invalid bound statement (not found) -->
<property name="mapperLocations" value="classpath*:mapper/**/**/*Dao.xml"/>
<!-- 配置Mybatis配置文件 -->
<property name="configLocation" value="classpath:mybatis-config.xml"/>
</bean>我的mapper下的dao里面有个方法被注释了,也就是没这个方法了,但是在其他类中被引用了,所以页面点击一些引用过该方法的类时会报404
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: