java里ssm_java搭建SSM开发环境

原标题:java搭建SSM开发环境

1.添加spring支持,加入mybatis jar包

2.配置web.xml文件.

在web.xml中加入以下代码,用于读取beans.xml文件和处理乱码

controller

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:beans.xml

controller

*.action

encoding

org.springframework.web.filter.CharacterEncodingFilter

encoding

UTF-8

encoding

/*

3.配置beans.xml文件

xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:p="http://www.springframework.org/schema/p"

xmlns:tx="http://www.springframework.org/schema/tx"

xmlns:mvc="http://www.springframework.org/schema/mvc"

xmlns:context="http://www.springframework.org/schema/context"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd

http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd

http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd

"

>

4.编写数据访问层

1).编写接口,

29955e150200c06efc318a6089de8835.png

2).编写mybatis的xml文件.

/p>

PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"

"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

select t.*,s.id sid,s.name sname,s.sex ssex,s.age sage from teacher t left join student s on t.id=s.tid

select s.*,t.id tid,t.name tname,t.sex tsex,t.age tage from student s inner join teacher t on s.tid=t.id

update student

name=#{name},

age=#{age},

where id=#{id}

insert into teacher (name,sex,age)values(#{name},#{sex},#{age})

其中有几点需要注意的

resultMap节点,用于设置返回数据和实体类的对应,里面有两个节点,type,id

操作节点,类似select,update,insert,操作这些节点的时候sql语句自己的属性就直接写,参数的属性就写#{}里面

update里面有一个set标签,记住更新的用法

联表查询,注意如果两张表数据库字段如果是一样的话,应该用别名处理,具体上面有。

springMVC和mybatis的集成基本实现。返回搜狐,查看更多

责任编辑:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值