springmvc+spring+mybatis+mysql配置过程
admin
2023-05-19 18:42:34
0

环境:eclipse

项目目录:

springmvc+spring+mybatis+mysql配置过程

jar包:

springmvc+spring+mybatis+mysql配置过程

springmvc+spring+mybatis+mysql配置过程


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.Driver
url=jdbc:mysql://localhost/cec
username=root
password=root
#\u5B9A\u4E49\u521D\u59CB\u8FDE\u63A5\u6570
initialSize=0
#\u5B9A\u4E49\u6700\u5927\u8FDE\u63A5\u6570
maxActive=20
#\u5B9A\u4E49\u6700\u5927\u7A7A\u95F2
maxIdle=20
#\u5B9A\u4E49\u6700\u5C0F\u7A7A\u95F2
minIdle=1
#\u5B9A\u4E49\u6700\u957F\u7B49\u5F85\u65F6\u95F4
maxWait=60000


log4j.properties

#\u5B9A\u4E49LOG\u8F93\u51FA\u7EA7\u522B
log4j.rootLogger=INFO,Console,File
#\u5B9A\u4E49\u65E5\u5FD7\u8F93\u51FA\u76EE\u7684\u5730\u4E3A\u63A7\u5236\u53F0
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.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\u5F0F
log4j.appender.Console.layout = org.apache.log4j.PatternLayout
log4j.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\u4EF6
log4j.appender.File = org.apache.log4j.RollingFileAppender
#\u6307\u5B9A\u8F93\u51FA\u76EE\u5F55
log4j.appender.File.File = logs/ssm.log
#\u5B9A\u4E49\u6587\u4EF6\u6700\u5927\u5927\u5C0F
log4j.appender.File.MaxFileSize = 10MB
# \u8F93\u51FA\u6240\u4EE5\u65E5\u5FD7\uFF0C\u5982\u679C\u6362\u6210DEBUG\u8868\u793A\u8F93\u51FADEBUG\u4EE5\u4E0A\u7EA7\u522B\u65E5\u5FD7
log4j.appender.File.Threshold = ALL
log4j.appender.File.layout = org.apache.log4j.PatternLayout
log4j.appender.File.layout.ConversionPattern =[%p] [%d{yyyy-MM-dd HH\:mm\:ss}][%c]%m%n

UserController.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 {
@Resource
private 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{
@Resource
private UserMapper userMapper ;
@Override
public void insert(User record) {
userMapper.insert(record) ;
}
@Override
public 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
  
  
    select 
    
    from user
    where id = #{id,jdbcType=VARCHAR}
  
  
    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
    
      
        username = #{username,jdbcType=VARCHAR},
      
      
        password = #{password,jdbcType=VARCHAR},
      
      
        age = #{age,jdbcType=VARCHAR},
      
      
        role = #{role,jdbcType=VARCHAR},
      
    
    where id = #{id,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


不推荐大家直接看源码,自己参考以上代码,看看能否自己搭出来

相关内容

热门资讯

牛蛙抗生素超标5倍,真把消费者... 文 | 心 冥深夜嗦蛙一时爽,一看检测报告“火葬场”。近日,“抗生素牛蛙”冲上热搜,给人看得一哆嗦,...
男子外出喝酒后深夜被人送回,家... 2025年8月21日,甘肃陇西县47岁男子张某某外出与人喝酒,其父母多次电话寻人,电话多由他人接听。...
安德烈·科尔图诺夫:当资本主义... 【文/观察者网专栏作者 安德烈·科尔图诺夫】 两千年前,蒙爱圣徒约翰警示所有罪人和无信之人:“拒绝把...
华为WATCH GT 7手表真... IT之家 8 月 3 日消息,华为 WATCH GT 7 系列手表新品海报今日登陆各大城市大屏,宣传...
大脑也有“带宽”瓶颈?他们发现... 原标题:开辟脑机接口“通信带宽”增强新范式(“咖”说科技) 人类大脑与物理世界之间存在“通信带宽”。...
招致强烈反对后,法庭临时叫停以... 【环球网报道 记者 李飒】据《以色列时报》《耶路撒冷邮报》等以媒8月2日报道,耶路撒冷地方法院当天发...
韩国 “赏月号” 探测器将观测... 8月3日,财闻海外资讯消息,SpaceX猎鹰9号火箭上面级残骸将于8月5日撞击月球表面,韩国首枚月球...
日本熊本商场爆炸,两名女员工本... 据凤凰卫视报道,日本熊本县嘉岛町永旺购物中心在强震后发生爆炸,造成7人死亡。公司高层8月2日晚出席遇...
AI圈最会“追风”的男人,杀入... 作者丨晨阳 编辑丨小龙 离开英伟达一个月后,贾扬清带着新公司Intent Lab杀回了战场。 没有...
小米汽车:澎程的长滑轨在损耗特... 来源:环球网 【环球网科技综合报道】8月3日,小米汽车在回答用户关于“车内的长滑轨用久了会不会出异响...