栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SSM 整合

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SSM 整合

ssm 整合,这个是自己导入相应dependence ,并创建好MAVEN project 以archetype webapp 为骨架进行整合。目的:对SSM整合加强记忆。 tomcat 服务器的构建 这个比较容易:简单说一下
  1. 下载,不用安装,解压就好。记住解压的目录。

tomcat下载地址

  1. 配置
    创建好maven project 后

    然后点击,可以先配置完Serve的一些配置,然后对Deployment 然后配置,然后继续Serve


没成功可以去找一下别的博客

目标文件路径


对web.xml进行修改如下





    
        dispatcherServlet
        org.springframework.web.servlet.DispatcherServlet
        
        
            contextConfigLocation
            classpath:dispatcher.xml
        
        
        1
    
    
        dispatcherServlet
        /
    


对dispatcher





    
    

    
    


    
        
        
        
        
    

    
        
        
        
        
    

    
        
        
        
            
                classpath:com.baizhiedu.mapper/*Mapper.xml
            
        
    

    
        
        
    

    
        
    

    



按如图创建文件结果

对数据库的操作:
进入到安装的mysql bin目录下
输入:
mysql -hlocalhost -uroot -p
密码:

输入:show databases 显示已有的数据库
输入:use database_name(已有的数据库名)
输入:
当然你也可以使用navicat等管理工具进行创建

create table t_user(
    id integer primary key auto_increment,
    name varchar(12),
    password varchar(12)
);

创建以Mapper.xml文件结尾的mapper文件






    
    
        insert into t_user(name,password) values (#{name},#{password})
    

在实体entity包中创建User对象

package com.baizhiedu.entity;

import java.io.Serializable;

public class User implements Serializable {
    private Integer id;
    private String name;
    private String password;

    public User(){}

    public User(Integer id, String name, String password) {
        this.id = id;
        this.name = name;
        this.password = password;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }


}

在dao包中创建UserDAO 接口

package com.baizhiedu.dao;

import com.baizhiedu.entity.User;

public interface UserDAO {
    public void save(User user);
}

在service保重创建UserSevice 接口 和他的实现类

package com.baizhiedu.service;

import com.baizhiedu.entity.User;

public interface UserService {
    public void register(User user);
}

实现类

package com.baizhiedu.service;

import com.baizhiedu.dao.UserDAO;
import com.baizhiedu.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDAO userDAO;

    @Override
    public void register(User user) {
        System.out.println("user = " + user);
        userDAO.save(user);
    }
}

在controller保重创建UserController类

package com.baizhiedu.controller;


import com.baizhiedu.entity.User;
import com.baizhiedu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("register")
    public String register(User user){
        userService.register(user);

        return "regOK";

    }
}

在webapp文件夹下创建regOK.jsp文件

<%--
  Created by IntelliJ IDEA.
  User: 25675
  Date: 2022/6/13
  Time: 19:12
  To change this template use File | Settings | File Templates.
--%>
<%@ page pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" language="java" %>


    



    
UserName
Password

我们需要进行Post 提交
创建一个reg.jsp 页面来进行提交

<%--
  Created by IntelliJ IDEA.
  User: 25675
  Date: 2022/6/13
  Time: 19:12
  To change this template use File | Settings | File Templates.
--%>
<%@ page pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" language="java" %>


    



    
UserName
Password

验证:



数据库:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/969638.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号