电信AP外置型Gpon上行家庭网关e8-c家庭网关(2+1) 插上电脑后显示网络访问受限

最近使用spring boot+mybatis,使用IntelliJ IDEA开发,记录一些问题的解决方法。
1、在使用@Mapper注解方式代替XXmapper.xml配置文件,使用@Select等注解配置sql语句的情况下,如何配置数据库字段名到JavaBean实体类属性命的自动驼峰命名转换?
使用spring boot后,越来越喜欢用注解方式进行配置,代替xml配置文件方式。mybatis中也可以完全使用注解,避免使用xml方式配置mapper。(参考 &)
设置自动驼峰命名转换,在xml中可以直接配置mapUnderscoreToCamelCase属性。
但是使用注解方式时,经过一番查找资料才找到比较好的设置方法。如下:
在spring boot的配置文件application.properties中,加入配置项:
<span style="color: # mybatis.configuration.mapUnderscoreToCamelCase=true
<span style="color: # 或
<span style="color: # mybatis.configuration.map-underscore-to-camel-case=true
设为true表示开启驼峰转换。经过试验,两种配置方法都可以。但如果同时配置,前者mybatis.configuration.mapUnderscoreToCamelCase的优先级更高。
官方的配置说明&
另外查到有通过javaConfig方式,配置org.apache.ibatis.session.SqlSessionFactory的Bean,放入spring的对象池。mapUnderscoreToCamelCase是org.apache.ibatis.session.Configuration的一个属性,实例化Configuration对象并将其mapUnderscoreToCamelCase属性设为true,再使用这个Configuration对象作为SqlSessionFactory的配置即可使mapUnderscoreToCamelCase=true生效。
但是仅仅为了改变一个属性的值,就自己编码生成一个SqlSessionFactory未免太繁琐了些。使用在application.properties中配置的方法更方便。
2.mybatis管理的@Mapper的Dao,在使用@Autowire自动注入时,IDEA有红色报错“could not autowire”,但实际运行时正常,如何去除报错?
按照本人的理解,这个报错是由于Dao接口只添加了mybatis自定义的@Mapper注解,没有添加spring定义的@Component、@Repository等,所以IDEA不认为这是纳入Spring管理的Bean,导致在IDEA找不到autowire的Dao的来源。
查找解决方法,找到了这里的问答:
里面提到安装【MyBatis plugin】插件可以解决,但是我尝试安装这个插件并启用后,仍然有红色报错(插件已经激活,不是license导致的问题),所以猜测这个插件可能是只针对XXmapper.xml配置的方式有效,而对@Mapper注解Dao interface的方式无效(针对后一种情况是否有效,大家尝试了可以反馈下结果)。
所以只好采用一种折中的不算完美的办法,在Dao interface中添加@Mapper的同时,再添加@Repository(或者@Component也可以),如下方代码的第1行:
<span style="color: # @Repository
<span style="color: # @Mapper
<span style="color: # public interface UserDao {
<span style="color: #
<span style="color: #
@Select("SELECT phone FROM user WHERE name = #{name}") //动态传入表名,可以使用 ...FROM ${tableName}... ,但需要解决sql注入风险
<span style="color: #
String getPhoneByUserName(@Param("name") String name);
<span style="color: # }
这个方法使用中看来也没有什么副作用。
PS:第一次试安装【MyBatis plugin】插件之后,启动后在IDEA的Event窗口中有以下输出:
<span style="color: # Mybatis Plugin: Mybatis Plugin is not activated yet. Click here to enter your license key to activate the plugin. You can also click here to purchase a license key to sponsor us making the plugin better. More features are on their way. Wish you happy coding with the plugin
这是一个收费的插件,需要购买license,官网显示价格是¥39.99。
我还尝试安装了【Free MyBatis plugin】和【iBATIS/MyBatis mini-plugin】插件,都没有去除红色报错。
哪位有更好的解决方法也欢迎提出~
阅读(...) 评论()mybatis 找不到映射器xml文件,该如何处理 - Java Web开发当前位置:& &&&mybatis 找不到映射器xml文件,该如何处理mybatis 找不到映射器xml文件,该如何处理&&网友分享于:&&浏览:0次mybatis 找不到映射器xml文件我用的idea,一个java&web项目,src/main/下面有三个文件夹:java,resources,webapp。当我在配置mybatsi-config.xml的&mappers&时,当我把文件放在angus.mapper.StudentMapper接口的同目录下,并配置
&&&&&&&&&mapper&resource="angus/mapper/StudentMapper.xml"/&
出现了找不到xml文件的,Error&parsing&SQL&Mapper&Configuration.&Cause:&:&Could&not&find&resource&angus/mapper/StudentMapper.xml
当我把StudentMapper.xml移动到resources文件夹(mybatis-config.xml也在这个文件夹)时,
&&mappers&
&&&&&&&&&mapper&resource="StudentMapper.xml"/&
&&&&&/mappers&
就可以了。因为xml文件很多,不想放在resources文件夹中,而且将Mapper接口和xml文件放在一块更容易修改。请大神帮忙!!!!!!
还有:官方文档给出的下面几个方法是怎么使用的呢?
&!--&Using&classpath&relative&resources&--&
&&&mapper&resource="org/mybatis/builder/AuthorMapper.xml"/&
&&&mapper&resource="org/mybatis/builder/BlogMapper.xml"/&
&&&mapper&resource="org/mybatis/builder/PostMapper.xml"/&
&/mappers&
&!--&Using&url&fully&qualified&paths&--&
&&&mapper&url="file:///var/mappers/AuthorMapper.xml"/&
&&&mapper&url="file:///var/mappers/BlogMapper.xml"/&
&&&mapper&url="file:///var/mappers/PostMapper.xml"/&
&/mappers&
&!--&Using&mapper&interface&classes&--&
&&&mapper&class="org.mybatis.builder.AuthorMapper"/&
&&&mapper&class="org.mybatis.builder.BlogMapper"/&
&&&mapper&class="org.mybatis.builder.PostMapper"/&
&/mappers&
&!--&Register&all&interfaces&in&a&package&as&mappers&--&
&&&package&name="org.mybatis.builder"/&
&/mappers&------解决思路----------------------SpringMVC&集成&MyBatis,配置&mapper&xml
&&&&&!--&2.&SQL&session&factory&--&
&&&&&bean&id="sqlSessionFactory"&class="org.mybatis.spring.SqlSessionFactoryBean"&
&&&&&&&&&property&name="dataSource"&ref="dataSource"&/&
&&&&&&&&&property&name="mapperLocations"&value="classpath:mybatis-mapper/**/*.xml"&/&&&!--&Mapper&xml&--&
&&&&&/bean&
可以参考Spring&集成&MyBatis&/java/13.%20Spring%20集成%20MyBatis.html------解决思路----------------------楼主&终于解决这问题了&&困扰我好久了
原因是:&idea不会编译src的java目录的xml文件
所以解决思路就是:将IDEA&maven项目中src源代码下的xml等资源文件编译进classes文件夹
具体操作方法就是:配置maven的pom文件配置,在&build&节点下添加&resources&代码:
&&&&&build&
&&&&&&&&&resources&
&&&&&&&&&&&&&resource&
&&&&&&&&&&&&&&&&&directory&src/main/java&/directory&
&&&&&&&&&&&&&&&&&includes&
&&&&&&&&&&&&&&&&&&&&&include&**/*.xml&/include&
&&&&&&&&&&&&&&&&&/includes&
&&&&&&&&&&&&&/resource&
&&&&&&&&&/resources&
&&&&&/build&
12345678910
12345678910
12345678910 上一篇:下一篇:文章评论相关解决方案 1234567891011 Copyright & &&版权所有刚用上mybatis,有个错误无法解决,希望求助前辈
mapper.xml映射文件接口
spring配置
我确定命名都跟要求是一样的,java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.iqclub.invite.mapper.InviteMapper.getInviteByInviteNumber &一直报错,求指导
确定你在mybatis的config.xml文件中已经引入了这个mapper文件?比如这样:
&mapper resource=&map/product.xml&/&
&?xml version=&1.0& encoding=&UTF-8& ?&
&!DOCTYPE configuration
PUBLIC &-//mybatis.org//DTD Config 3.0//EN&
&http://mybatis.org/dtd/mybatis-3-config.dtd&&
&configuration&
&environments default=&development&&
&environment id=&development&&
&transactionManager type=&JDBC&/&
&dataSource type=&POOLED&&
&property name=&driver& value=&com.mysql.jdbc.Driver&/&
&property name=&url& value=&xxxxxxxxxxxxxxx?useUnicode=true&characterEncoding=utf-8&/&
&property name=&username& value=&xxxxxxxxxx&/&
&property name=&password& value=&xxxxxxxxxxxx&/&
&/dataSource&
&/environment&
&/environments&
&mapper resource=&map/sys.xml&/&
&mapper resource=&map/product.xml&/&
&/mappers&
&/configuration&
--- 共有 4 条评论 ---
: 有可能是增加xml了没有重启,还有可能是basePackage的value值没有指定到mapper.xml的上级目录,但文档上说这个配置扫描器是递归扫描的,应该不存在路径的这个问题,再就是其它原因了
: 不对呀,写了这个bean应该mybatis的config文件不需要配置了呀,可是我按你说的引入mapper文件就好了,不配置还是不行,咋回事呢
: 那再重启一下?
谢谢,我以为配置了spring中的自动扫描&bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"&
&property name="basePackage" value="com.iqclub" /&
&/bean& 就不用引入配置文件了
mapper文件配置错了,仔细点!
--- 共有 5 条评论 ---
: 这个我也试了,上面的resultMap写了没用,是试了的。
你的resultType 换成 resultMap 。原因是返回的不一定只有一列 它的值跟resultMap一致就OK。
: 我不是执行这个方法报错,是select出错,而且,我insert方法是插入Invite对象
你把参数类型 Invite 改成 Map&String, Object&
告诉我哪里错了吧,谢谢
parameterType你别名定义了没,没有就有完整的类名试试,然后返回resultType改为resultMap=&IniteMapper&
弄个源码,跟一下mapper的解析过程,再配置起来就容易了
引用来自“Minuzy”的答案mapper文件配置错了,仔细点! 今天翻了下源码,发现org.mybatis.spring.mapper.MapperScannerConfigurer 自动扫描并创建的是java 的mapper文件,即编译后的class文件,并不是xml文件,见org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider中的resourcePattern成员:
所以无法自动扫描到xml文件就可以理解了。
要使用通配符,可以作如下配置,使用mapperLocations属性:
&bean id=&sqlSessionFactory& class=&org.mybatis.spring.SqlSessionFactoryBean&&
&property name=&dataSource& ref=&dataSource& /&
&property name=&mapperLocations& value=&classpath*:com/xxxxxx/dao/sqlmap/*.xml& /&
--- 共有 2 条评论 ---
全局自动扫Mapper是 jar包版本问题。mybatis入门常见错误
时间: 19:27:30
1.Exception in thread &main& java.io.IOException: Could not find resource config2.xml需要去Reader reader=Resources.getResourceAsReader(&config2.xml&);代码处看下,是否和src下面的配置文件名称一样,如果不一样,泽会报没有发现资源文件的错误;2.White spaces are required after keyword PUBLIC in DOCTYPE decl,原因是&!DOCTYPE configuration PUBLIC&-//mybatis.org//DTD Config 3.0//EN& && &&http://mybatis.org/dtd/mybatis-3-config.dtd&&,public后面应该加空格;3.Element type &enviroments& must be declared.或Element type &enviroment& must be declared.,Attribute &resourse& must be declared for element type &mapper&.等type需要定义的错误,则是标签出问题了,需要检查xml配置文件;4.The content of element type &transactionManager& must match &(property)*&.,错误是&transactionManager type=&JDBC&/&,标签用完就结束,不要包含property.5.Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'Dept'.& Cause: java.lang.ClassNotFoundException: Cannot find class: Dept,,原因是&select id=&selectOne& parameterType=&int& resultType=&Dept&&,此处的返回类型出问题了!!!,需要返回bean包下的实体类。综上所述,针对开始学习配置文件的同学们来说,写的时候,要仔细再仔细!!!注意大小写 空格 单引号 全交 半角等等问题!!!
作者:zhangchen124 发表于 21:27:30 原文链接
阅读:14 评论:0 查看评论java.io.IOException: Could not find resource configuration.xml
2 messages
Open this post in threaded view
Report Content as Inappropriate
java.io.IOException: Could not find resource configuration.xml
Hi,Did anyone already have this weird problem when trying to read an ibatis config file, with code like---------------------------------------------------------------------------------------------------------------
InputStream inputStry {
inputStream = Resources.getResourceAsStream("configuration.xml");
} catch (IOException e) {
trace(ExtensionLogLevel.WARN,&e.toString());
}---------------------------------------------------------------------------------------------------------------I keep on getting the error "java.io.IOException: Could not find resource configuration.xml ".I have opened my jar manually, and made sure the file is at the root of it. I also tried putting this file into a package like my.domain.config, and referenced it with&"my/domain/config/configuration.xml", but same problem.Any idea what happens here?Thanks!
You received this message because you are subscribed to the Google Groups &mybatis-user& group.
To unsubscribe from this group and stop receiving emails from it, send an email to .
For more options, visit .
Open this post in threaded view
Report Content as Inappropriate
Re: java.io.IOException: Could not find resource configuration.xml
Hello:I don&#39;t know what is your problem but I useString resource = &com/persistence/configuration.xml&;Reader reader = Resources.getResourceAsReader(resource);
this.sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
Hi,Did anyone already have this weird problem when trying to read an ibatis config file, with code like
---------------------------------------------------------------------------------------------------------------
InputStream inputStry {
inputStream = Resources.getResourceAsStream(&configuration.xml&);
} catch (IOException e) {
trace(ExtensionLogLevel.WARN, e.toString());
}---------------------------------------------------------------------------------------------------------------I keep on getting the error &java.io.IOException: Could not find resource configuration.xml &.
I have opened my jar manually, and made sure the file is at the root of it. I also tried putting this file into a package like my.domain.config, and referenced it with &my/domain/config/configuration.xml&, but same problem.
Any idea what happens here?Thanks!
You received this message because you are subscribed to the Google Groups &mybatis-user& group.
To unsubscribe from this group and stop receiving emails from it, send an email to .
For more options, visit .
You received this message because you are subscribed to the Google Groups &mybatis-user& group.
To unsubscribe from this group and stop receiving emails from it, send an email to .
For more options, visit .
Loading...}

我要回帖

更多关于 ap外置型e8 c家庭网关 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信