MyBatis 不封装对象获取数据库值的解决方案 思路:如果我们不想封装对象,使用 Map 来获得 SQL 查询的结果集是一个理想的方案。下面就是一个实现类示例。 List Map String , String listMap = ( List Map String , String ) this.getSqlMapClientTemplate().
MyBatis 不封装对象获取数据库值的解决方案
思路:如果我们不想封装对象,使用 Map 来获得 SQL 查询的结果集是一个理想的方案。下面就是一个实现类示例。
List Map String , String >> listMap = ( List Map String , String >>) this.getSqlMapClientTemplate().queryForList( "writingEssay.queryAssignmentErrorAndReminderByAssId" , assignment_id); String context = getEssayContextByJson(listMap.get( 0 ).get( "assignment_history_content" ), listMap.get( 0 ).get( "essay_set_format" ));
我们再来看看底层的 SQL 语句。
"queryAssignmentErrorAndReminderByAssId" resultClass= "java.util.HashMap" parameterClass= "java.lang.Integer" > SELECT a .assignment _history_content AS assignment_history_content, c .essay _set_format AS essay_set_format, d .essay _reminder AS essay_reminder FROM t_assignment_content a, t_assignment b, t_essay_set c, t_essay d WHERE b .assignment _history_id = a .assignment _history_id AND b .assignment _id = $assignment_id$ AND b .essay _id = d .essay _id AND d .essay _set_id = c .essay _set_id ;
查询数据库得到的结果集。
分析:因为我们明确地知道结果集返回一条数据。
下面的知识点和本小节无关。
if (StringUtils.isNotEmpty(reminder)) { for (String str : reminder.split( "#" )) { int flag = context.indexOf( str ); if (flag == - 1 ) { mapReminder.put( str , false ); } else { mapReminder.put( str , true ); } } }
查看更多关于MyBatis不封装对象获取数据库值的解决方案的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did159732