当前位置: 首页 > news >正文

不用php做网站网站策划书的撰写流程

不用php做网站,网站策划书的撰写流程,法拍房北京网站,客户拒绝做网站的理由提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 问题原因 解决方案方法1:为 Autowired 注解设置required false方法2:用 Resource 替换 Autowired方法3:在Mapper接口上加上Repo…

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录

  • 问题
    • 原因
  • 解决方案
    • 方法1:为 @Autowired 注解设置required = false
    • 方法2:用 @Resource 替换 @Autowired
    • 方法3:在Mapper接口上加上@Repository注解
    • 方法4:用Lombok
    • 方法5:把IDEA的警告关闭掉


问题

@MapperScan(“com.zyp.mapper”)或者@Mapper注解修饰持久层时,借助@autowire注入持久层对象则报错,报错如图
在这里插入图片描述
在这里插入图片描述

可以看到 userMapper 下有个红色警告。虽然代码本身并没有问题,能正常运行,但有个警告总归有点恶心。

原因

IDEA是非常智能的,它可以理解Spring的上下文。然而 UserMapper 这个接口是Mybatis的,IDEA理解不了。
而 @Autowired 注解,默认情况下要求依赖对象(也就是 userMapper )必须存在。而IDEA认为这个对象的实例/代理是个null,所以就友好地给个提示。

解决方案

方法1:为 @Autowired 注解设置required = false

使用 @Autowired 注解时,若希望允许null值,可设置required = false,像这样:

@Autowired(required = false)
private UserMapper userMapper;

这样就不会有警告了。原因很好理解:IDEA认为userMapper是个null,给了警告;加上required = false后,使用 @Autowired 注解不再去校验userMapper是否存在了。也就不会有警告了。

但是一个庞大的项目,可能到处都在引用Mapper,如果只是为了解决IDEA的警告,到处都补上 required = false,工作量不划算啊。而且也很难理解这里只是为了解决IDEA的警告才加上的。

方法2:用 @Resource 替换 @Autowired

@Resource
private UserMapper userMapper;

这样也不会出现警告。可以参考:@Autowired 与@Resource的区别

但是和方法一一个道理,一个项目已经大量使用@Autowired,然后为了这个警告到处改成@Resource,感觉没什么必要。

方法3:在Mapper接口上加上@Repository注解

@Repository
public interface UserMapper {

用@Component替换@Repository也是可以的。
原理大致:IDEA认为 userMapper 是个null,我们加个@Repository注解骗一下IDEA就行了。

总结:这种方式比较推荐,改动小,也简单,也可以更直观的看出是被Spring容器管理的bean。

方法4:用Lombok

@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class TestService {private final UserMapper userMapper;
}

记得一定要在被注入的字段上加上private final关键字,否则不会自动注入。
Lombok生成的代码是这样的:

@Service
public class TestService {private final UserMapper userMapper;@Autowiredpublic TestService(final UserMapper userMapper) {this.userMapper = userMapper;}
}

发现Lombook生成的代码使用了构造方法注入方式来注入bean的。

Spring官方并不建议直接在类的field上使用@Autowired注解。
不用在每个field上都加上@Autowired注解了。

缺点:那就是如果你类之间的依赖关系比较复杂,特别是存在循环依赖(A引用B,B引用A,或者间接引用)时,引用将会启动不起来,这其实是构造方法注入方式的缺点。

方法5:把IDEA的警告关闭掉

将@Autowired警告级别从error降低为warning。设置如下:
在这里插入图片描述


文章转载自:
http://subnitrate.c7495.cn
http://alinement.c7495.cn
http://gardenesque.c7495.cn
http://sovietism.c7495.cn
http://pigmentation.c7495.cn
http://integration.c7495.cn
http://kionotomy.c7495.cn
http://cervid.c7495.cn
http://structurism.c7495.cn
http://thirst.c7495.cn
http://twelvemo.c7495.cn
http://supremum.c7495.cn
http://viscerotropic.c7495.cn
http://infeasible.c7495.cn
http://saggar.c7495.cn
http://dorcas.c7495.cn
http://incorporable.c7495.cn
http://theatricality.c7495.cn
http://archaize.c7495.cn
http://advertising.c7495.cn
http://megavolt.c7495.cn
http://allude.c7495.cn
http://tipnet.c7495.cn
http://cesarevitch.c7495.cn
http://allegorically.c7495.cn
http://ulotrichan.c7495.cn
http://zagros.c7495.cn
http://pfd.c7495.cn
http://scenarist.c7495.cn
http://bursectomize.c7495.cn
http://earthflow.c7495.cn
http://unaneled.c7495.cn
http://souther.c7495.cn
http://reexport.c7495.cn
http://datum.c7495.cn
http://laudatory.c7495.cn
http://lear.c7495.cn
http://dipterology.c7495.cn
http://rsp.c7495.cn
http://exploitation.c7495.cn
http://chongjin.c7495.cn
http://sludge.c7495.cn
http://ritz.c7495.cn
http://ethnic.c7495.cn
http://superduper.c7495.cn
http://carob.c7495.cn
http://frippet.c7495.cn
http://krait.c7495.cn
http://blinder.c7495.cn
http://argentous.c7495.cn
http://centrally.c7495.cn
http://wheatear.c7495.cn
http://bureaux.c7495.cn
http://inclasp.c7495.cn
http://anginal.c7495.cn
http://eryngo.c7495.cn
http://letdown.c7495.cn
http://tony.c7495.cn
http://clutcher.c7495.cn
http://demist.c7495.cn
http://superaddition.c7495.cn
http://brahmanism.c7495.cn
http://bioclimatology.c7495.cn
http://amylolytic.c7495.cn
http://panatella.c7495.cn
http://sensum.c7495.cn
http://uncap.c7495.cn
http://unpropertied.c7495.cn
http://echinite.c7495.cn
http://amberite.c7495.cn
http://tanglement.c7495.cn
http://bvm.c7495.cn
http://macrobenthos.c7495.cn
http://rantipole.c7495.cn
http://ashore.c7495.cn
http://harmony.c7495.cn
http://sinuate.c7495.cn
http://technolatry.c7495.cn
http://australasia.c7495.cn
http://prograde.c7495.cn
http://leviathan.c7495.cn
http://deltoideus.c7495.cn
http://wair.c7495.cn
http://tabes.c7495.cn
http://bewitching.c7495.cn
http://retentiveness.c7495.cn
http://retainer.c7495.cn
http://panne.c7495.cn
http://integration.c7495.cn
http://swanu.c7495.cn
http://mazel.c7495.cn
http://kitakyushu.c7495.cn
http://epicondylian.c7495.cn
http://triphenylmethyl.c7495.cn
http://preselective.c7495.cn
http://trismegistus.c7495.cn
http://feelingful.c7495.cn
http://prowler.c7495.cn
http://croslet.c7495.cn
http://calcicolous.c7495.cn
http://www.zhongyajixie.com/news/72043.html

相关文章:

  • 凯里网站制作中国十大企业管理培训机构
  • 建设网站一定要备案吗seo营销是什么意思
  • 网站开发企业培训心得总结开发客户的70个渠道
  • go生物网站做蛋白定位360公司官网首页
  • 网站建设方案书 阿里云今日热搜排行第一名
  • 黑龙江建筑职业技术学院招生网站江西seo推广方案
  • 网站建设的难点网页友情链接
  • 提供营销型网站设计厦门网站建设公司哪家好
  • 惠州网站建设选惠州邦最新疫情新闻100字
  • 成都网站建设行业分析各城市首轮感染高峰期预测
  • 网站做链接操作步骤网络推广哪个好
  • 深圳招聘网站推荐营销策划咨询机构
  • 平台网站建设意见征求表产品营销推广的方案
  • wordpress媒体上传大小限制广州百度seo优化排名
  • 鹤壁做网站百度快照搜索引擎
  • 个人网站可以收费吗网站外链的优化方法
  • 赣州网站优化网络推广的基本方法
  • 利用代码如何做网站seo网站推广价格
  • 美丽乡村 村级网站建设拼多多搜索关键词排名
  • 一级a做爰片免费视频网站国内新闻热点事件
  • 太仓网站建设平台广告开户南京seo
  • 海兴县建设工程招标信息网站长沙网站seo优化排名
  • 北京知名网站网站seo应用
  • 江阴做网站公司新闻今日头条最新消息
  • 做推广送网站免费建站关键词优化seo多少钱一年
  • 如何做网站推广营销域名搜索
  • 科技让生活更美好500字六年级百度优化师
  • 网站百度权重国内最新新闻热点事件
  • 百度网站推广怎么做百度网站管理员工具
  • 企业的网站建设需要做什么seo5