实现通过指定id查询

main
郝辰余 1 week ago
parent 40cdb858af
commit a7e7fc88ee

@ -1,5 +1,6 @@
package com.ssm.mapper;
import com.ssm.entity.Budget;
import com.ssm.entity.Dict;
import java.util.List;
@ -16,4 +17,5 @@ public interface DictMapper {
Dict getDictById(Integer dictId);
List<Dict> listDict(String dictType);
Dict selectDictById(Integer dictId);
}

@ -53,5 +53,9 @@
FROM dict
WHERE is_valid = 'Y'
</select>
<!-- 查询指定id-->
<select id="selectDictById" parameterType="int" resultType="com.ssm.entity.Dict">
SELECT * FROM dict WHERE dict_id = #{dictId}
</select>
</mapper>

@ -19,6 +19,8 @@ public class DictTest {
// 2. 按类型查询字典项(可选,和你的业务匹配)
// testGetDictsByType();
//3.按id查询
testGetDictById();
}
@ -58,6 +60,22 @@ public class DictTest {
System.out.println(dict);
}
session.close();
}
//按id查询
private static void testGetDictById() throws IOException {
Reader reader = Resources.getResourceAsReader("config.xml");
SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader);
SqlSession session = factory.openSession();
DictMapper mapper = session.getMapper(DictMapper.class);
// 查询 id = 1 的预算
Dict dict = mapper.selectDictById(1);
System.out.println("\n===== 根据ID查询预算 =====");
System.out.println(dict);
session.close();
}
}

Loading…
Cancel
Save