public class TB_AD {
//最主要就是与数据库中内容的表头相对应
private int id;
private int fromdev;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getFromdev() {
return fromdev;
}
public void setFromdev(int fromdev) {
this.fromdev = fromdev;
}
}
<!-- 增加 -->
<insert id="addAd" parameterType="TB_AD">
<!-- 默认参数 -->
insert into tb_ad(id,fromdev,destID,px) values(#{param1},#{param2},#{param3},#{param4})
<!--
固定参数名
insert into tb_dev(id,fromdev,destID,px) values(#{id},#{fromdev},#{destID},#{px})
-->
</insert>
<!-- 删除 -->
<delete id="deleteAd" parameterType="int">
delete from tb_ad where id=#{id}
</delete>
<!-- 修改 -->
<update id="updateAd" parameterType="TB_AD" >
update tb_ad set id=#{id},fromdev=#{fromdev},destID=#{destID},px=#{px} where id=#{id}
</update>
<!-- 查询 -->
<select id="selectById" parameterType="int" resultType="TB_AD">
SELECT * FROM tb_ad where id=#{id}
</select>
<select id="list" parameterType="String" resultType="TB_AD">
SELECT * FROM tb_ad
</select>
@Service
public class TB_DESTServiceimpl implements TB_DESTService {
@Autowired
TB_DESTMapper tbdest;
//添加数据
@Override
public void addDest(int id,String destname,double lng,double lat) {
tbdest.addDest(id,destname,lng,lat);
}
//删除
@Override
public void deleteDest(int id) {
tbdest.deleteDest(id);
}
//修改
@Override
public void updateDest(int id, String destname, double lng, double lat) {
tbdest.updateDest(id, destname, lng, lat);
}
//各种查找数据
@Override
public List<TB_DEST> getDestByName(String destname) {
return tbdest.selectByName(destname);
}
@Override
public List<TB_DEST> list() {
return tbdest.list();
}
}
@Controller
public class DestinationControl {
@Autowired
TB_DESTService tbdest;
//查询
//跳转到destination页面,列出设备名称
@RequestMapping("/destination")
public String destination(Model model) {
List<TB_DEST> list = tbdest.list();
model.addAttribute("list",list);
return "destination";
}
@RequestMapping("/selectByDestName")
public String destinationUpdate(HttpServletRequest req,HttpServletResponse resq,Model model)throws ServletException, IOException{
req.setCharacterEncoding("UTF-8");
String destname=req.getParameter("destname");
List<TB_DEST> list = tbdest.getDestByName(destname);
model.addAttribute("list",list);
return "destination";
}
@RequestMapping("/routeSelectByDestName")
public String routeSelectByDestName(HttpServletRequest req,HttpServletResponse resq,Model model)throws ServletException, IOException{
req.setCharacterEncoding("UTF-8");
String destname=req.getParameter("destname");
List<TB_DEST> list = tbdest.getDestByName(destname);
model.addAttribute("list",list);
return "route-selectDest";
}
//跳转到destination-add界面
@RequestMapping("/destination-add")
public String destinationAdd(Model model){
return "destination-add";
}
//增加
@RequestMapping("/addDest")
public String add(HttpServletRequest req,HttpServletResponse resq,Model model) throws ServletException, IOException{
req.setCharacterEncoding("UTF-8");
//获取前台数据,强制转换类型
int id=Integer.parseInt(req.getParameter("id"));
String destname=req.getParameter("destname");
double lng=Double.parseDouble(req.getParameter("lng"));
double lat=Double.parseDouble(req.getParameter("lat"));
tbdest.addDest(id,destname,lng,lat);
List<TB_DEST> list = tbdest.list();
model.addAttribute("list",list);
return "destination";
}
//删除
@RequestMapping("/deleteDest")
protected String deleteDest(HttpServletRequest request, HttpServletResponse response,Model model) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
//接受前端传来的id
int id=Integer.parseInt(request.getParameter("id"));
tbdest.deleteDest(id);
List<TB_DEST> list = tbdest.list();
model.addAttribute("list",list);
return "destination";
}
//修改
@RequestMapping("/destUpdate")
public String update(HttpServletRequest req,HttpServletResponse resq,Model model)throws ServletException, IOException{
req.setCharacterEncoding("UTF-8");
String destname=req.getParameter("destname");
List<TB_DEST> list = tbdest.getDestByName(destname);
model.addAttribute("list",list);
return "destination-update";
}
@RequestMapping("/updateDest")
public String updateDest(HttpServletRequest req,HttpServletResponse resq,Model model) throws ServletException, IOException{
req.setCharacterEncoding("UTF-8");
//获取前台数据,强制转换类型
int id=Integer.parseInt(req.getParameter("id"));
String destname=req.getParameter("destname");
double lng=Double.parseDouble(req.getParameter("lng"));
double lat=Double.parseDouble(req.getParameter("lat"));
tbdest.updateDest(id, destname, lng, lat);
List<TB_DEST> list = tbdest.list();
model.addAttribute("list",list);
return "destination";
}
}
public class MyThreadTest {
private final static Semaphore semaphore = new Semaphore(2);// 设置2个车位
public static void main(String[] args) {
System.out.println("start");
p(semaphore, true, 1);
p(semaphore, false, 2);
p(semaphore, false, 3);
p(semaphore, true, 4);
p(semaphore, true, 5);
System.out.println("end");
}
/**
* 停车
*
* @param semaphore 信号对象
* @param enterInto 停车true/出库false
* @param theCarNum 车辆序号
*/
private static void p(Semaphore semaphore, boolean enterInto, int theCarNum) {
if (!enterInto) {
try {
Thread.sleep(2000);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("车辆出库");
// 释放1个车位
// 通过LockSupport.unpark(s.thread)来释放锁,详见AbstractOwnableSynchronizer.unparkSuccessor
semaphore.release(1);
}
try {
// 如果达到设定的信号量,通过LockSupport.park(this)来释放锁,详见AbstractOwnableSynchronizer.parkAndCheckInterrupt
semaphore.acquire();
System.out.println("第 " + theCarNum + " 辆车进入");
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Semaphore中Sync继承了AbstractQueuedSynchronizer
* 改变AbstractOwnableSynchronizer中state值(该值记录着剩余信号量)
*
* AbstractOwnableSynchronizer加载时会调用静态代码块获取state的偏移地址:
* stateOffset = unsafe.objectFieldOffset(AbstractQueuedSynchronizer.class.getDeclaredField("state"));
* 上述获取对象某个变量的效率比使用反射获取的效率高
*
* protected final boolean compareAndSetState(int expect, int update) {
* // stateOffset为state变量的偏移地址
* return unsafe.compareAndSwapInt(this, stateOffset, expect, update);
* }
*/
}
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 模板方法模式二
{
class CustomerDbObject:DatabaseObject
{
private string ConnenctString = "Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=D:\\Database4.mdb";
private string CommandString;
private DataSet dataSet=null;
public override void Connect()
{
Console.WriteLine("ddddd");
}
public override void DisConnect()
{
Console.WriteLine("ddddd");//
}
public override void Process()
{
DataTable dataTable = dataSet.Tables["Customer"];
Console.WriteLine("processss");
//dataTable.Rows;
foreach (DataRow dataRow in dataTable.Rows)
Console.WriteLine(dataRow["CompanyName"]);
//Console.WriteLine(x.StackTrace);
}
public override void Select()
{
OleDbConnection connetion = new OleDbConnection(ConnenctString);
connetion.Open();
CommandString = "select CompanyName from Customer";
Console.WriteLine("processss");
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(CommandString, connetion);
dataSet = new DataSet();
dataAdapter.Fill(dataSet, "Customer");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 模板方法模式二
{
abstract class DatabaseObject
{
abstract public void Connect();
abstract public void Select();
abstract public void Process();
abstract public void DisConnect();
//模板方法
public void run()
{
Connect();
Select();
Process();
DisConnect();
}
}
}
using System;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 模板方法模式二
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
CustomerDbObject ma = new CustomerDbObject();
ma.run();
Console.WriteLine("gfff");//
// OleDbDataAdapter a;
//Application.EnableVisualStyles();
// Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new Form1());
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 模板_登录
{
public partial class Form1 : Form
{
string count;
string pwd;
public Form1()
{
InitializeComponent();
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
pwd = textBox2.Text.ToString();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
count = textBox1.Text.ToString();
}
private void label2_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Database_Edit ma = new Database_Edit();
ma.run();
Form2 f = new Form2();
if (ma.GetPwd() == pwd)
f.Show();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}