IDEA整合 ssm的详细demo(使用maven)

网友投稿 786 2022-05-29

前言

把我idea的模板拿出来,希望能够帮到大家初学者,从myeclipse迁移到idea是以把心酸泪,我把以前的demo拿出来。

创建maven项目,切记别选错

到这项的时候,如果创建maven项目不全的话,一定要加上最后的archetypeCatalog=internal.

这样项目就创建好,下面添加tomcat,配置的话就不多说了。记住将项目添加进去,还有路径配置(这个配置资料比较多)

添加tomcat

紧接着先创建对应文件夹,使其目录大致与相似一致(大文件夹一致)创建完文件夹要声明作用。

创建完文件夹声明各个文件夹的属性以及用途(和myeclipse有点不一样,因为myeclipse帮你自动配置好了,idea需要自己配置一下)。

结果这样就行:

接着开始配置maven环境。里面包含几乎初学者的所有jar包。ssm的初始配置应该是够的,我刚开始找maven完整版也找了很久,自己也凑了一点。我的maven配置为:(项目名改成自己的)

4.0.0 food food 1.0-SNAPSHOT war food Maven Webapp http://www.example.com 7.0 1.2 5.1.46 1.4 1.3.0 5.1.5.RELEASE 3.4.0 2.9.8 4.12 3.2.2 1.7.21 1.2.17 javax javaee-api ${javaee.version} jstl jstl ${jstl.version} mysql mysql-connector-java ${mysql.version} commons-dbcp commons-dbcp ${dbcp.version} org.mybatis mybatis-spring ${mybatis-spring.version} org.mybatis.generator mybatis-generator-core 1.3.7 org.mybatis mybatis ${mybatis.version} org.springframework spring-core ${spring.version} org.springframework spring-web ${spring.version} org.springframework spring-oxm ${spring.version} org.springframework spring-tx ${spring.version} org.springframework spring-jdbc ${spring.version} org.springframework spring-webmvc ${spring.version} org.springframework spring-aop ${spring.version} org.springframework spring-context ${spring.version} org.springframework spring-test ${spring.version} com.fasterxml.jackson.core jackson-databind ${jackson.verson} com.fasterxml.jackson.core jackson-core ${jackson.verson} com.fasterxml.jackson.core jackson-annotations ${jackson.verson} junit junit ${junit-version} test cglib cglib ${cglib-version} log4j log4j ${log4j.version} org.slf4j slf4j-api ${slf4j.version} org.aspectj aspectjweaver 1.8.10 aspectj aspectjrt 1.5.3 food maven-clean-plugin 3.0.0 maven-resources-plugin 3.0.2 maven-compiler-plugin 3.7.0 maven-surefire-plugin 2.20.1 maven-war-plugin 3.2.0 maven-install-plugin 2.5.2 maven-deploy-plugin 2.8.2

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

紧接着web.xml配置,我第一个过滤器可以删除掉,里面一些名称根据自己项目名修改,但是对应关系要一致

cors2 com.date.fitter.filter cors2 /* org.springframework.web.context.ContextLoaderListener contextConfigLocation classpath*:applicationContext.xml springMvc org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath*:food-servlet.xml 1 20971520 20971520 0 springMvc / encodingFilter org.springframework.web.filter.CharacterEncodingFilter encoding UTF-8 forceEncoding true encodingFilter /*

1

2

3

4

5

6

7

8

9

10

11

12

13

IDEA整合 ssm的详细demo(使用maven)

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

接着在resource目录下的xml配置如下:

application.xml spring核心配置

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

food-servlet.xml配置 springmvc的配置,名称具体参考自己的,包括映射jsp等等

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

mybatis-conf.xml配置: mybatis一些额外配置,但是我用的不太多

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

还剩log4j.properties:这是输出日志的配置

# Global logging configuration log4j.rootLogger=DEBUG, stdout # Console output... log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

1

2

3

4

5

6

上面就是基本的配置,下面我把我简单的结合的demo展示出来控制层controller,控制器是springmvc的主要部分,里面主要关于url请求地址的配置,以及处理。和servlet很像。它是网站和服务器通信的枢纽。

controller:

dao层叫数据访问层。其实就是声明一个接口,这个接口有很多方法集合,关于数据的增删该查,返回的类型可以为自定义map,list,或者bean对象等等。

dao层为:

mapper,mapper就是dao的方法具体实现,在xml中写sql,这是mybatis部分。在myeclipse中我的dao和mapper是放到一块的,但是idea的maven编译方式和myeclipse不同,如果写在一块需要配置,可以直接在resources中新建mapping文件夹放到里面。这样就能够被编译

bean层,至于bean层就不多说了,就是对象,要和数据库对象的字段一一对应。如果不一致则需要自定义返回类型在其中配置。

另外,还有一些遇到过的小问题,比如没有找打监听器报错,

还有就是一些jar包版本可能会冲突,比如我之前用的mysql就出错了。后来换了版本。注意要在dependece中先将jar包移除,然后maven clean jar包,不然可能会出错。还有就是刚开始配置可能有的xml或者class没找到,可以在target文件下查看classes那些东西已经编译

剩下的如果以后遇到会补充,上面有些文件名可能写blog时候会打错,各位具体名称还请对照自己的名称。另外,如果有错误还请大神指出。

项目完整github地址(有些变化)

ssm

如果对后端、爬虫、数据结构算法等感性趣欢迎关注我的个人公众号交流:bigsai

IDE Maven Spring

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Vue进阶(幺捌肆):CodeMirror应用小结
下一篇:【MindSpore第六期两日集训营】MindElec作业记录
相关文章