SpringMVC和Mybatis整合中出现“Available parameters are [arg1, arg0, param1, param2]”解决方案

原因:接口中传入了多个参数如:

接口:fusePlanCaseEntities=planInter.selectPlanCaseInfoByPlanId(planId,sSearch);//获取用例返回结果集

映射:@RequestParam(value="planId",required=false) int planId,HttpServletRequest request)

mybatis映射xml: <resultMap id="PlanCaseResultMap" type="**.FusePlanCaseEntity">
           <id column="id" property="id" jdbcType="INTEGER" />
           <result column="planId" property="planId" jdbcType="INTEGER"/>
           <result column="projectName" property="projectName" jdbcType="VARCHAR"/>
           <result column="planCaseDec" property="planCaseDec" jdbcType="VARCHAR"/>
           <result column="sfSendMail" property="sfSendMail" jdbcType="VARCHAR"/>
           <result column="creater" property="creater" jdbcType="VARCHAR"/>
           <result column="planCase" property="planCase" jdbcType="VARCHAR"/>
      </resultMap>
      <sql id="PlanCase_List">
           id,planId,projectName,planCaseDec,sfSendMail,creater,planCase
      </sql>
      <select id="selectPlanCaseInfoByPlanId" parameterType="java.lang.Integer" resultMap="PlanCaseResultMap">
           select <include refid="PlanCase_List"/>
           from tfci_fuseplan_case where planId= #{planId}
      </select>

解决方案:

方法一:使用#{arg0}和#{arg1}确认使用哪个参数的值

  <select id="selectPlanCaseInfoByPlanId" parameterType="java.lang.Integer" resultMap="PlanCaseResultMap">
           select <include refid="PlanCase_List"/>
           from tfci_fuseplan_case where planId= #{arg0}
      </select>

补充说明:接口存在多个参数,但是业务需求只需映射一个planId,这时只需要通过尝试使用#{arg0}、或者#{arg1}代替#{planId},最终成功获取期望值

好的,以下是一个简单的工具类实现,使用了SpringMVC+MyBatis框架。 首先,在SpringMVC的配置文件中添加MyBatis的配置: ``` <!-- MyBatis配置 --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/test" /> <property name="username" value="root" /> <property name="password" value="root" /> </bean> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:mybatis-config.xml" /> </bean> <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate"> <constructor-arg index="0" ref="sqlSessionFactory" /> </bean> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.example.mapper" /> </bean> ``` 其中,`dataSource`是数据库连接信息,`sqlSessionFactory`是MyBatis的SessionFactory,`sqlSession`是MyBatis的SqlSessionTemplate,`MapperScannerConfigurer`是MyBatis的Mapper扫描器,用于自动扫描Mapper接口并生成实现类。 接着,创建一个图片工具类`ImageUtil`,其中包含两个方法:`saveImage`用于保存图片到本地文件夹并返回图片路径,`saveImagePath`用于将图片路径保存到数据库中。 ``` public class ImageUtil { // 保存图片到本地文件夹并返回图片路径 public static String saveImage(MultipartFile file, String filePath) throws IOException { File f = new File(filePath); if (!f.exists()) { f.mkdirs(); } String fileName = UUID.randomUUID().toString() + "." + file.getOriginalFilename().split("\\.")[1]; File newFile = new File(filePath + File.separator + fileName); file.transferTo(newFile); return newFile.getAbsolutePath(); } // 将图片路径保存到数据库中 public static void saveImagePath(String imagePath, int id, SqlSession sqlSession) { ImageMapper imageMapper = sqlSession.getMapper(ImageMapper.class); imageMapper.saveImagePath(imagePath, id); } } ``` 其中,`saveImage`方法接收一个`MultipartFile`类型的文件一个文件夹路径,通过`UUID.randomUUID().toString()`文件后缀名生成一个新的文件名,将文件保存到指定的文件夹下,并返回保存后的文件路径。`saveImagePath`方法接收一个图片路径、一个id一个SqlSession对象,通过MyBatis的Mapper将图片路径保存到数据库中。 最后,创建一个Mapper接口`ImageMapper`,用于定义保存图片路径的方法。 ``` public interface ImageMapper { void saveImagePath(@Param("imagePath") String imagePath, @Param("id") int id); } ``` 这个Mapper接口只有一个方法`saveImagePath`,用于将图片路径保存到数据库中。 以上就是将图片存在本地文件夹,图片路径存在MySQL的项目工具类的实现。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值