In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you the "mybatis returns map type data null field does not show how to do", the content is easy to understand, clear, hope to help you solve the doubt, the following let Xiaobian lead you to study and learn "mybatis return map type data null field does not show how to do" this article.
Mybatis returns map data null field does not display query sql add each field judgment null IFNULL (rate,'') as rateResultType uses entity return
No need for map
SpringMVC+mybatis query data
When resultType= "map" is returned, if the data is an empty field, the field is omitted and not displayed. You can return null if the query data is empty by adding a configuration file.
Spring-mybatis.xml
If you want to configure the default value of rate, such as the "" string, you can set up a class that implements the TypeHandler interface of Mybatis
Public class EmptyStringIfNull implements TypeHandler {@ Override public String getResult (ResultSet rs, String columnName) throws SQLException {return (rs.getString (columnName) = = null)? ": rs.getString (columnName);} @ Override public String getResult (ResultSet rs, int columnIndex) throws SQLException {return (rs.getString (columnIndex) = null)?": rs.getString (columnIndex) @ Override public String getResult (CallableStatement cs, int columnIndex) throws SQLException {return (cs.getString (columnIndex) = = null)? "": cs.getString (columnIndex);} @ Override public void setParameter (PreparedStatement ps, int arg1, String str, JdbcType jdbcType) throws SQLException {}}
The definition and use in the sql.xml file are as follows
Mybatis returns map null field mybatis opens CallSettersOnNulls@Beanpublic SqlSessionFactory sqlSessionFactoryBean () throws Exception {SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean (); sqlSessionFactoryBean.setDataSource (dataSource ()); Configuration configuration = new .configuration (); configuration.setCallSettersOnNulls (true); / / map returns empty field disappearance problem PageInterceptor pagePlugin = new PageInterceptor (); JalorResultSetInterceptor jalorResultSetPlugin = new JalorResultSetInterceptor (); ProgramInterceptor programPlugin = new ProgramInterceptor () / / add the plug-in sqlSessionFactoryBean.setPlugins (new Interceptor [] {pagePlugin, jalorResultSetPlugin, programPlugin}); sqlSessionFactoryBean.setConfiguration (configuration); return sqlSessionFactoryBean.getObject ();} above is all the content of the article "what to do if the null value field of map type data returned by mybatis is not displayed?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.