springmvc+spring+mybatis+mysql配置过程
发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,环境:eclipse项目目录:jar包:web.xmlArchetype Created Web Application
千家信息网最后更新 2026年11月01日springmvc+spring+mybatis+mysql配置过程
环境:eclipse
项目目录:

jar包:

web.xml
Archetype Created Web Application contextConfigLocation classpath:hanxuanyuan/config/spring-mybatis.xml encodingFilter org.springframework.web.filter.CharacterEncodingFilter true encoding UTF-8 encodingFilter /* org.springframework.web.context.ContextLoaderListener org.springframework.web.util.IntrospectorCleanupListener SpringMVC org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath:hanxuanyuan/config/spring-mvc.xml 1 true SpringMVC / /index.jsp
spring-mybatis.xml
jdbc.properties
driver=com.mysql.jdbc.Driverurl=jdbc:mysql://localhost/cecusername=rootpassword=root#\u5B9A\u4E49\u521D\u59CB\u8FDE\u63A5\u6570initialSize=0#\u5B9A\u4E49\u6700\u5927\u8FDE\u63A5\u6570maxActive=20#\u5B9A\u4E49\u6700\u5927\u7A7A\u95F2maxIdle=20#\u5B9A\u4E49\u6700\u5C0F\u7A7A\u95F2minIdle=1#\u5B9A\u4E49\u6700\u957F\u7B49\u5F85\u65F6\u95F4maxWait=60000
log4j.properties
#\u5B9A\u4E49LOG\u8F93\u51FA\u7EA7\u522Blog4j.rootLogger=INFO,Console,File#\u5B9A\u4E49\u65E5\u5FD7\u8F93\u51FA\u76EE\u7684\u5730\u4E3A\u63A7\u5236\u53F0log4j.appender.Console=org.apache.log4j.ConsoleAppenderlog4j.appender.Console.Target=System.out#\u53EF\u4EE5\u7075\u6D3B\u5730\u6307\u5B9A\u65E5\u5FD7\u8F93\u51FA\u683C\u5F0F\uFF0C\u4E0B\u9762\u4E00\u884C\u662F\u6307\u5B9A\u5177\u4F53\u7684\u683C\u5F0Flog4j.appender.Console.layout = org.apache.log4j.PatternLayoutlog4j.appender.Console.layout.ConversionPattern=[%c] - %m%n#\u6587\u4EF6\u5927\u5C0F\u5230\u8FBE\u6307\u5B9A\u5C3A\u5BF8\u7684\u65F6\u5019\u4EA7\u751F\u4E00\u4E2A\u65B0\u7684\u6587\u4EF6log4j.appender.File = org.apache.log4j.RollingFileAppender#\u6307\u5B9A\u8F93\u51FA\u76EE\u5F55log4j.appender.File.File = logs/ssm.log#\u5B9A\u4E49\u6587\u4EF6\u6700\u5927\u5927\u5C0Flog4j.appender.File.MaxFileSize = 10MB# \u8F93\u51FA\u6240\u4EE5\u65E5\u5FD7\uFF0C\u5982\u679C\u6362\u6210DEBUG\u8868\u793A\u8F93\u51FADEBUG\u4EE5\u4E0A\u7EA7\u522B\u65E5\u5FD7log4j.appender.File.Threshold = ALLlog4j.appender.File.layout = org.apache.log4j.PatternLayoutlog4j.appender.File.layout.ConversionPattern =[%p] [%d{yyyy-MM-dd HH\:mm\:ss}][%c]%m%nUserController.java
package hanxuanyuan.controller;import javax.annotation.Resource;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.RequestMapping;import hanxuanyuan.domain.User;import hanxuanyuan.service.UserService;@Controller@RequestMapping("/user")public class UserController {@Resourceprivate UserService userService;@RequestMapping("/showUser")public String showUser(Model model){User user = userService.selectByPrimaryKey("1") ;model.addAttribute("user",user) ;return "welcome" ;}}UserService.java
package hanxuanyuan.service;import hanxuanyuan.domain.User;public interface UserService { void insert(User record); User selectByPrimaryKey(String id);}UserServiceImpl.java
package hanxuanyuan.service;import javax.annotation.Resource;import org.springframework.stereotype.Service;import hanxuanyuan.dao.UserMapper;import hanxuanyuan.domain.User;@Service("userService")public class UserServiceImpl implements UserService{@Resourceprivate UserMapper userMapper ;@Overridepublic void insert(User record) {userMapper.insert(record) ;}@Overridepublic User selectByPrimaryKey(String id) {return userMapper.selectByPrimaryKey(id);}}UserMapper.java
package hanxuanyuan.dao;import hanxuanyuan.domain.User;public interface UserMapper { int deleteByPrimaryKey(String id); int insert(User record); int insertSelective(User record); User selectByPrimaryKey(String id); int updateByPrimaryKeySelective(User record); int updateByPrimaryKey(User record);}UserMapper.xml
id, username, password, age, role delete from user where id = #{id,jdbcType=VARCHAR} insert into user (id, username, password, age, role) values (#{id,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, #{age,jdbcType=VARCHAR}, #{role,jdbcType=VARCHAR}) insert into user id, username, password, age, role, #{id,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, #{age,jdbcType=VARCHAR}, #{role,jdbcType=VARCHAR}, update user where id = #{id,jdbcType=VARCHAR} username = #{username,jdbcType=VARCHAR}, password = #{password,jdbcType=VARCHAR}, age = #{age,jdbcType=VARCHAR}, role = #{role,jdbcType=VARCHAR}, update user set username = #{username,jdbcType=VARCHAR}, password = #{password,jdbcType=VARCHAR}, age = #{age,jdbcType=VARCHAR}, role = #{role,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
userMapper,User,UserMapper.xml这三个文件是mybatis-generator自动生成的,http://pan.baidu.com/s/1cvQWsY
使用方法: (1)打开dos命令窗口,进入到该目录下,配置好generatorConfig.xml后,运行命令:
java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite
(2)拷贝文件到项目对应位置
jar包链接:http://down.51cto.com/data/2302826
项目源码链接: http://pan.baidu.com/s/1o7H6WUu
不推荐大家直接看源码,自己参考以上代码,看看能否自己搭出来
项目
命令
文件
源码
目录
链接
配置
三个
代码
位置
使用方法
拷贝
方法
环境
自动生成
参考
推荐
生成
运行
过程
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
科技赋能下的互联网金融
互联网科技公司发展
上海挚品互联网科技
美国互联网黑科技
互联网科技上市公司
友谊互联网络科技
深圳艾佳互联网科技
济南华为互联网科技产业总部基地
哈尔滨新华互联网科技学院
宁波青枫互联网科技有限公司
阿里互联网科技公司
科技互联网大厂
武汉健翔互联网络科技有限公司
荆州市昕露互联网络科技有限公司
中天科技中国工业互联网
互联网科技融合创新
广东鹅鹅鹅互联网科技有限公司
银川新华互联网科技学校原画
互联网科技职业技能培训学校
互联网科技创新创业项目
互联网新科技
互联网是第几次科技革命的成果
金融科技创新监管互联网金融
深圳互联网络科技有限公司
万易互联网科技有限公司
广西互联网科技公司
苏州大垚互联网科技
互联网科技圈年度人物
互联网金融科技公司的优势
前海云享互联网科技