博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java框架--spring+stutrs2+mybatis整合
阅读量:4993 次
发布时间:2019-06-12

本文共 5874 字,大约阅读时间需要 19 分钟。

代码区

package cn.sxt.action;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.context.annotation.Scope;import org.springframework.stereotype.Controller;import cn.sxt.service.UserService;import cn.sxt.vo.User;@Controller("userAction")@Scope("prototype")public class UserAction {    private List
list; @Autowired private UserService userService; public String list(){ list = userService.getAll(); return "success"; } public List
getList() { return list; } public void setList(List
list) { this.list = list; } public UserService getUserService() { return userService; } public void setUserService(UserService userService) { this.userService = userService; } }
UserAction
package cn.sxt.dao;import java.util.List;import cn.sxt.vo.User;public interface UserDao {    public List
getAll();}
UserDao
package cn.sxt.dao.impl;import java.util.List;import org.apache.ibatis.session.SqlSessionFactory;import org.mybatis.spring.support.SqlSessionDaoSupport;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Repository;import cn.sxt.dao.UserDao;import cn.sxt.vo.User;@Repository("userDao")public class UserDaoImpl extends SqlSessionDaoSupport implements UserDao{    @Autowired    @Override    public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {        super.setSqlSessionFactory(sqlSessionFactory);    }    public List
getAll() { return this.getSqlSession().selectList("cn.sxt.vo.user.mapper.getAll"); }}
UserDaoImpl
package cn.sxt.service;import java.util.List;import cn.sxt.vo.User;public interface UserService {    public List
getAll();}
UserService
package cn.sxt.service.impl;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import cn.sxt.dao.UserDao;import cn.sxt.service.UserService;import cn.sxt.vo.User;@Service("userService")public class UserServiceImpl implements UserService{    @Autowired    private UserDao userDao;    public void setUserDao(UserDao userDao) {        this.userDao = userDao;    }    public List
getAll() { return userDao.getAll(); }}
UserServiceImpl
package cn.sxt.test;import java.util.List;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import cn.sxt.dao.UserDao;public class Test {    public static void main(String[] args) {        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");        UserDao userDao = (UserDao)ac.getBean("userDao");        List list = userDao.getAll();        System.out.println(list.size());    }}
Test
package cn.sxt.vo;public class User {    private int id;    private String name;    private String pwd;    public int getId() {        return id;    }    public void setId(int id) {        this.id = id;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public String getPwd() {        return pwd;    }    public void setPwd(String pwd) {        this.pwd = pwd;    }}
User
user.mapper.xml
applicationContext.xml
mybatis.cfg.xml
/list.jsp
struts.xml
17ssm_annotation
contextConfigLocation
classpath:applicationContext.xml
org.springframework.web.context.ContextLoaderListener
struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
struts2
/*
index.html
index.htm
index.jsp
default.html
default.htm
default.jsp
web.xml
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>              My JSP 'index.jsp' starting page    
编号 姓名 密码
${bean.id } ${bean.name } ${bean.pwd }
list.jsp

 

转载于:https://www.cnblogs.com/ou-pc/p/8228051.html

你可能感兴趣的文章
十大经典数据挖掘算法
查看>>
Rhythmbox乱码的解决的方法
查看>>
中纪委:抗震中官员临危退缩玩忽职守将被严处
查看>>
MySQL 8.0.12 基于Windows 安装教程
查看>>
在hue中使用hive
查看>>
eclipse快捷键
查看>>
在指定文本里记录内容
查看>>
Android WebView常见问题及解决方案汇总
查看>>
[BZOJ4025]二分图
查看>>
HTML5 Canvas玩转酷炫大波浪进度图
查看>>
创建ASP.NET Core MVC应用程序(5)-添加查询功能 & 新字段
查看>>
电话录音系统说明书
查看>>
JVM(1)——IDEA启动分配内存大小及GC日志打印
查看>>
oracle 批量更新之update case when then
查看>>
text3
查看>>
自己写的连击文字特效
查看>>
【Android】eclipse打不开的解决办法和“Jar mismatch! Fix your dependencies”的解决
查看>>
Mysql查询某字段值重复的数据
查看>>
Java 自学笔记-基本语法3setOut()方法设置新的输出流
查看>>
cocos2d-JS 模块 anysdk 概述
查看>>