大致流程是在mysql中新建一个存储过程然后
mapper.java定义方法的写法:
DELIMITER$
create PROCEDURE jysapp.get_second_member(IN user_id int)
BEGIN
SELECT id,username,phonenum,registertime,str1 FROM jysapp.user where user.pid = user_id;
end
mybatis中的mapper.xml配置
<select id="getsecondmember" parameterType="java.lang.Integer" statementType="CALLABLE" resultType="com.jys.po.User">
{call
get_second_member(
#{user_id,jdbcType=INTEGER,mode=IN}
)
}
</select>
mapper.java定义方法的写法:
List<User> getsecondmember(int user_id);
使用Junit测试整合Spring代码,直接注入mapper进行测试
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:/spring/applicationContext-*"})
public class Test {
@Autowired
UserMapper userMapper;
@org.junit.Test
public void test1() {
System.out.println(userMapper.getsecondmember(50).get(1));
}
}