整合SSM框架(SpringMVC + Spring + MyBatis),适合刚接触spring的童鞋,需要有servlet和jsp基础。学习完SSM整合后可以应付开发工作,但是建议继续深究,学习spring boot,spring cloud等技术,让开发效率更上一层楼。
http://blog.csdn.net/qq598535550/article/details/51703190
- jdk 1.8
- tomcat 8.5
手把手教你整合最优雅SSM框架:SpringMVC + Spring + MyBatis
Home Page: http://blog.csdn.net/qq598535550/article/details/51703190
License: MIT License
整合SSM框架(SpringMVC + Spring + MyBatis),适合刚接触spring的童鞋,需要有servlet和jsp基础。学习完SSM整合后可以应付开发工作,但是建议继续深究,学习spring boot,spring cloud等技术,让开发效率更上一层楼。
http://blog.csdn.net/qq598535550/article/details/51703190
appoint图书重复预约时事务不会回滚,@transactional注解只在throw exception时才会回滚吧
找到多个spring-web片段怎么解决
待完善代码
return new Result<>(false, "学号不能为空");
Description Resource Path Location Type
Cannot change version of project facet Dynamic Web Module to 3.1. ssm line 1 Maven Java EE Configuration Problem
兄弟已经在spring-service.xml中配置了:
<context:component-scan base-package="xxx.xxx.xxx.service" />
spring会自动扫描xxx.xxx.xxx.service包下所有注解,完成Bean的装配。
可直接在Service中写业务,无需xxxServiceImpl这一层。
controller的方法的参数要不要约定好(比如全部实现一个公共接口从而强制约定),如果不这样,那么在拦截器中如何精确获取访问的类以及方法呢?
我现在的思路是在拦截器的preHandle方法中将handler强转为HandlerMethod,调用getMethod方法去与目标class的getMethod对比,但是你看class的getMethod,其中参数为getMethod(name, parameterTypes),如果不对controller方法的参数进行约定,这写起来会很混乱,而且代码会写的很长(很不好看)。
所以我想问下,controller方法参数怎么设计好呢?
webapp/WEB-INF/lib里的包是不是不需要用到,用maven的就行,可以删掉嘛
信息: Deploying web application directory [E:\apache-tomcat-8.5.31\webapps\DRM]
五月 15, 2018 8:04:29 下午 org.apache.catalina.core.ApplicationContext log
信息: No Spring WebApplicationInitializer types detected on classpath
五月 15, 2018 8:04:29 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory [E:\apache-tomcat-8.5.31\webapps\DRM] has finished in [63] ms
五月 15, 2018 8:04:39 下午 org.apache.catalina.startup.HostConfig undeploy
信息: Undeploying context [/DRM]
五月 15, 2018 8:04:39 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory [E:\apache-tomcat-8.5.31\webapps\DRM]
五月 15, 2018 8:04:39 下午 org.apache.catalina.core.ApplicationContext log
信息: No Spring WebApplicationInitializer types detected on classpath
五月 15, 2018 8:04:39 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory [E:\apache-tomcat-8.5.31\webapps\DRM] has finished in [62] ms
五月 15, 2018 8:04:49 下午 org.apache.catalina.startup.HostConfig undeploy
信息: Undeploying context [/DRM]
五月 15, 2018 8:04:49 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory [E:\apache-tomcat-8.5.31\webapps\DRM]
五月 15, 2018 8:04:49 下午 org.apache.catalina.core.ApplicationContext log
信息: No Spring WebApplicationInitializer types detected on classpath
五月 15, 2018 8:04:49 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory [E:\apache-tomcat-8.5.31\webapps\DRM] has finished in [59] ms
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.mycompony.app.dao.BookDao.queryById
at org.apache.ibatis.binding.MapperMethod$SqlCommand.(MapperMethod.java:227)
at org.apache.ibatis.binding.MapperMethod.(MapperMethod.java:49)
at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:65)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58)
at com.sun.proxy.$Proxy22.queryById(Unknown Source)
at com.mycompany.app.dao.BookDaoTest.testQueryById(BookDaoTest.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:73)
at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:83)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at com.microsoft.java.test.runner.JUnit4TestReference.run(JUnit4TestReference.java:51)
at com.microsoft.java.test.runner.CustomizedJUnitCoreRunner.run(CustomizedJUnitCoreRunner.java:45)
at com.microsoft.java.test.runner.JUnitLauncher.main(JUnitLauncher.java:21)
SSM框架整合配置
好了,前面bb那么多,下面我们真正开始敲代码了~
首先我们打开IED
你好,我想用tomcat把这个项目跑起来,还需要改什么配置么?
这个真的没有出现,我这边测试了下,Junit4会报错的,初学者折腾了下,发现这个问题但是还没有找到解决办法。希望能修改下。 刚才看到更新里面说的“修改预约业务代码,失败时抛异常,成功时才返回结果”,希望文档也及时修改下。
schema.sql文件中有三条sql语句,建议每条结束都添加分号。
这样就可以一次全部执行了。
<dependency>
org.springframework
spring-test
4.2.4.RELEASE
pom修改成以下,解决问题
com.mchange
c3p0
0.9.5.2
据说是:c3p0-0.9.5.2有一个依赖包mchange-commons-java-0.2.11,必须加载此包才行
项目就运行不起来,晕
It's detailed,But it can be more simple when you configure XML.
The number of XML configuration can be less if simple,some of them can configured together.
it will be reasonable when you do it!
服务可以成功启动。 数据库可以成功链接。 junit test 没问题。现在想进一步做 Controller 的调试。但是不知怎么输入url才能跑到对应 Controller 中的方法。debug时跑不到Controller 里面。求 url:/模块/资源/{id}/细分 /seckill/list 参数的具体说明 在你的这个项目中分别是什么 在哪里设置 什么的 。求详细解释 谢谢!!
前端页面没有啊 兄弟
博主您好!我们刚学ssm不会maven,能改成不用maven管理的吗?就用ssm框架的那种,具体方案求解答,谢谢!
但是我手动将xml里面的sql去查询的时候,是有返回值的
我的环境是jdk8,然后导入的时候报了下面两个错误:
One or more constraints have not been satisfied.
Cannot change version of project facet Dynamic web module to 3.1
通过下面的方法解决:
http://blog.csdn.net/steveguoshao/article/details/38414145
可能会对其他导入项目的小伙伴有用,写在这里~~~
Connected to server [2017-10-10 09:31:28,414] Artifact ssm:war exploded: Artifact is being deployed, please wait... 10-Oct-2017 21:31:33.488 INFO [RMI TCP Connection(3)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. [2017-10-10 09:31:33,754] Artifact ssm:war exploded: Artifact is deployed successfully [2017-10-10 09:31:33,754] Artifact ssm:war exploded: Deploy took 5,340 milliseconds 10-Oct-2017 21:31:38.246 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory D:\tomcat\tomcat8\webapps\manager 10-Oct-2017 21:31:38.371 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory D:\tomcat\tomcat8\webapps\manager has finished in 125 ms
启动到上面,就不走了,
no-xml版本异常,junit :
BookDaoTest.testQueryAll()---->
Book [bookId=0, name=Java程序设计, number=91]
Book [bookId=0, name=数据结构, number=7]
Book [bookId=0, name=设计模式, number=8]
Book [bookId=0, name=编译原理, number=8]
xml版正常:
BookDaoTest.testQueryAll()---->
Book [bookId=1000, name=Java程序设计, number=90]
Book [bookId=1001, name=数据结构, number=7]
Book [bookId=1002, name=设计模式, number=8]
Book [bookId=1003, name=编译原理, number=8]
30-Aug-2022 16:46:17.033 严重 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: 无法启动组件[StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:753)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:727)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:695)
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1775)
有了AppointStateEnum是否能够替换掉AppointException、NoNumberException、RepeatAppointException这3个异常呢。这种状态枚举和异常,怎么取舍呢?个人更加倾向枚举。。
return new Result<>(false, "学号不能为空"); 这句话 在maven 3.5.3 版本报错
文件已损坏
你的代码不全啊,controller那边的,list.jsp等都没有啊。
能发全一点的代码么?
学的人请慎重,前面教程不错。
然而不全
然并卵
正在转后台开发,拿着你的项目来入门,发现有一个问题,就是在controller里有个bug,最后一个函数,我做了修改。
@RequestMapping(value = "/{bookId}/{studentId}", method = RequestMethod.POST, produces = {
"application/json; charset=utf-8" })
@responsebody
private Result appoint(@PathVariable("bookId") Long bookId, @PathVariable("studentId") Long studentId) {
if (studentId == null || studentId.equals("")) {
return new Result(false, "学号不能为空");
}
AppointExecution execution = bookService.appoint(bookId, studentId);
return new Result(true, execution);
}
我本地的环境是 jdk 1.8 Tomacat 8.5 运行的时候老是报错,提示初始化失败。 所以想向你请教一下 你的本地环境是怎样的?
这也太简单了吧
感觉抛出异常需要额外写很多的异常类吧。这样的好处是什么呢?为什么一定要定义异常类?
为什么我创建的项目没有webapp目录
@test
public void appointTest() throws Exception {
this.mockMvc.perform(post(appointUrl, bookId).param("studentId", "1").accept(MediaType.APPLICATION_JSON))
.andExpect(content().contentType("application/json;charset=utf-8"));
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.