当前位置: 首页 > wzjs >正文

怎么做一个企业的网站网站开发周期和进度管理

怎么做一个企业的网站,网站开发周期和进度管理,网站建设外包还是自己做,10常用的网络营销方法目录 一、环境准备二、简单启动三、增< insert id >四、返回主键五、删<delete id >六、改<update id >七、查< select id resultType > 一、环境准备 在使用XML来实现的数据库操作的时候&#xff0c;我们的依赖下载与前面的使用注解时的依赖是一…

目录

  • 一、环境准备
  • 二、简单启动
  • 三、增< insert id = >
  • 四、返回主键
  • 五、删<delete id = >
  • 六、改<update id = >
  • 七、查< select id = resultType = >

一、环境准备

在使用XML来实现的数据库操作的时候,我们的依赖下载与前面的使用注解时的依赖是一样的。

		<dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>3.0.4</version></dependency><dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId><scope>runtime</scope></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter-test</artifactId><version>3.0.4</version><scope>test</scope></dependency>

在配置文件yml格式,也需要添加上跟使用注解时的配置。还要多加上mybatis. mapper-locations: classpath:mapper/**Mapper.xml

# 数据库连接配置 
spring:application:name: spring-mybatis-demodatasource:url: jdbc:mysql://127.0.0.1:3306/mybatis_test?characterEncoding=utf8&useSSL=falseusername: rootpassword: 1234driver-class-name: com.mysql.cj.jdbc.Drivermybatis:configuration: # 配置打印 MyBatis⽇志log-impl: org.apache.ibatis.logging.stdout.StdOutImplmap-underscore-to-camel-case: true #配置驼峰⾃动转换# 配置 mybatis xml 的⽂件路径,在 resources/mapper 创建所有表的 xml ⽂件 mapper-locations: classpath:mapper/**Mapper.xml

二、简单启动

我们先安装一个插件MybatisX,可以帮我们更简单实现xml文件与接口之间的跳转。

mapper接口:

package com.example.springmybatisdemo.mapper;import com.example.springmybatisdemo.model.UserInfo;
import org.apache.ibatis.annotations.Mapper;import java.util.List;
@Mapper
public interface UserMapperXML {List<UserInfo> selectAll();
}

xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.springmybatisdemo.mapper.UserMapperXML"><select id="selectAll" resultType="com.example.springmybatisdemo.model.UserInfo">select * from user_info;</select></mapper>
  • <mapper> 标签:需要指定 namespace 属性,表⽰命名空间,值为 UserMapperXML 接⼝的全限定名,包括全包名.类名。
  • <select> 查询标签:是⽤来执⾏数据库的查询操作的:
  • id :是和 Interface (接⼝)中定义的⽅法名称⼀样的,表⽰对接⼝的具体实现⽅法。
  • resultType :是返回的数据类型,也就是我们定义的实体类.

测试:

package com.example.springmybatisdemo.mapper;import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest
class UserMapperXMLTest {@Autowiredprivate UserMapperXML userMapperXML;@BeforeEachvoid setUp() {}@AfterEachvoid tearDown() {}@Testvoid selectAll() {System.out.println(userMapperXML.selectAll());}
}

结果:

三、增< insert id = >

使用标签< Insert >来写入数据,直接使⽤UserInfo对象的属性名来获取参数。

    <insert id="insertOne">insert into user_info (username, password, age) values (#{username},#{password},#{age})</insert>

测试函数:

    @Testvoid insertOne() {UserInfo userInfo = new UserInfo();userInfo.setAge(8);userInfo.setPassword("888");userInfo.setUsername("888");Integer result = userMapperXML.insertOne(userInfo);System.out.println("增加函数:"+ result);}

测试结果:

四、返回主键

还是使用< insert >标签来写入数据,只不过设置useGeneratedKeys 和keyProperty属性 。

  • useGeneratedKeys:这会令 MyBatis 使⽤ JDBC 的 getGeneratedKeys ⽅法来取出由数据库内部⽣成的主键(⽐如:像 MySQL 和 SQL Server 这样的关系型数据库管理系统的⾃动递增字段),默认值:false.
  • keyProperty:指定能够唯⼀识别对象的属性,MyBatis 会使⽤ getGeneratedKeys 的返回值或 insert 语句的 selectKey ⼦元素设置它的值,默认值:未设置(unset)
<insert id="insertOne" useGeneratedKeys="true" keyProperty="id">insert into user_info (username, password, age) values (#{username},#{password},#{age})</insert>

测试方法:

    @Testvoid insertOne() {UserInfo userInfo = new UserInfo();userInfo.setAge(9);userInfo.setPassword("999");userInfo.setUsername("999");Integer result = userMapperXML.insertOne(userInfo);System.out.println("增加函数:"+ result+", 增加数据的id:"+userInfo.getId());}

结果:

五、删<delete id = >

使用< delete >标签,加上删除的SQL语句即可。

    <delete id="deleteOne">delete from user_info where id = #{id}</delete>

测试方法:

    @Testvoid deleteOne() {userMapperXML.deleteOne(9);}

结果:

六、改<update id = >

修改数据直接使用< update >注解,加上修改SQL语句即可。

    <update id="updateOne">update user_info set delete_flag = #{deleteFlag} where id = #{id}</update>

测试方法:

@Testvoid updateOne() {UserInfo userInfo = new UserInfo();userInfo.setId(8);userInfo.setDeleteFlag(1);userMapperXML.updateOne(userInfo);}

结果:

七、查< select id = resultType = >

查询我们只需要使用标签即可。
但是我们也会遇见像前面注解的时候因为字段名和变量名不同而导致映射错误。解决方式与前面也相似。

  1. 使用起别名的查询语句,将数据库不同字段名取别名为属性名。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.springmybatisdemo.mapper.UserMapperXML"><select id="selectAll" resultType="com.example.springmybatisdemo.model.UserInfo">select username , password, age, gender, phone,delete_flag as deleteFlag , create_time as createTime, update_time as updateTimefrom user_info</select></mapper>
  1. 使用配置文件将数据库字段中使用下划线的蛇形命名转换为小驼峰命名。mybatis.configuration.map-underscore-to-camel-case: true
mybatis:configuration:map-underscore-to-camel-case: true #配置驼峰⾃动转换
  1. 使用标签result和resultMap。在resultMap标签中放入result标签数组,result标签的column属性对应数据库字段,property属性对应类属性名。当其他查询语句需要使用相同的映射时,这需要在select标签的resultMap属性写上resultMap标签的id属性即可。
	<resultMap id="UserMap" type="com.example.springmybatisdemo.model.UserInfo"><result column="delete_flag" property="deleteFlag"></result><result column="create_time" property="createTime"></result><result column="update_time" property="updateTime"></result></resultMap><select id="selectAll" resultType="com.example.springmybatisdemo.model.UserInfo" resultMap="UserMap">select * from user_info</select>


文章转载自:

http://Vvh7AvC5.yzxhk.cn
http://q0UL3Msa.yzxhk.cn
http://9dNdFEn2.yzxhk.cn
http://0KBQETAJ.yzxhk.cn
http://9AOGhUbm.yzxhk.cn
http://OgoBlTRp.yzxhk.cn
http://AFmL6yff.yzxhk.cn
http://3rlo3sWp.yzxhk.cn
http://vwJEdDGZ.yzxhk.cn
http://EcElLBBR.yzxhk.cn
http://Go0zr5e0.yzxhk.cn
http://fBZcZqNu.yzxhk.cn
http://iDGlyP4J.yzxhk.cn
http://gX1JmHza.yzxhk.cn
http://7nNXDyQQ.yzxhk.cn
http://Au9M1EXa.yzxhk.cn
http://8HCvCdgs.yzxhk.cn
http://uiyz9CB2.yzxhk.cn
http://rfNjKkch.yzxhk.cn
http://666mQsA5.yzxhk.cn
http://gBoHaKDK.yzxhk.cn
http://8kbrmcv9.yzxhk.cn
http://NgsAXqJv.yzxhk.cn
http://USRtrV6E.yzxhk.cn
http://DfebDz0R.yzxhk.cn
http://TKow5fY1.yzxhk.cn
http://po5lygOf.yzxhk.cn
http://wbzfZU6h.yzxhk.cn
http://k8KQ1QXx.yzxhk.cn
http://dS6mLjaU.yzxhk.cn
http://www.dtcms.com/wzjs/645698.html

相关文章:

  • 温州学校网站建设easyui 网站设计
  • 网站后台密码是什么如何快速提高网站关键词排名
  • 页面好看的蛋糕网站绿色网站欣赏
  • 平面设计素材免费网站有哪些宁波龙山建设有限公司网站
  • 陇西哪里能学做网站建设网站要学编程吗
  • 江门营销网站建设龙岩网站建设一般多少钱
  • html网站首页设计小店怎么做网站
  • 网站内容要突出什么原因网站被降权怎么恢复
  • 山东网络推广平台关键词优化排名有哪些牛霸天的软件1
  • 北京市规划网站张家口市住房和城乡建设局网站
  • 网页特效 网页素材的网站新手如何入侵一个网站
  • 宜兴城乡建设局网站做导购网站赚钱吗
  • 建立网站数据库实验报告wordpress logo怎么换
  • DW做网站入门步骤教学云网站注册
  • 攻击jsp网站西安网站建设公司平台
  • 合肥常德seo技术
  • 模板网站制作平台网络软文营销案例3篇
  • 自己的网站做怎样的优化调整appstar
  • 湖州做网站公司有那几家天津百度做网站多少钱
  • 网站排名优化外包wordpress ghostjs
  • 人才网站怎么做网站功能设计
  • 开网站建设公司挣钱吗深圳汇鑫科技网站建设
  • flash云网站卖服务器网站源码
  • 免费的个人主页网页制作网站哈尔滨市建筑企业管理站
  • 网站开发技术的雏形 cgi动画设计就业前景
  • 微信上的网站怎么做的吗wordpress修改邮箱设置
  • 做视频网站 视频放在哪里找数据库与网站建设的关系
  • 国外免费建站网站搭建设计类专业哪个专科学校好
  • 潮州专业网站建设制作有个专门做简历的网站叫
  • 做网站公司 郑州福州专业做网站公司