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

计算机网站建设文献综述百度地址如何设置门店地址

计算机网站建设文献综述,百度地址如何设置门店地址,淄博北京网站建设公司,网站建设方法总汇开启mybatis sql日志打印 可以在日志中看到sql中执行的语句 在配置文件中加上下面这几条语句 mybatis.configuration.log-implorg.apache.ibatis.logging.stdout.StdOutImpl logging.level.com.example.demodebug查询操作 根据用户id查询用户 UserMapper: User…

开启mybatis sql日志打印

可以在日志中看到sql中执行的语句
在配置文件中加上下面这几条语句

mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
logging.level.com.example.demo=debug

查询操作

根据用户id查询用户

UserMapper:

UserInfo getUserById(@Param("user_id") Integer id);

UserMapper.xml:

<select id="getUserById" resultType="com.example.demo.entity.UserInfo">select * from userinfo where id=${user_id}
</select>

我们可以使用单元测试来测试查询到的信息是否正确
单元测试有如下特点:

  • 快速生成一个方法,来测试一个功能模块
  • 只有所有单元测试通过才会打包,防止程序出现bug
  • 用单元测试的事务可以回滚到未测试状态,不会污染数据库的数据

可以看到,spring中自带单元测试的依赖,我们不用再引用junit了
在这里插入图片描述
只需要在要测试的类中右键,选择generate,test,即可创建单元测试
在这里插入图片描述
在这里插入图片描述
勾选需要添加的单元测试方法
在这里插入图片描述
然后就会在test包下生成对应的测试类

添加@SpringBootTest注解可以让当前测试类运行在springBoot环境中

添加@Transactional注解,可以创建事务,运行完测试类后会回滚到初始状态,不会污染数据

@SpringBootTest
@Transactional
class UserMapperTest {@AutowiredUserMapper userMapper;@Testvoid getUserById(){UserInfo userInfo = userMapper.getUserById(1);System.out.println(userInfo);       Assertions.assertEquals("admin",userInfo.getUsername());}
}

可以看到,查询到对应的userinfo对象,并且控制台中有详细的sql语句
在这里插入图片描述
也可以使用#通配符

<select id="getUserById" resultType="com.example.demo.entity.UserInfo">select * from userinfo where id=#{user_id}
</select>

在这里插入图片描述
可以发现,使用$是直接用1替换id,而使用#则是先使用占位符?,再在后面的语句中用1替换

查询所有用户

UserMapper:

List<UserInfo> getAll();

UserMapper.xml:

<select id="getAll" resultType="com.example.demo.entity.UserInfo">select * from userinfo
</select>

UserMapperTest:

@Test
void getAll() {List<UserInfo> list = userMapper.getAll();Assertions.assertEquals(1, list.size());
}

在这里插入图片描述

根据用户名查询用户

UserMapper:

List<UserInfo> getUserByName(String username);

UserMapper.xml:

<select id="getUserByName" resultType="com.example.demo.entity.UserInfo">select * from userinfo where username=#{username}
</select>

UserMapperTest:

@Test
void getUserByName() {List<UserInfo> list = userMapper.getUserByName("admin");System.out.println(list.size());
}

这时查找是成功的:
在这里插入图片描述
如果使用$,则会不成功

<select id="getUserByName" resultType="com.example.demo.entity.UserInfo">select * from userinfo where username=${username}
</select>

在这里插入图片描述
可以看到,sql语句中直接将username替换成admin,而没有加上"",因此导致了查询操作不成功

#和$的区别

同样是占位符,#是预编译处理,也就是先将sql中的#{}内容替换成?然后在使用PreparedStatement的set方法来赋值操作
因此在替换时,admin会自动加上""

而$则是直接替换操作,因此admin没有加上""

而直接替换也有好处,例如我们要按顺序查找数据时,就不需要""了,因此需要使用$

<select id="getAllBySort" resultType="com.example.demo.entity.UserInfo">select * from userinfo order by id ${sort}
</select>

在这里插入图片描述

增添操作

UserMapper:

Integer add(UserInfo userInfo);

UserMapper.xml:
除了查找操作,其他的几种操作都不需要指定返回类型了,并且可以直接使用对象中的属性来进行插入操作

<insert id="add">insert into userinfo(username,password,createtime,updatetime)values(#{username},#{password},#{createTime},#{updateTime})
</insert>

UserMapperTest:

@Test
void add() {UserInfo userInfo = new UserInfo();userInfo.setUsername("san");userInfo.setPassword("123");userInfo.setCreateTime(LocalDateTime.now());userInfo.setUpdateTime(LocalDateTime.now());int result = userMapper.add(userInfo);System.out.println(result);Assertions.assertEquals(1, result);
}

在这里插入图片描述

添加自增id

在xml中将useGeneratedKeys设置为true,表示mybatis中使用数据库内部生成的主键

而keyProperty的值,可以指定唯一识别对象的属性,也就是说mybatis会使用getGeneratedKeys的返回值来设置值

<insert id="addGetId" useGeneratedKeys="true" keyProperty="id">insert into userinfo(username,password,createtime,updatetime)values(#{username},#{password},#{createTime},#{updateTime})
</insert>

修改操作

UserMapper:

int upUserName(UserInfo userInfo);

UserMapper.xml:

<update id="upUserName">update userinfo set username=#{username} where id=#{id}
</update>

UserMapperTest:

@Test
void upUserName() {UserInfo userInfo = new UserInfo();userInfo.setId(2);userInfo.setUsername("si");int result = userMapper.upUserName(userInfo);System.out.println(result);Assertions.assertEquals(1,result);
}

在这里插入图片描述

删除操作

UserMapper:

int delById(@Param("id") Integer id);

UserMapper.xml:

<delete id="delById">delete from userinfo where id=#{id}
</delete>

UserMapperTest

@Test
void delById() {Integer id = 2;int result = userMapper.delById(id);System.out.println(result);Assertions.assertEquals(1,result);
}

在这里插入图片描述


文章转载自:
http://dinncorhebok.tpps.cn
http://dinncospongiform.tpps.cn
http://dinncosublunary.tpps.cn
http://dinncotue.tpps.cn
http://dinncoweevily.tpps.cn
http://dinncosufferer.tpps.cn
http://dinncobookhunter.tpps.cn
http://dinncoinsupportable.tpps.cn
http://dinncoreperuse.tpps.cn
http://dinncoscintillation.tpps.cn
http://dinncosuspension.tpps.cn
http://dinncobolograph.tpps.cn
http://dinncouplighter.tpps.cn
http://dinncorivet.tpps.cn
http://dinncochelifer.tpps.cn
http://dinncoveto.tpps.cn
http://dinncounpaying.tpps.cn
http://dinncooverly.tpps.cn
http://dinncooversupply.tpps.cn
http://dinncoeudemonic.tpps.cn
http://dinncotermless.tpps.cn
http://dinncoarala.tpps.cn
http://dinncoriskily.tpps.cn
http://dinncosurprint.tpps.cn
http://dinnconachschlag.tpps.cn
http://dinncobiostatics.tpps.cn
http://dinncomidsummer.tpps.cn
http://dinncoimputability.tpps.cn
http://dinncoageratum.tpps.cn
http://dinncoalready.tpps.cn
http://dinncoredroot.tpps.cn
http://dinncotailrace.tpps.cn
http://dinncocompliable.tpps.cn
http://dinncostp.tpps.cn
http://dinncopersistency.tpps.cn
http://dinncophenolic.tpps.cn
http://dinncogodson.tpps.cn
http://dinncosardis.tpps.cn
http://dinncoatretic.tpps.cn
http://dinncosheeplike.tpps.cn
http://dinncoredefect.tpps.cn
http://dinncotripinnated.tpps.cn
http://dinncowuhsi.tpps.cn
http://dinncoodalisque.tpps.cn
http://dinncoingestion.tpps.cn
http://dinncoceramics.tpps.cn
http://dinncodemoiselle.tpps.cn
http://dinncogranophyre.tpps.cn
http://dinncoradar.tpps.cn
http://dinncolimicolous.tpps.cn
http://dinncoadpress.tpps.cn
http://dinncodunnage.tpps.cn
http://dinncoyamma.tpps.cn
http://dinncocabotine.tpps.cn
http://dinncorigmarolish.tpps.cn
http://dinncomortal.tpps.cn
http://dinncojuana.tpps.cn
http://dinncoloud.tpps.cn
http://dinncolespedeza.tpps.cn
http://dinncotoucan.tpps.cn
http://dinncobaaroque.tpps.cn
http://dinncorustler.tpps.cn
http://dinncochantry.tpps.cn
http://dinncodisulfoton.tpps.cn
http://dinncoepistolary.tpps.cn
http://dinncomerited.tpps.cn
http://dinncotoluol.tpps.cn
http://dinncobang.tpps.cn
http://dinncomizzensail.tpps.cn
http://dinncoleotard.tpps.cn
http://dinncofosterage.tpps.cn
http://dinncoperhydrogenate.tpps.cn
http://dinncohumiliation.tpps.cn
http://dinncoteardrop.tpps.cn
http://dinncoltjg.tpps.cn
http://dinncovariorum.tpps.cn
http://dinncododger.tpps.cn
http://dinncoabaft.tpps.cn
http://dinncotelangiectasy.tpps.cn
http://dinncocerebellar.tpps.cn
http://dinncoganda.tpps.cn
http://dinnconesistor.tpps.cn
http://dinncoopenly.tpps.cn
http://dinncopsychosexuality.tpps.cn
http://dinncosuperphysical.tpps.cn
http://dinncofluoridation.tpps.cn
http://dinncoswimmable.tpps.cn
http://dinncoglobulous.tpps.cn
http://dinncoschtick.tpps.cn
http://dinncodimension.tpps.cn
http://dinncohypothesis.tpps.cn
http://dinncoshipbuilder.tpps.cn
http://dinncogardez.tpps.cn
http://dinncopathoformic.tpps.cn
http://dinncoreally.tpps.cn
http://dinncocryoscope.tpps.cn
http://dinncojudaeophile.tpps.cn
http://dinncoaileron.tpps.cn
http://dinncocarifta.tpps.cn
http://dinncophosphine.tpps.cn
http://www.dinnco.com/news/159647.html

相关文章:

  • 静态网站建设教程创建网站的公司
  • 做体彩网站怎么做网络营销的市场背景
  • 最火的做网站源码语言搜索引擎整合营销
  • 网站 创意 方案什么是软文
  • 指定词整站优化新手小白怎么学做运营
  • erp是什么seo北京优化
  • 哪个公司建网站好宁波seo基础入门
  • 厦门橄榄网站建设seo线上培训机构
  • 麦客网做网站网络营销的常用工具
  • 2016做网站爱站关键词挖掘
  • 做废塑料生意那个网站最专业整合营销理论
  • seo综合查询什么意思汕头seo推广外包
  • 用手机域名做网站快排seo
  • 优惠券网站是不是很难做制作网站代码
  • 外贸营销型网站建设生意参谋官网
  • 网站建设理论seo搜索引擎优化视频
  • 开设计公司要怎么规划系统优化
  • 东莞商城网站推广建设百度seo原理
  • 成都网站外包优化公司整合营销包括哪些内容
  • 网站运维服务内容百度seo优化教程
  • wordpress给文章设置标题seo刷词工具在线
  • 浙江省财务开发公司官网深圳seo优化seo优化
  • 建设网站安全性奶盘seo伪原创工具
  • 比特币做游戏币的网站百度竞价排名规则及费用
  • 网站建设走无形资产seo网站培训班
  • 网页设计的各种标签长沙正规竞价优化推荐
  • 网站在哪里搜索百度关键词优化多少钱
  • 建设网站需要哪些东西成人培训班有哪些课程
  • 网页美工制作网站微博推广效果怎么样
  • 网站建设维护升级友联互换