SSM整合的小Demo:
功能点:
1.分页
2.数据校验
2.1前端(jquery)和后端校验(JSR303)
3.ajax(新增,编辑,删除,多个删除)
4.Rest风格的URL:使用HTTP协议请求方式的动词,来表示对资源的操作(GET(查询),POST(新增),PUT(修改),DELETE(删除))
技术点:
1.基础框架—ssm(SpringMVC+Spring+MyBatis
2. 数据库-MySQL
3.前端框架-bootstrap快速搭建简洁美观的界面
4.项目的依赖管理-Maven
5.分页-pagehelper
6.逆向工程-MyBatis Generator
效果
- 主界面
- 新增
- 修改
- 删除单个
- 删除多个
项目的地址:https://github.com/clover426/atguigu_SSM
踩过的坑:
第一个:
dispatcherServlet-servlet.xml在WEB-INF路径下
必须设置为资源路径
第二个:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException:
Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table ‘ssm_crud.d’ doesn’t exist
The error may exist in file [I:\Springmvctest\ssm_CRUD\target\classes\mapper\EmployeeMapper.xml]
The error may involve defaultParameterMap
The error occurred while setting parameters
SQL: SELECT count(0) FROM tbl_emp e LEFT JOIN d ON e.d_id
= d.dept_id
Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table ‘ssm_crud.d’ doesn’t exist
; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table ‘ssm_crud.d’ doesn’t exist
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at org.springframework.test.web.servlet.TestDispatcherServlet.service(TestDispatcherServlet.java:65)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at org.springframework.mock.web.MockFilterChain$ServletFilterProxy.doFilter(MockFilterChain.java:167)
at org.springframework.mock.web.MockFilterChain.doFilter(MockFilterChain.java:134)
at org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:155)
at com.itt.crud.test.MvcTest.testPage(MvcTest.java:45)
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.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
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:252)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
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:191)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.springframework.jdbc.BadSqlGrammarException:
Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table ‘ssm_crud.d’ doesn’t exist
The error may exist in file [I:\Springmvctest\ssm_CRUD\target\classes\mapper\EmployeeMapper.xml]
The error may involve defaultParameterMap
The error occurred while setting parameters
SQL: SELECT count(0) FROM tbl_emp e LEFT JOIN d ON e.d_id
= d.dept_id
Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table ‘ssm_crud.d’ doesn’t exist
; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table ‘ssm_crud.d’ doesn’t exist
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:231)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
at org.mybatis.spring.SqlSessionTemplate
S
q
l
S
e
s
s
i
o
n
I
n
t
e
r
c
e
p
t
o
r
.
i
n
v
o
k
e
(
S
q
l
S
e
s
s
i
o
n
T
e
m
p
l
a
t
e
.
j
a
v
a
:
446
)
a
t
c
o
m
.
s
u
n
.
p
r
o
x
y
.
SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446) at com.sun.proxy.
SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)atcom.sun.proxy.Proxy22.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:137)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:75)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
at com.sun.proxy.
P
r
o
x
y
23.
s
e
l
e
c
t
B
y
E
x
a
m
p
l
e
W
i
t
h
D
e
p
t
(
U
n
k
n
o
w
n
S
o
u
r
c
e
)
a
t
c
o
m
.
i
t
t
.
c
r
u
d
.
s
e
r
v
i
c
e
.
E
m
p
l
o
y
e
e
S
e
r
v
i
c
e
.
g
e
t
A
l
l
(
E
m
p
l
o
y
e
e
S
e
r
v
i
c
e
.
j
a
v
a
:
22
)
a
t
c
o
m
.
i
t
t
.
c
r
u
d
.
s
e
r
v
i
c
e
.
E
m
p
l
o
y
e
e
S
e
r
v
i
c
e
Proxy23.selectByExampleWithDept(Unknown Source) at com.itt.crud.service.EmployeeService.getAll(EmployeeService.java:22) at com.itt.crud.service.EmployeeService
Proxy23.selectByExampleWithDept(UnknownSource)atcom.itt.crud.service.EmployeeService.getAll(EmployeeService.java:22)atcom.itt.crud.service.EmployeeService
F
a
s
t
C
l
a
s
s
B
y
S
p
r
i
n
g
C
G
L
I
B
FastClassBySpringCGLIB
FastClassBySpringCGLIB
824
f
9610.
i
n
v
o
k
e
(
<
g
e
n
e
r
a
t
e
d
>
)
a
t
o
r
g
.
s
p
r
i
n
g
f
r
a
m
e
w
o
r
k
.
c
g
l
i
b
.
p
r
o
x
y
.
M
e
t
h
o
d
P
r
o
x
y
.
i
n
v
o
k
e
(
M
e
t
h
o
d
P
r
o
x
y
.
j
a
v
a
:
204
)
a
t
o
r
g
.
s
p
r
i
n
g
f
r
a
m
e
w
o
r
k
.
a
o
p
.
f
r
a
m
e
w
o
r
k
.
C
g
l
i
b
A
o
p
P
r
o
x
y
824f9610.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) at org.springframework.aop.framework.CglibAopProxy
824f9610.invoke(<generated>)atorg.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)atorg.springframework.aop.framework.CglibAopProxyCglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:721)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor
1.
p
r
o
c
e
e
d
W
i
t
h
I
n
v
o
c
a
t
i
o
n
(
T
r
a
n
s
a
c
t
i
o
n
I
n
t
e
r
c
e
p
t
o
r
.
j
a
v
a
:
99
)
a
t
o
r
g
.
s
p
r
i
n
g
f
r
a
m
e
w
o
r
k
.
t
r
a
n
s
a
c
t
i
o
n
.
i
n
t
e
r
c
e
p
t
o
r
.
T
r
a
n
s
a
c
t
i
o
n
A
s
p
e
c
t
S
u
p
p
o
r
t
.
i
n
v
o
k
e
W
i
t
h
i
n
T
r
a
n
s
a
c
t
i
o
n
(
T
r
a
n
s
a
c
t
i
o
n
A
s
p
e
c
t
S
u
p
p
o
r
t
.
j
a
v
a
:
282
)
a
t
o
r
g
.
s
p
r
i
n
g
f
r
a
m
e
w
o
r
k
.
t
r
a
n
s
a
c
t
i
o
n
.
i
n
t
e
r
c
e
p
t
o
r
.
T
r
a
n
s
a
c
t
i
o
n
I
n
t
e
r
c
e
p
t
o
r
.
i
n
v
o
k
e
(
T
r
a
n
s
a
c
t
i
o
n
I
n
t
e
r
c
e
p
t
o
r
.
j
a
v
a
:
96
)
a
t
o
r
g
.
s
p
r
i
n
g
f
r
a
m
e
w
o
r
k
.
a
o
p
.
f
r
a
m
e
w
o
r
k
.
R
e
f
l
e
c
t
i
v
e
M
e
t
h
o
d
I
n
v
o
c
a
t
i
o
n
.
p
r
o
c
e
e
d
(
R
e
f
l
e
c
t
i
v
e
M
e
t
h
o
d
I
n
v
o
c
a
t
i
o
n
.
j
a
v
a
:
179
)
a
t
o
r
g
.
s
p
r
i
n
g
f
r
a
m
e
w
o
r
k
.
a
o
p
.
i
n
t
e
r
c
e
p
t
o
r
.
E
x
p
o
s
e
I
n
v
o
c
a
t
i
o
n
I
n
t
e
r
c
e
p
t
o
r
.
i
n
v
o
k
e
(
E
x
p
o
s
e
I
n
v
o
c
a
t
i
o
n
I
n
t
e
r
c
e
p
t
o
r
.
j
a
v
a
:
92
)
a
t
o
r
g
.
s
p
r
i
n
g
f
r
a
m
e
w
o
r
k
.
a
o
p
.
f
r
a
m
e
w
o
r
k
.
R
e
f
l
e
c
t
i
v
e
M
e
t
h
o
d
I
n
v
o
c
a
t
i
o
n
.
p
r
o
c
e
e
d
(
R
e
f
l
e
c
t
i
v
e
M
e
t
h
o
d
I
n
v
o
c
a
t
i
o
n
.
j
a
v
a
:
179
)
a
t
o
r
g
.
s
p
r
i
n
g
f
r
a
m
e
w
o
r
k
.
a
o
p
.
f
r
a
m
e
w
o
r
k
.
C
g
l
i
b
A
o
p
P
r
o
x
y
1.proceedWithInvocation(TransactionInterceptor.java:99) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.CglibAopProxy
1.proceedWithInvocation(TransactionInterceptor.java:99)atorg.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)atorg.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)atorg.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)atorg.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)atorg.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)atorg.springframework.aop.framework.CglibAopProxyDynamicAdvisedInterceptor.intercept(CglibAopProxy.java:656)
at com.itt.crud.service.EmployeeService
E
n
h
a
n
c
e
r
B
y
S
p
r
i
n
g
C
G
L
I
B
EnhancerBySpringCGLIB
EnhancerBySpringCGLIB20270937.getAll()
at com.itt.crud.controller.EmployeeController.getEmps(EmployeeController.java:37)
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.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
… 38 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table ‘ssm_crud.d’ doesn’t exist
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
at com.mysql.jdbc.Util.getInstance(Util.java:387)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:939)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2478)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2625)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2551)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1192)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.execute(NewProxyPreparedStatement.java:67)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:63)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79)
at org.apache.ibatis.executor.BatchExecutor.doQuery(BatchExecutor.java:93)
at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324)
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
at com.github.pagehelper.PageInterceptor.intercept(PageInterceptor.java:111)
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)
at com.sun.proxy.
P
r
o
x
y
34.
q
u
e
r
y
(
U
n
k
n
o
w
n
S
o
u
r
c
e
)
a
t
o
r
g
.
a
p
a
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java:148) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141) 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.mybatis.spring.SqlSessionTemplate
Proxy34.query(UnknownSource)atorg.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)atorg.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)atjava.lang.reflect.Method.invoke(Method.java:498)atorg.mybatis.spring.SqlSessionTemplateSqlSessionInterceptor.invoke(SqlSessionTemplate.java:433)
… 71 more
解决的方法:
这个错误### SQL: SELECT count(0) FROM tbl_emp e LEFT JOIN d ON e.
d_id
= d.dept_id
我们就知道,肯定是SQL有错误,这个的bug是在用LEFT JOIN时没有加表名,直接用了别名d才报的错!!!!!!
第三种:
在使用maven开发时,由于jar包版本的不同,有时候会有冲突之类的,所以在做的时候尽量的统一jar包的版本!切记!